소스 검색

Improved support for different alphabets in 'Substitute' operation

n1474335 8 년 전
부모
커밋
14b7c4bf23
2개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 2 2
      src/core/config/OperationConfig.js
  2. 7 7
      src/core/operations/Cipher.js

+ 2 - 2
src/core/config/OperationConfig.js

@@ -3196,8 +3196,8 @@ const OperationConfig = {
     "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.runSubstitute,
-        inputType: "byteArray",
-        outputType: "byteArray",
+        inputType: "string",
+        outputType: "string",
         args: [
             {
                 name: "Plaintext",

+ 7 - 7
src/core/operations/Cipher.js

@@ -608,23 +608,23 @@ const Cipher = {
     /**
      * Substitute operation.
      *
-     * @param {byteArray} input
+     * @param {string} input
      * @param {Object[]} args
-     * @returns {byteArray}
+     * @returns {string}
      */
     runSubstitute: function (input, args) {
-        let plaintext = Utils.strToByteArray(Utils.expandAlphRange(args[0]).join()),
-            ciphertext = Utils.strToByteArray(Utils.expandAlphRange(args[1]).join()),
-            output = [],
+        let plaintext = Utils.expandAlphRange(args[0]).join(),
+            ciphertext = Utils.expandAlphRange(args[1]).join(),
+            output = "",
             index = -1;
 
         if (plaintext.length !== ciphertext.length) {
-            output = Utils.strToByteArray("Warning: Plaintext and Ciphertext lengths differ\n\n");
+            output = "Warning: Plaintext and Ciphertext lengths differ\n\n";
         }
 
         for (let i = 0; i < input.length; i++) {
             index = plaintext.indexOf(input[i]);
-            output.push(index > -1 && index < ciphertext.length ? ciphertext[index] : input[i]);
+            output += index > -1 && index < ciphertext.length ? ciphertext[index] : input[i];
         }
 
         return output;