Merge branch 'feature-xor-brute-scheme'

This commit is contained in:
n1474335 2017-07-18 16:17:13 +00:00
commit c7d0b0ccc5
2 changed files with 26 additions and 26 deletions

View File

@ -330,30 +330,25 @@ const OperationConfig = {
value: BitwiseOp.XOR_BRUTE_KEY_LENGTH value: BitwiseOp.XOR_BRUTE_KEY_LENGTH
}, },
{ {
name: "Length of sample", name: "Sample length",
type: "number", type: "number",
value: BitwiseOp.XOR_BRUTE_SAMPLE_LENGTH value: BitwiseOp.XOR_BRUTE_SAMPLE_LENGTH
}, },
{ {
name: "Offset of sample", name: "Sample offset",
type: "number", type: "number",
value: BitwiseOp.XOR_BRUTE_SAMPLE_OFFSET value: BitwiseOp.XOR_BRUTE_SAMPLE_OFFSET
}, },
{
name: "Scheme",
type: "option",
value: BitwiseOp.XOR_SCHEME
},
{ {
name: "Null preserving", name: "Null preserving",
type: "boolean", type: "boolean",
value: BitwiseOp.XOR_PRESERVE_NULLS value: BitwiseOp.XOR_PRESERVE_NULLS
}, },
{
name: "Differential",
type: "boolean",
value: BitwiseOp.XOR_DIFFERENTIAL
},
{
name: "Crib (known plaintext string)",
type: "binaryString",
value: ""
},
{ {
name: "Print key", name: "Print key",
type: "boolean", type: "boolean",
@ -363,6 +358,11 @@ const OperationConfig = {
name: "Output as hex", name: "Output as hex",
type: "boolean", type: "boolean",
value: BitwiseOp.XOR_BRUTE_OUTPUT_HEX value: BitwiseOp.XOR_BRUTE_OUTPUT_HEX
},
{
name: "Crib (known plaintext string)",
type: "binaryString",
value: ""
} }
] ]
}, },

View File

@ -36,7 +36,9 @@ const BitwiseOp = {
o = input[i]; o = input[i];
x = nullPreserving && (o === 0 || o === k) ? o : func(o, k); x = nullPreserving && (o === 0 || o === k) ? o : func(o, k);
result.push(x); result.push(x);
if (scheme !== "Standard" && !(nullPreserving && (o === 0 || o === k))) { if (scheme &&
scheme !== "Standard" &&
!(nullPreserving && (o === 0 || o === k))) {
switch (scheme) { switch (scheme) {
case "Input differential": case "Input differential":
key[i % key.length] = x; key[i % key.length] = x;
@ -120,19 +122,19 @@ const BitwiseOp = {
* @returns {string} * @returns {string}
*/ */
runXorBrute: function (input, args) { runXorBrute: function (input, args) {
let keyLength = parseInt(args[0], 10), const keyLength = parseInt(args[0], 10),
sampleLength = args[1], sampleLength = args[1],
sampleOffset = args[2], sampleOffset = args[2],
nullPreserving = args[3], scheme = args[3],
differential = args[4], nullPreserving = args[4],
crib = args[5], printKey = args[5],
printKey = args[6], outputHex = args[6],
outputHex = args[7], crib = args[7];
regex;
let output = "", let output = "",
result, result,
resultUtf8; resultUtf8,
regex;
input = input.slice(sampleOffset, sampleOffset + sampleLength); input = input.slice(sampleOffset, sampleOffset + sampleLength);
@ -142,14 +144,12 @@ const BitwiseOp = {
for (let key = 1, l = Math.pow(256, keyLength); key < l; key++) { for (let key = 1, l = Math.pow(256, keyLength); key < l; key++) {
result = BitwiseOp._bitOp(input, Utils.fromHex(key.toString(16)), BitwiseOp._xor, nullPreserving, differential); result = BitwiseOp._bitOp(input, Utils.fromHex(key.toString(16)), BitwiseOp._xor, nullPreserving, scheme);
resultUtf8 = Utils.byteArrayToUtf8(result); resultUtf8 = Utils.byteArrayToUtf8(result);
if (crib !== "" && resultUtf8.search(regex) === -1) continue; if (crib !== "" && resultUtf8.search(regex) === -1) continue;
if (printKey) output += "Key = " + Utils.hex(key, (2*keyLength)) + ": "; if (printKey) output += "Key = " + Utils.hex(key, (2*keyLength)) + ": ";
if (outputHex) if (outputHex) output += Utils.toHex(result) + "\n";
output += Utils.toHex(result) + "\n"; else output += Utils.printable(resultUtf8, false) + "\n";
else
output += Utils.printable(resultUtf8, false) + "\n";
if (printKey) output += "\n"; if (printKey) output += "\n";
} }
return output; return output;