Selaa lähdekoodia

Tidied up Bacon Cipher operations

n1474335 5 vuotta sitten
vanhempi
commit
b31f32a7e7

+ 5 - 5
src/core/lib/Bacon.mjs

@@ -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_TRANSLATIONS[1]]: /[^ABab]/g,
-    [BACON_TRANSLATIONS[2]]: /[^A-Za-z]/g,
+    [BACON_TRANSLATION_01]: /[^01]/g,
+    [BACON_TRANSLATION_AB]: /[^ABab]/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",

+ 16 - 18
src/core/operations/BaconCipherDecode.mjs

@@ -1,10 +1,8 @@
 /**
 /**
- * BaconCipher operation.
- *
-* @author Karsten Silkenbäumer [github.com/kassi]
-* @copyright Karsten Silkenbäumer 2019
-* @license Apache-2.0
-*/
+ * @author Karsten Silkenbäumer [github.com/kassi]
+ * @copyright Karsten Silkenbäumer 2019
+ * @license Apache-2.0
+ */
 
 
 import Operation from "../Operation";
 import Operation from "../Operation";
 import {
 import {
@@ -14,19 +12,19 @@ import {
 } from "../lib/Bacon";
 } from "../lib/Bacon";
 
 
 /**
 /**
-* BaconCipherDecode operation
-*/
+ * Bacon Cipher Decode operation
+ */
 class BaconCipherDecode extends Operation {
 class BaconCipherDecode extends Operation {
     /**
     /**
-    * BaconCipherDecode constructor
-    */
+     * BaconCipherDecode constructor
+     */
     constructor() {
     constructor() {
         super();
         super();
 
 
         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.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher";
+        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://wikipedia.org/wiki/Bacon%27s_cipher";
         this.inputType = "string";
         this.inputType = "string";
         this.outputType = "string";
         this.outputType = "string";
         this.args = [
         this.args = [
@@ -49,10 +47,10 @@ class BaconCipherDecode extends Operation {
     }
     }
 
 
     /**
     /**
-    * @param {String} input
-    * @param {Object[]} args
-    * @returns {String}
-    */
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
     run(input, args) {
     run(input, args) {
         const [alphabet, translation, invert] = args;
         const [alphabet, translation, invert] = args;
         const alphabetObject = BACON_ALPHABETS[alphabet];
         const alphabetObject = BACON_ALPHABETS[alphabet];
@@ -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++) {
-            const code = inputArray[index];
+        for (let i = 0; i < inputArray.length; i++) {
+            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] : "?";
         }
         }

+ 14 - 16
src/core/operations/BaconCipherEncode.mjs

@@ -1,10 +1,8 @@
 /**
 /**
- * BaconCipher operation.
- *
-* @author Karsten Silkenbäumer [github.com/kassi]
-* @copyright Karsten Silkenbäumer 2019
-* @license Apache-2.0
-*/
+ * @author Karsten Silkenbäumer [github.com/kassi]
+ * @copyright Karsten Silkenbäumer 2019
+ * @license Apache-2.0
+ */
 
 
 import Operation from "../Operation";
 import Operation from "../Operation";
 import {
 import {
@@ -14,19 +12,19 @@ import {
 } from "../lib/Bacon";
 } from "../lib/Bacon";
 
 
 /**
 /**
-* BaconCipherEncode operation
-*/
+ * Bacon Cipher Encode operation
+ */
 class BaconCipherEncode extends Operation {
 class BaconCipherEncode extends Operation {
     /**
     /**
-    * BaconCipherEncode constructor
-    */
+     * BaconCipherEncode constructor
+     */
     constructor() {
     constructor() {
         super();
         super();
 
 
         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.infoURL = "https://en.wikipedia.org/wiki/Bacon%27s_cipher";
+        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://wikipedia.org/wiki/Bacon%27s_cipher";
         this.inputType = "string";
         this.inputType = "string";
         this.outputType = "string";
         this.outputType = "string";
         this.args = [
         this.args = [
@@ -54,10 +52,10 @@ class BaconCipherEncode extends Operation {
     }
     }
 
 
     /**
     /**
-    * @param {String} input
-    * @param {Object[]} args
-    * @returns {String}
-    */
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
     run(input, args) {
     run(input, args) {
         const [alphabet, translation, keep, invert] = args;
         const [alphabet, translation, keep, invert] = args;
 
 

+ 77 - 77
tests/operations/index.mjs

@@ -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/BSON";
-import "./tests/BaconCipher";
-import "./tests/Base58";
-import "./tests/Base64";
-import "./tests/Base62";
-import "./tests/BitwiseOp";
-import "./tests/ByteRepr";
-import "./tests/CartesianProduct";
-import "./tests/CharEnc";
-import "./tests/ChangeIPFormat";
-import "./tests/Charts";
-import "./tests/Checksum";
-import "./tests/Ciphers";
-import "./tests/Code";
-import "./tests/Comment";
-import "./tests/Compress";
-import "./tests/ConditionalJump";
-import "./tests/Crypt";
-import "./tests/CSV";
-import "./tests/DateTime";
-import "./tests/ExtractEmailAddresses";
-import "./tests/Fork";
-import "./tests/FromDecimal";
-import "./tests/Hash";
-import "./tests/HaversineDistance";
-import "./tests/Hexdump";
-import "./tests/Image";
-import "./tests/IndexOfCoincidence";
-import "./tests/Jump";
-import "./tests/JSONBeautify";
-import "./tests/JSONMinify";
-import "./tests/JSONtoCSV";
-import "./tests/JWTDecode";
-import "./tests/JWTSign";
-import "./tests/JWTVerify";
-import "./tests/MS";
-import "./tests/Magic";
-import "./tests/MorseCode";
-import "./tests/NetBIOS";
-import "./tests/OTP";
-import "./tests/PGP";
-import "./tests/PHP";
-import "./tests/ParseIPRange";
-import "./tests/ParseQRCode";
-import "./tests/PowerSet";
-import "./tests/Regex";
-import "./tests/Register";
-import "./tests/RemoveDiacritics";
-import "./tests/Rotate";
-import "./tests/SeqUtils";
-import "./tests/SetDifference";
-import "./tests/SetIntersection";
-import "./tests/SetUnion";
-import "./tests/StrUtils";
-import "./tests/SymmetricDifference";
-import "./tests/TextEncodingBruteForce";
-import "./tests/TranslateDateTimeFormat";
-import "./tests/Magic";
-import "./tests/ParseTLV";
-import "./tests/Media";
-import "./tests/ToFromInsensitiveRegex";
+import "./tests/BCD.mjs";
+import "./tests/BSON.mjs";
+import "./tests/BaconCipher.mjs";
+import "./tests/Base58.mjs";
+import "./tests/Base64.mjs";
+import "./tests/Base62.mjs";
+import "./tests/BitwiseOp.mjs";
+import "./tests/ByteRepr.mjs";
+import "./tests/CartesianProduct.mjs";
+import "./tests/CharEnc.mjs";
+import "./tests/ChangeIPFormat.mjs";
+import "./tests/Charts.mjs";
+import "./tests/Checksum.mjs";
+import "./tests/Ciphers.mjs";
+import "./tests/Code.mjs";
+import "./tests/Comment.mjs";
+import "./tests/Compress.mjs";
+import "./tests/ConditionalJump.mjs";
+import "./tests/Crypt.mjs";
+import "./tests/CSV.mjs";
+import "./tests/DateTime.mjs";
+import "./tests/ExtractEmailAddresses.mjs";
+import "./tests/Fork.mjs";
+import "./tests/FromDecimal.mjs";
+import "./tests/Hash.mjs";
+import "./tests/HaversineDistance.mjs";
+import "./tests/Hexdump.mjs";
+import "./tests/Image.mjs";
+import "./tests/IndexOfCoincidence.mjs";
+import "./tests/Jump.mjs";
+import "./tests/JSONBeautify.mjs";
+import "./tests/JSONMinify.mjs";
+import "./tests/JSONtoCSV.mjs";
+import "./tests/JWTDecode.mjs";
+import "./tests/JWTSign.mjs";
+import "./tests/JWTVerify.mjs";
+import "./tests/MS.mjs";
+import "./tests/Magic.mjs";
+import "./tests/MorseCode.mjs";
+import "./tests/NetBIOS.mjs";
+import "./tests/OTP.mjs";
+import "./tests/PGP.mjs";
+import "./tests/PHP.mjs";
+import "./tests/ParseIPRange.mjs";
+import "./tests/ParseQRCode.mjs";
+import "./tests/PowerSet.mjs";
+import "./tests/Regex.mjs";
+import "./tests/Register.mjs";
+import "./tests/RemoveDiacritics.mjs";
+import "./tests/Rotate.mjs";
+import "./tests/SeqUtils.mjs";
+import "./tests/SetDifference.mjs";
+import "./tests/SetIntersection.mjs";
+import "./tests/SetUnion.mjs";
+import "./tests/StrUtils.mjs";
+import "./tests/SymmetricDifference.mjs";
+import "./tests/TextEncodingBruteForce.mjs";
+import "./tests/TranslateDateTimeFormat.mjs";
+import "./tests/Magic.mjs";
+import "./tests/ParseTLV.mjs";
+import "./tests/Media.mjs";
+import "./tests/ToFromInsensitiveRegex.mjs";
 import "./tests/YARA.mjs";
 import "./tests/YARA.mjs";
-import "./tests/ConvertCoordinateFormat";
-import "./tests/Enigma";
-import "./tests/Bombe";
-import "./tests/MultipleBombe";
-import "./tests/Typex";
-import "./tests/BLAKE2b";
-import "./tests/BLAKE2s";
-import "./tests/Protobuf";
-import "./tests/ParseSSHHostKey";
-import "./tests/DefangIP";
-import "./tests/ParseUDP";
+import "./tests/ConvertCoordinateFormat.mjs";
+import "./tests/Enigma.mjs";
+import "./tests/Bombe.mjs";
+import "./tests/MultipleBombe.mjs";
+import "./tests/Typex.mjs";
+import "./tests/BLAKE2b.mjs";
+import "./tests/BLAKE2s.mjs";
+import "./tests/Protobuf.mjs";
+import "./tests/ParseSSHHostKey.mjs";
+import "./tests/DefangIP.mjs";
+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/ops";
+// import "./tests/nodeApi/nodeApi.mjs";
+// import "./tests/nodeApi/ops.mjs";
 
 
 const testStatus = {
 const testStatus = {
     allTestsPassing: true,
     allTestsPassing: true,

+ 3 - 5
tests/operations/tests/BaconCipher.mjs

@@ -1,11 +1,11 @@
 /**
 /**
- * BaconCipher tests.
+ * Bacon Cipher tests.
  *
  *
  * @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
  */
  */
-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: "",