mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Variable names changed from underscore to CamelCase. Eslint rules updated. #64
This commit is contained in:
parent
f8193797fa
commit
e3c977934b
66 changed files with 3176 additions and 3172 deletions
|
@ -15,14 +15,14 @@ var BitwiseOp = {
|
|||
* Runs bitwise operations across the input data.
|
||||
*
|
||||
* @private
|
||||
* @param {byte_array} input
|
||||
* @param {byte_array} key
|
||||
* @param {byteArray} input
|
||||
* @param {byteArray} key
|
||||
* @param {function} func - The bitwise calculation to carry out
|
||||
* @param {boolean} null_preserving
|
||||
* @param {boolean} nullPreserving
|
||||
* @param {string} scheme
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
_bit_op: function (input, key, func, null_preserving, scheme) {
|
||||
_bitOp: function (input, key, func, nullPreserving, scheme) {
|
||||
if (!key || !key.length) key = [0];
|
||||
var result = [],
|
||||
x = null,
|
||||
|
@ -32,9 +32,9 @@ var BitwiseOp = {
|
|||
for (var i = 0; i < input.length; i++) {
|
||||
k = key[i % key.length];
|
||||
o = input[i];
|
||||
x = null_preserving && (o === 0 || o === k) ? o : func(o, k);
|
||||
x = nullPreserving && (o === 0 || o === k) ? o : func(o, k);
|
||||
result.push(x);
|
||||
if (scheme !== "Standard" && !(null_preserving && (o === 0 || o === k))) {
|
||||
if (scheme !== "Standard" && !(nullPreserving && (o === 0 || o === k))) {
|
||||
switch (scheme) {
|
||||
case "Input differential":
|
||||
key[i % key.length] = x;
|
||||
|
@ -69,18 +69,18 @@ var BitwiseOp = {
|
|||
/**
|
||||
* XOR operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_xor: function (input, args) {
|
||||
runXor: function (input, args) {
|
||||
var key = Utils.format[args[0].option].parse(args[0].string || ""),
|
||||
scheme = args[1],
|
||||
null_preserving = args[2];
|
||||
nullPreserving = args[2];
|
||||
|
||||
key = Utils.word_array_to_byte_array(key);
|
||||
key = Utils.wordArrayToByteArray(key);
|
||||
|
||||
return BitwiseOp._bit_op(input, key, BitwiseOp._xor, null_preserving, scheme);
|
||||
return BitwiseOp._bitOp(input, key, BitwiseOp._xor, nullPreserving, scheme);
|
||||
},
|
||||
|
||||
|
||||
|
@ -113,42 +113,42 @@ var BitwiseOp = {
|
|||
/**
|
||||
* XOR Brute Force operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run_xor_brute: function (input, args) {
|
||||
var key_length = parseInt(args[0], 10),
|
||||
sample_length = args[1],
|
||||
sample_offset = args[2],
|
||||
null_preserving = args[3],
|
||||
runXorBrute: function (input, args) {
|
||||
var keyLength = parseInt(args[0], 10),
|
||||
sampleLength = args[1],
|
||||
sampleOffset = args[2],
|
||||
nullPreserving = args[3],
|
||||
differential = args[4],
|
||||
crib = args[5],
|
||||
print_key = args[6],
|
||||
output_hex = args[7],
|
||||
printKey = args[6],
|
||||
outputHex = args[7],
|
||||
regex;
|
||||
|
||||
var output = "",
|
||||
result,
|
||||
result_utf8;
|
||||
resultUtf8;
|
||||
|
||||
input = input.slice(sample_offset, sample_offset + sample_length);
|
||||
input = input.slice(sampleOffset, sampleOffset + sampleLength);
|
||||
|
||||
if (crib !== "") {
|
||||
regex = new RegExp(crib, "im");
|
||||
}
|
||||
|
||||
|
||||
for (var key = 1, l = Math.pow(256, key_length); key < l; key++) {
|
||||
result = BitwiseOp._bit_op(input, Utils.hex_to_byte_array(key.toString(16)), BitwiseOp._xor, null_preserving, differential);
|
||||
result_utf8 = Utils.byte_array_to_utf8(result);
|
||||
if (crib !== "" && result_utf8.search(regex) === -1) continue;
|
||||
if (print_key) output += "Key = " + Utils.hex(key, (2*key_length)) + ": ";
|
||||
if (output_hex)
|
||||
output += Utils.byte_array_to_hex(result) + "\n";
|
||||
for (var key = 1, l = Math.pow(256, keyLength); key < l; key++) {
|
||||
result = BitwiseOp._bitOp(input, Utils.hexToByteArray(key.toString(16)), BitwiseOp._xor, nullPreserving, differential);
|
||||
resultUtf8 = Utils.byteArrayToUtf8(result);
|
||||
if (crib !== "" && resultUtf8.search(regex) === -1) continue;
|
||||
if (printKey) output += "Key = " + Utils.hex(key, (2*keyLength)) + ": ";
|
||||
if (outputHex)
|
||||
output += Utils.byteArrayToHex(result) + "\n";
|
||||
else
|
||||
output += Utils.printable(result_utf8, false) + "\n";
|
||||
if (print_key) output += "\n";
|
||||
output += Utils.printable(resultUtf8, false) + "\n";
|
||||
if (printKey) output += "\n";
|
||||
}
|
||||
return output;
|
||||
},
|
||||
|
@ -157,72 +157,72 @@ var BitwiseOp = {
|
|||
/**
|
||||
* NOT operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_not: function (input, args) {
|
||||
return BitwiseOp._bit_op(input, null, BitwiseOp._not);
|
||||
runNot: function (input, args) {
|
||||
return BitwiseOp._bitOp(input, null, BitwiseOp._not);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* AND operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_and: function (input, args) {
|
||||
runAnd: function (input, args) {
|
||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
||||
key = Utils.word_array_to_byte_array(key);
|
||||
key = Utils.wordArrayToByteArray(key);
|
||||
|
||||
return BitwiseOp._bit_op(input, key, BitwiseOp._and);
|
||||
return BitwiseOp._bitOp(input, key, BitwiseOp._and);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* OR operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_or: function (input, args) {
|
||||
runOr: function (input, args) {
|
||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
||||
key = Utils.word_array_to_byte_array(key);
|
||||
key = Utils.wordArrayToByteArray(key);
|
||||
|
||||
return BitwiseOp._bit_op(input, key, BitwiseOp._or);
|
||||
return BitwiseOp._bitOp(input, key, BitwiseOp._or);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* ADD operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_add: function (input, args) {
|
||||
runAdd: function (input, args) {
|
||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
||||
key = Utils.word_array_to_byte_array(key);
|
||||
key = Utils.wordArrayToByteArray(key);
|
||||
|
||||
return BitwiseOp._bit_op(input, key, BitwiseOp._add);
|
||||
return BitwiseOp._bitOp(input, key, BitwiseOp._add);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* SUB operation.
|
||||
*
|
||||
* @param {byte_array} input
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byte_array}
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run_sub: function (input, args) {
|
||||
runSub: function (input, args) {
|
||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
||||
key = Utils.word_array_to_byte_array(key);
|
||||
key = Utils.wordArrayToByteArray(key);
|
||||
|
||||
return BitwiseOp._bit_op(input, key, BitwiseOp._sub);
|
||||
return BitwiseOp._bitOp(input, key, BitwiseOp._sub);
|
||||
},
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue