mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-25 01:06:16 -04:00
CipherSaber2 ops now accept a variety of key types
This commit is contained in:
parent
5e7b004925
commit
64b979e25e
4 changed files with 26 additions and 20 deletions
|
@ -1,12 +1,10 @@
|
|||
import Utils from "../Utils.mjs";
|
||||
|
||||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
export function encode(tempIVP, args, input) {
|
||||
const ivp = new Uint8Array(Utils.strToByteArray(args[0]).concat(tempIVP));
|
||||
export function encode(tempIVP, key, rounds, input) {
|
||||
const ivp = new Uint8Array(key.concat(tempIVP));
|
||||
const state = new Array(256).fill(0);
|
||||
let j = 0, i = 0;
|
||||
const result = [];
|
||||
|
@ -15,7 +13,7 @@ export function encode(tempIVP, args, input) {
|
|||
for (let i = 0; i < 256; i++)
|
||||
state[i] = i;
|
||||
const ivpLength = ivp.length;
|
||||
for (let r = 0; r < args[1]; r ++) {
|
||||
for (let r = 0; r < rounds; r ++) {
|
||||
for (let k = 0; k < 256; k++) {
|
||||
j = (j + state[k] + ivp[k % ivpLength]) % 256;
|
||||
[state[k], state[j]] = [state[j], state[k]];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue