mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 00:06:17 -04:00
Use better names for the alphabet selection
This commit is contained in:
parent
a262d70b88
commit
d36cede0c7
4 changed files with 21 additions and 15 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import {
|
||||
BACON_ALPHABET_REDUCED, BACON_ALPHABET_COMPLETE,
|
||||
BACON_ALPHABETS,
|
||||
BACON_TRANSLATION_CASE, BACON_TRANSLATION_AMNZ, BACON_TRANSLATIONS, BACON_CLEARER_MAP, BACON_NORMALIZE_MAP,
|
||||
swapZeroAndOne
|
||||
} from "../lib/Bacon";
|
||||
|
@ -33,7 +33,7 @@ class BaconCipherDecode extends Operation {
|
|||
{
|
||||
"name": "Alphabet",
|
||||
"type": "option",
|
||||
"value": [BACON_ALPHABET_REDUCED, BACON_ALPHABET_COMPLETE]
|
||||
"value": Object.keys(BACON_ALPHABETS)
|
||||
},
|
||||
{
|
||||
"name": "Translation",
|
||||
|
@ -55,10 +55,11 @@ class BaconCipherDecode extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
const [alphabet, translation, invert] = args;
|
||||
// split text into groups of 5 characters
|
||||
const alphabetObject = BACON_ALPHABETS[alphabet];
|
||||
|
||||
// remove invalid characters
|
||||
input = input.replace(BACON_CLEARER_MAP[translation], "");
|
||||
|
||||
// normalize to unique alphabet
|
||||
if (BACON_NORMALIZE_MAP[translation] !== undefined) {
|
||||
input = input.replace(/./g, function (c) {
|
||||
|
@ -95,7 +96,7 @@ class BaconCipherDecode extends Operation {
|
|||
for (let index = 0; index < inputArray.length; index++) {
|
||||
const code = inputArray[index];
|
||||
const number = parseInt(code, 2);
|
||||
output += number < alphabet.length ? alphabet[number] : "?";
|
||||
output += number < alphabetObject.alphabet.length ? alphabetObject.alphabet[number] : "?";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
|
||||
import Operation from "../Operation";
|
||||
import {
|
||||
BACON_ALPHABET_REDUCED, BACON_ALPHABET_COMPLETE,
|
||||
BACON_ALPHABETS,
|
||||
BACON_TRANSLATIONS_FOR_ENCODING, BACON_TRANSLATION_AB,
|
||||
swapZeroAndOne
|
||||
} from "../lib/Bacon";
|
||||
import { BACON_CODES_REDUCED } from "../lib/Bacon.mjs";
|
||||
|
||||
/**
|
||||
* BaconCipherEncode operation
|
||||
|
@ -34,7 +33,7 @@ class BaconCipherEncode extends Operation {
|
|||
{
|
||||
"name": "Alphabet",
|
||||
"type": "option",
|
||||
"value": [BACON_ALPHABET_REDUCED, BACON_ALPHABET_COMPLETE]
|
||||
"value": Object.keys(BACON_ALPHABETS)
|
||||
},
|
||||
{
|
||||
"name": "Translation",
|
||||
|
@ -62,6 +61,7 @@ class BaconCipherEncode extends Operation {
|
|||
run(input, args) {
|
||||
const [alphabet, translation, keep, invert] = args;
|
||||
|
||||
const alphabetObject = BACON_ALPHABETS[alphabet];
|
||||
const charCodeA = "A".charCodeAt(0);
|
||||
const charCodeZ = "Z".charCodeAt(0);
|
||||
|
||||
|
@ -69,8 +69,8 @@ class BaconCipherEncode extends Operation {
|
|||
const charCode = c.toUpperCase().charCodeAt(0);
|
||||
if (charCode >= charCodeA && charCode <= charCodeZ) {
|
||||
let code = charCode - charCodeA;
|
||||
if (alphabet === BACON_ALPHABET_REDUCED) {
|
||||
code = BACON_CODES_REDUCED[code];
|
||||
if (alphabetObject.codes !== undefined) {
|
||||
code = alphabetObject.codes[code];
|
||||
}
|
||||
const bacon = ("00000" + code.toString(2)).substr(-5, 5);
|
||||
return bacon;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue