Explorar el Código

Adds Affine/Atbash Cipher encryption/decryption

- 3 new operations - Affine Encode, Decode and Atbash Cipher
- Added 3 new utils - mod, GCD and modInv
Matt C hace 8 años
padre
commit
2750be36da

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
build/prod/cyberchef.htm


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
build/prod/index.html


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
build/prod/scripts.js


+ 3 - 0
src/js/config/Categories.js

@@ -66,6 +66,9 @@ var Categories = [
         ops: [
         ops: [
             "AES Encrypt",
             "AES Encrypt",
             "AES Decrypt",
             "AES Decrypt",
+            "Affine Cipher Encode",
+            "Affine Cipher Decode",
+            "Atbash Cipher",
             "Blowfish Encrypt",
             "Blowfish Encrypt",
             "Blowfish Decrypt",
             "Blowfish Decrypt",
             "DES Encrypt",
             "DES Encrypt",

+ 59 - 10
src/js/config/OperationConfig.js

@@ -20,7 +20,7 @@
  * @property {boolean} [flowControl] - True if the operation is for Flow Control
  * @property {boolean} [flowControl] - True if the operation is for Flow Control
  * @property {ArgConf[]} [args] - A list of configuration objects for the arguments
  * @property {ArgConf[]} [args] - A list of configuration objects for the arguments
  */
  */
- 
+
 
 
 /**
 /**
  * Type definition for an ArgConf.
  * Type definition for an ArgConf.
@@ -800,7 +800,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -847,7 +847,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -894,7 +894,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -941,7 +941,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -988,7 +988,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -1035,7 +1035,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -1130,7 +1130,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -1177,7 +1177,7 @@ var OperationConfig = {
                 type: "toggleString",
                 type: "toggleString",
                 value: "",
                 value: "",
                 toggleValues: Cipher.IO_FORMAT1
                 toggleValues: Cipher.IO_FORMAT1
-                
+
             },
             },
             {
             {
                 name: "Salt",
                 name: "Salt",
@@ -1360,6 +1360,55 @@ var OperationConfig = {
             }
             }
         ]
         ]
     },
     },
+    "Affine Cipher Encode": {
+        description: "The affine cipher is a type of monoalphabetic substitution cipher, wherein each letter in an alphabet is mapped to its numeric equivalent, encrypted using simple mathematical function (ax + b) % 26, and converted back to a letter.",
+        run: Cipher.runAffineEnc,
+        highlight: true,
+        highlightReverse: true,
+        inputType: "string",
+        outputType: "string",
+        args: [
+            {
+                name: "a",
+                type: "number",
+                value: Cipher.AFFINE_A
+            },
+            {
+                name: "b",
+                type: "number",
+                value: Cipher.AFFINE_B
+            }
+        ]
+    },
+    "Affine Cipher Decode": {
+        description: "The affine cipher is a type of monoalphabetic substitution cipher. To decrypt, each letter in an alphabet is mapped to its numeric equivalent, decrypted by a mathematical function, and converted back to a letter.",
+        run: Cipher.runAffineDec,
+        highlight: true,
+        highlightReverse: true,
+        inputType: "string",
+        outputType: "string",
+        args: [
+            {
+                name: "a",
+                type: "number",
+                value: Cipher.AFFINE_A
+            },
+            {
+                name: "b",
+                type: "number",
+                value: Cipher.AFFINE_B
+            }
+        ]
+    },
+    "Atbash Cipher": {
+        description: "Atbash is a mono-alphabetic substitution cipher originally used to encode the Hebrew alphabet. It has been modified here for use with the latin alphabet.",
+        run: Cipher.runAtbash,
+        highlight: true,
+        highlightReverse: true,
+        inputType: "string",
+        outputType: "string",
+        args: []
+    },
     "Rotate right": {
     "Rotate right": {
         description: "Rotates each byte to the right by the number of bits specified. Currently only supports 8-bit values.",
         description: "Rotates each byte to the right by the number of bits specified. Currently only supports 8-bit values.",
         run: Rotate.runRotr,
         run: Rotate.runRotr,
@@ -1724,7 +1773,7 @@ var OperationConfig = {
                 type: "boolean",
                 type: "boolean",
                 value: StrUtils.FIND_REPLACE_MULTILINE,
                 value: StrUtils.FIND_REPLACE_MULTILINE,
             },
             },
-            
+
         ]
         ]
     },
     },
     "To Upper case": {
     "To Upper case": {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 1
src/js/core/Utils.js


+ 83 - 1
src/js/operations/Cipher.js

@@ -385,7 +385,6 @@ var Cipher = {
         return encrypted.ciphertext.toString(Utils.format[args[2]]);
         return encrypted.ciphertext.toString(Utils.format[args[2]]);
     },
     },
 
 
-
     /**
     /**
      * Vigenère Encode operation.
      * Vigenère Encode operation.
      *
      *
@@ -475,6 +474,89 @@ var Cipher = {
         return output;
         return output;
     },
     },
 
 
+    /**
+     * @constant
+     * @default
+     */
+    AFFINE_A: 1,
+    /**
+     * @constant
+     * @default
+     */
+    AFFINE_B: 0,
+    /**
+     * Affine Cipher Encode operation.
+     *
+     * @author Matt C [matt@artemisbot.pw]
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
+    runAffineEnc: function (input, args) {
+        var alphabet = "abcdefghijklmnopqrstuvwxyz",
+            a = args[0],
+            b = args[1],
+            output = "";
+        if (!/^\+?(0|[1-9]\d*)$/.test(a) || !/^\+?(0|[1-9]\d*)$/.test(b)) return "The values of a and b can only be integers.";
+        for (var i = 0; i < input.length; i++) {
+            if (alphabet.indexOf(input[i]) >= 0) {
+                // Uses the affine function ax+b % m = y (where m is length of the alphabet)
+                output += alphabet[((a * alphabet.indexOf(input[i])) + b) % 26];
+            } else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
+                // Same as above, accounting for uppercase
+                output += alphabet[((a * alphabet.indexOf(input[i].toLowerCase())) + b) % 26].toUpperCase();
+            } else {
+                // Non-alphabetic characters
+                output += input[i];
+            }
+        }
+        return output;
+    },
+
+    /**
+     * Affine Cipher Encode operation.
+     *
+     * @author Matt C [matt@artemisbot.pw]
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
+    runAffineDec: function (input, args) {
+        var alphabet = "abcdefghijklmnopqrstuvwxyz",
+            a = args[0],
+            b = args[1],
+            output = "",
+            aModInv;
+        if (!/^\+?(0|[1-9]\d*)$/.test(a) || !/^\+?(0|[1-9]\d*)$/.test(b)) return "The values of a and b can only be integers.";
+        if (Utils.gcd(a, 26) !== 1) return "The value of a must be coprime to 26.";
+        // Calculates modular inverse of a
+        aModInv = Utils.modInv(a, 26);
+        for (var i = 0; i < input.length; i++) {
+            if (alphabet.indexOf(input[i]) >= 0) {
+                // Uses the affine decode function (y-b * A') % m = x (where m is length of the alphabet and A' is modular inverse)
+                output += alphabet[Utils.mod((alphabet.indexOf(input[i]) - b) * aModInv, 26)];
+            } else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
+                // Same as above, accounting for uppercase
+                output += alphabet[Utils.mod((alphabet.indexOf(input[i].toLowerCase()) - b) * aModInv, 26)].toUpperCase();
+            } else {
+                // Non-alphabetic characters
+                output += input[i];
+            }
+        }
+        return output;
+    },
+
+    /**
+     * Atbash Cipher Encode operation.
+     *
+     * @author Matt C [matt@artemisbot.pw]
+     * @param {string} input
+     * @param {Object[]} args
+     * @returns {string}
+     */
+    runAtbash: function (input, args) {
+        return Cipher.runAffineEnc(input, [25, 25]);
+    },
 
 
     /**
     /**
      * @constant
      * @constant

+ 7 - 7
src/static/stats.txt

@@ -1,9 +1,9 @@
-212	source files
-115060	lines
+211	source files
+115224	lines
 4.3M	size
 4.3M	size
 
 
 142	JavaScript source files
 142	JavaScript source files
-105900	lines
+106064	lines
 3.8M	size
 3.8M	size
 
 
 83	third party JavaScript source files
 83	third party JavaScript source files
@@ -11,11 +11,11 @@
 3.0M	size
 3.0M	size
 
 
 59	first party JavaScript source files
 59	first party JavaScript source files
-19642	lines
-740K	size
+19806	lines
+748K	size
 
 
-3.4M	uncompressed JavaScript size
+3.5M	uncompressed JavaScript size
 1.9M	compressed JavaScript size
 1.9M	compressed JavaScript size
 
 
 15	categories
 15	categories
-167	operations
+170	operations

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio