mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added 'Substitute' operation.
This commit is contained in:
parent
e1ef228575
commit
ef464ab57c
7 changed files with 83 additions and 27 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -82,6 +82,7 @@ const Categories = [
|
||||||
"XOR Brute Force",
|
"XOR Brute Force",
|
||||||
"Vigenère Encode",
|
"Vigenère Encode",
|
||||||
"Vigenère Decode",
|
"Vigenère Decode",
|
||||||
|
"Substitute",
|
||||||
"Derive PBKDF2 key",
|
"Derive PBKDF2 key",
|
||||||
"Derive EVP key",
|
"Derive EVP key",
|
||||||
]
|
]
|
||||||
|
|
|
@ -2863,5 +2863,23 @@ const OperationConfig = {
|
||||||
input_type: "string",
|
input_type: "string",
|
||||||
output_type: "string",
|
output_type: "string",
|
||||||
args: []
|
args: []
|
||||||
|
},
|
||||||
|
"Substitute": {
|
||||||
|
description: "A substitution cipher allowing you to specify bytes to replace with other byte values. This can be used to create Caesar ciphers but is more powerful as any byte value can be substituted, not just letters, and the substitution values need not be in order.<br><br>Enter the bytes you want to replace in the Plaintext field and the bytes to replace them with in the Ciphertext field.<br><br>Non-printable bytes can be specified using string escape notation. For example, a line feed character can be written as either <code>\\n</code> or <code>\\x0a</code>.<br><br>Byte ranges can be specified using a hyphen. For example, the sequence <code>0123456789</code> can be written as <code>0-9</code>.",
|
||||||
|
run: Cipher.run_substitute,
|
||||||
|
input_type: "byte_array",
|
||||||
|
output_type: "byte_array",
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: "Plaintext",
|
||||||
|
type: "binary_string",
|
||||||
|
value: Cipher.SUBS_PLAINTEXT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ciphertext",
|
||||||
|
type: "binary_string",
|
||||||
|
value: Cipher.SUBS_CIPHERTEXT
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -475,6 +475,43 @@ var Cipher = {
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
SUBS_PLAINTEXT: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
SUBS_CIPHERTEXT: "XYZABCDEFGHIJKLMNOPQRSTUVW",
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Substitute operation.
|
||||||
|
*
|
||||||
|
* @param {byte_array} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {byte_array}
|
||||||
|
*/
|
||||||
|
run_substitute: function (input, args) {
|
||||||
|
var plaintext = Utils.str_to_byte_array(Utils.expand_alph_range(args[0]).join()),
|
||||||
|
ciphertext = Utils.str_to_byte_array(Utils.expand_alph_range(args[1]).join()),
|
||||||
|
output = [],
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
if (plaintext.length !== ciphertext.length) {
|
||||||
|
output = Utils.str_to_byte_array("Warning: Plaintext and Ciphertext lengths differ\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < input.length; i++) {
|
||||||
|
index = plaintext.indexOf(input[i]);
|
||||||
|
output.push(index > -1 && index < ciphertext.length ? ciphertext[index] : input[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
206 source files
|
206 source files
|
||||||
113355 lines
|
113411 lines
|
||||||
4.2M size
|
4.2M size
|
||||||
|
|
||||||
137 JavaScript source files
|
137 JavaScript source files
|
||||||
104197 lines
|
104253 lines
|
||||||
3.7M size
|
3.7M size
|
||||||
|
|
||||||
79 third party JavaScript source files
|
79 third party JavaScript source files
|
||||||
|
@ -11,11 +11,11 @@
|
||||||
3.0M size
|
3.0M size
|
||||||
|
|
||||||
58 first party JavaScript source files
|
58 first party JavaScript source files
|
||||||
19145 lines
|
19201 lines
|
||||||
724K size
|
724K size
|
||||||
|
|
||||||
3.4M uncompressed JavaScript size
|
3.4M uncompressed JavaScript size
|
||||||
1.8M compressed JavaScript size
|
1.8M compressed JavaScript size
|
||||||
|
|
||||||
15 categories
|
15 categories
|
||||||
157 operations
|
158 operations
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue