Tidied up Bacon Cipher operations

This commit is contained in:
n1474335 2019-09-04 17:13:05 +01:00
parent f0b3bd0ede
commit b31f32a7e7
5 changed files with 115 additions and 121 deletions

View file

@ -1,5 +1,5 @@
/** /**
* Bacon resources. * Bacon Cipher resources.
* *
* @author Karsten Silkenbäumer [github.com/kassi] * @author Karsten Silkenbäumer [github.com/kassi]
* @copyright Karsten Silkenbäumer 2019 * @copyright Karsten Silkenbäumer 2019
@ -33,12 +33,12 @@ export const BACON_TRANSLATIONS_FOR_ENCODING = [
BACON_TRANSLATION_AB BACON_TRANSLATION_AB
]; ];
export const BACON_CLEARER_MAP = { export const BACON_CLEARER_MAP = {
[BACON_TRANSLATIONS[0]]: /[^01]/g, [BACON_TRANSLATION_01]: /[^01]/g,
[BACON_TRANSLATIONS[1]]: /[^ABab]/g, [BACON_TRANSLATION_AB]: /[^ABab]/g,
[BACON_TRANSLATIONS[2]]: /[^A-Za-z]/g, [BACON_TRANSLATION_CASE]: /[^A-Za-z]/g,
}; };
export const BACON_NORMALIZE_MAP = { export const BACON_NORMALIZE_MAP = {
[BACON_TRANSLATIONS[1]]: { [BACON_TRANSLATION_AB]: {
"A": "0", "A": "0",
"B": "1", "B": "1",
"a": "0", "a": "0",

View file

@ -1,6 +1,4 @@
/** /**
* BaconCipher operation.
*
* @author Karsten Silkenbäumer [github.com/kassi] * @author Karsten Silkenbäumer [github.com/kassi]
* @copyright Karsten Silkenbäumer 2019 * @copyright Karsten Silkenbäumer 2019
* @license Apache-2.0 * @license Apache-2.0
@ -25,8 +23,8 @@ class BaconCipherDecode extends Operation {
this.name = "Bacon Cipher Decode"; this.name = "Bacon Cipher Decode";
this.module = "Default"; this.module = "Default";
this.description = "Bacon's cipher or the Baconian cipher is a method of steganography(a method of hiding a secret message as opposed to just a cipher) devised by Francis Bacon in 1605.[1][2][3] A message is concealed in the presentation of text, rather than its content."; this.description = "Bacon's cipher or the Baconian cipher is a method of steganography devised by Francis Bacon in 1605. A message is concealed in the presentation of text, rather than its content.";
this.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher"; this.infoURL = "https://wikipedia.org/wiki/Bacon%27s_cipher";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
@ -49,9 +47,9 @@ class BaconCipherDecode extends Operation {
} }
/** /**
* @param {String} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {String} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [alphabet, translation, invert] = args; const [alphabet, translation, invert] = args;
@ -97,8 +95,8 @@ class BaconCipherDecode extends Operation {
const inputArray = input.match(/(.{5})/g) || []; const inputArray = input.match(/(.{5})/g) || [];
let output = ""; let output = "";
for (let index = 0; index < inputArray.length; index++) { for (let i = 0; i < inputArray.length; i++) {
const code = inputArray[index]; const code = inputArray[i];
const number = parseInt(code, 2); const number = parseInt(code, 2);
output += number < alphabetObject.alphabet.length ? alphabetObject.alphabet[number] : "?"; output += number < alphabetObject.alphabet.length ? alphabetObject.alphabet[number] : "?";
} }

View file

@ -1,6 +1,4 @@
/** /**
* BaconCipher operation.
*
* @author Karsten Silkenbäumer [github.com/kassi] * @author Karsten Silkenbäumer [github.com/kassi]
* @copyright Karsten Silkenbäumer 2019 * @copyright Karsten Silkenbäumer 2019
* @license Apache-2.0 * @license Apache-2.0
@ -25,8 +23,8 @@ class BaconCipherEncode extends Operation {
this.name = "Bacon Cipher Encode"; this.name = "Bacon Cipher Encode";
this.module = "Default"; this.module = "Default";
this.description = "Bacon's cipher or the Baconian cipher is a method of steganography(a method of hiding a secret message as opposed to just a cipher) devised by Francis Bacon in 1605.[1][2][3] A message is concealed in the presentation of text, rather than its content."; this.description = "Bacon's cipher or the Baconian cipher is a method of steganography devised by Francis Bacon in 1605. A message is concealed in the presentation of text, rather than its content.";
this.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher"; this.infoURL = "https://wikipedia.org/wiki/Bacon%27s_cipher";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
@ -54,9 +52,9 @@ class BaconCipherEncode extends Operation {
} }
/** /**
* @param {String} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {String} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const [alphabet, translation, keep, invert] = args; const [alphabet, translation, keep, invert] = args;

View file

@ -14,89 +14,89 @@
import { import {
setLongTestFailure, setLongTestFailure,
logTestReport, logTestReport,
} from "../lib/utils"; } from "../lib/utils.mjs";
import TestRegister from "../lib/TestRegister.mjs"; import TestRegister from "../lib/TestRegister.mjs";
import "./tests/BCD"; import "./tests/BCD.mjs";
import "./tests/BSON"; import "./tests/BSON.mjs";
import "./tests/BaconCipher"; import "./tests/BaconCipher.mjs";
import "./tests/Base58"; import "./tests/Base58.mjs";
import "./tests/Base64"; import "./tests/Base64.mjs";
import "./tests/Base62"; import "./tests/Base62.mjs";
import "./tests/BitwiseOp"; import "./tests/BitwiseOp.mjs";
import "./tests/ByteRepr"; import "./tests/ByteRepr.mjs";
import "./tests/CartesianProduct"; import "./tests/CartesianProduct.mjs";
import "./tests/CharEnc"; import "./tests/CharEnc.mjs";
import "./tests/ChangeIPFormat"; import "./tests/ChangeIPFormat.mjs";
import "./tests/Charts"; import "./tests/Charts.mjs";
import "./tests/Checksum"; import "./tests/Checksum.mjs";
import "./tests/Ciphers"; import "./tests/Ciphers.mjs";
import "./tests/Code"; import "./tests/Code.mjs";
import "./tests/Comment"; import "./tests/Comment.mjs";
import "./tests/Compress"; import "./tests/Compress.mjs";
import "./tests/ConditionalJump"; import "./tests/ConditionalJump.mjs";
import "./tests/Crypt"; import "./tests/Crypt.mjs";
import "./tests/CSV"; import "./tests/CSV.mjs";
import "./tests/DateTime"; import "./tests/DateTime.mjs";
import "./tests/ExtractEmailAddresses"; import "./tests/ExtractEmailAddresses.mjs";
import "./tests/Fork"; import "./tests/Fork.mjs";
import "./tests/FromDecimal"; import "./tests/FromDecimal.mjs";
import "./tests/Hash"; import "./tests/Hash.mjs";
import "./tests/HaversineDistance"; import "./tests/HaversineDistance.mjs";
import "./tests/Hexdump"; import "./tests/Hexdump.mjs";
import "./tests/Image"; import "./tests/Image.mjs";
import "./tests/IndexOfCoincidence"; import "./tests/IndexOfCoincidence.mjs";
import "./tests/Jump"; import "./tests/Jump.mjs";
import "./tests/JSONBeautify"; import "./tests/JSONBeautify.mjs";
import "./tests/JSONMinify"; import "./tests/JSONMinify.mjs";
import "./tests/JSONtoCSV"; import "./tests/JSONtoCSV.mjs";
import "./tests/JWTDecode"; import "./tests/JWTDecode.mjs";
import "./tests/JWTSign"; import "./tests/JWTSign.mjs";
import "./tests/JWTVerify"; import "./tests/JWTVerify.mjs";
import "./tests/MS"; import "./tests/MS.mjs";
import "./tests/Magic"; import "./tests/Magic.mjs";
import "./tests/MorseCode"; import "./tests/MorseCode.mjs";
import "./tests/NetBIOS"; import "./tests/NetBIOS.mjs";
import "./tests/OTP"; import "./tests/OTP.mjs";
import "./tests/PGP"; import "./tests/PGP.mjs";
import "./tests/PHP"; import "./tests/PHP.mjs";
import "./tests/ParseIPRange"; import "./tests/ParseIPRange.mjs";
import "./tests/ParseQRCode"; import "./tests/ParseQRCode.mjs";
import "./tests/PowerSet"; import "./tests/PowerSet.mjs";
import "./tests/Regex"; import "./tests/Regex.mjs";
import "./tests/Register"; import "./tests/Register.mjs";
import "./tests/RemoveDiacritics"; import "./tests/RemoveDiacritics.mjs";
import "./tests/Rotate"; import "./tests/Rotate.mjs";
import "./tests/SeqUtils"; import "./tests/SeqUtils.mjs";
import "./tests/SetDifference"; import "./tests/SetDifference.mjs";
import "./tests/SetIntersection"; import "./tests/SetIntersection.mjs";
import "./tests/SetUnion"; import "./tests/SetUnion.mjs";
import "./tests/StrUtils"; import "./tests/StrUtils.mjs";
import "./tests/SymmetricDifference"; import "./tests/SymmetricDifference.mjs";
import "./tests/TextEncodingBruteForce"; import "./tests/TextEncodingBruteForce.mjs";
import "./tests/TranslateDateTimeFormat"; import "./tests/TranslateDateTimeFormat.mjs";
import "./tests/Magic"; import "./tests/Magic.mjs";
import "./tests/ParseTLV"; import "./tests/ParseTLV.mjs";
import "./tests/Media"; import "./tests/Media.mjs";
import "./tests/ToFromInsensitiveRegex"; import "./tests/ToFromInsensitiveRegex.mjs";
import "./tests/YARA.mjs"; import "./tests/YARA.mjs";
import "./tests/ConvertCoordinateFormat"; import "./tests/ConvertCoordinateFormat.mjs";
import "./tests/Enigma"; import "./tests/Enigma.mjs";
import "./tests/Bombe"; import "./tests/Bombe.mjs";
import "./tests/MultipleBombe"; import "./tests/MultipleBombe.mjs";
import "./tests/Typex"; import "./tests/Typex.mjs";
import "./tests/BLAKE2b"; import "./tests/BLAKE2b.mjs";
import "./tests/BLAKE2s"; import "./tests/BLAKE2s.mjs";
import "./tests/Protobuf"; import "./tests/Protobuf.mjs";
import "./tests/ParseSSHHostKey"; import "./tests/ParseSSHHostKey.mjs";
import "./tests/DefangIP"; import "./tests/DefangIP.mjs";
import "./tests/ParseUDP"; import "./tests/ParseUDP.mjs";
// Cannot test operations that use the File type yet // Cannot test operations that use the File type yet
//import "./tests/SplitColourChannels"; // import "./tests/SplitColourChannels.mjs";
// import "./tests/nodeApi/nodeApi"; // import "./tests/nodeApi/nodeApi.mjs";
// import "./tests/nodeApi/ops"; // import "./tests/nodeApi/ops.mjs";
const testStatus = { const testStatus = {
allTestsPassing: true, allTestsPassing: true,

View file

@ -5,7 +5,7 @@
* @copyright Karsten Silkenbäumer 2019 * @copyright Karsten Silkenbäumer 2019
* @license Apache-2.0 * @license Apache-2.0
*/ */
import TestRegister from "../TestRegister"; import TestRegister from "../../lib/TestRegister";
import { BACON_ALPHABETS, BACON_TRANSLATIONS } from "../../../src/core/lib/Bacon"; import { BACON_ALPHABETS, BACON_TRANSLATIONS } from "../../../src/core/lib/Bacon";
const alphabets = Object.keys(BACON_ALPHABETS); const alphabets = Object.keys(BACON_ALPHABETS);
@ -242,9 +242,7 @@ TestRegister.addTests([
args: [alphabets[1], translations[3], true] args: [alphabets[1], translations[3], true]
} }
], ],
} },
]);
TestRegister.addTests([
{ {
name: "Bacon Encode: no input", name: "Bacon Encode: no input",
input: "", input: "",