CyberChef/src/core/operations/CipherSaber2Encrypt.mjs

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-02-14 15:21:32 +01:00
/**
* @author n1073645 [n1073645@gmail.com]
* @copyright Crown Copyright 2020
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import crypto from "crypto";
import { encode } from "../lib/CipherSaber2.mjs";
import Utils from "../Utils.mjs";
2020-02-14 15:21:32 +01:00
/**
* CipherSaber2 Encrypt operation
2020-02-14 15:21:32 +01:00
*/
class CipherSaber2Encrypt extends Operation {
2020-02-14 15:21:32 +01:00
/**
* CipherSaber2Encrypt constructor
2020-02-14 15:21:32 +01:00
*/
constructor() {
super();
this.name = "CipherSaber2 Encrypt";
this.module = "Crypto";
this.description = "CipherSaber is a simple symmetric encryption protocol based on the RC4 stream cipher. It gives reasonably strong protection of message confidentiality, yet it's designed to be simple enough that even novice programmers can memorize the algorithm and implement it from scratch.";
this.infoURL = "https://wikipedia.org/wiki/CipherSaber";
this.inputType = "ArrayBuffer";
this.outputType = "ArrayBuffer";
this.args = [
{
name: "Key",
type: "toggleString",
value: "",
toggleValues: ["Hex", "UTF8", "Latin1", "Base64"]
2020-02-14 15:21:32 +01:00
},
{
name: "Rounds",
type: "number",
value: 20
}
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
input = new Uint8Array(input);
const result = [],
key = Utils.convertToByteArray(args[0].string, args[0].option),
rounds = args[1];
2020-02-14 15:21:32 +01:00
// Assign into initialisation vector based on cipher mode.
const tempIVP = crypto.randomBytes(10);
for (let m = 0; m < 10; m++)
result.push(tempIVP[m]);
return new Uint8Array(result.concat(encode(tempIVP, key, rounds, input))).buffer;
2020-02-14 15:21:32 +01:00
}
}
export default CipherSaber2Encrypt;