Merge branch 'bugfixes' of https://github.com/bwhitn/CyberChef into bwhitn-bugfixes

This commit is contained in:
n1474335 2018-11-06 18:51:40 +00:00
commit 2d5b157c91
5 changed files with 39 additions and 3 deletions

View file

@ -8,7 +8,7 @@
"node": "6.5" "node": "6.5"
}, },
"modules": false, "modules": false,
"useBuiltIns": "usage" "useBuiltIns": "entry"
}] }]
], ],
"plugins": [ "plugins": [

View file

@ -71,6 +71,11 @@ class FromBase58 extends Operation {
if (input.length === 0) return []; if (input.length === 0) return [];
let zeroPrefix = 0;
for (let i = 0; i < input.length && input[i] === alphabet[0]; i++) {
zeroPrefix++;
}
[].forEach.call(input, function(c, charIndex) { [].forEach.call(input, function(c, charIndex) {
const index = alphabet.indexOf(c); const index = alphabet.indexOf(c);
@ -98,6 +103,10 @@ class FromBase58 extends Operation {
} }
}); });
while (zeroPrefix--) {
result.push(0);
}
return result.reverse(); return result.reverse();
} }

View file

@ -62,7 +62,7 @@ class Scrypt extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const salt = Utils.convertToByteString(args[0].string || "", args[0].option), const salt = Buffer.from(Utils.convertToByteArray(args[0].string || "", args[0].option)),
iterations = args[1], iterations = args[1],
memFactor = args[2], memFactor = args[2],
parallelFactor = args[3], parallelFactor = args[3],

View file

@ -53,6 +53,11 @@ class ToBase58 extends Operation {
if (input.length === 0) return ""; if (input.length === 0) return "";
let zeroPrefix = 0;
for (let i = 0; i < input.length && input[i] === 0; i++) {
zeroPrefix++;
}
input.forEach(function(b) { input.forEach(function(b) {
let carry = (result[0] << 8) + b; let carry = (result[0] << 8) + b;
result[0] = carry % 58; result[0] = carry % 58;
@ -74,7 +79,7 @@ class ToBase58 extends Operation {
return alphabet[b]; return alphabet[b];
}).reverse().join(""); }).reverse().join("");
while (result.length < input.length) { while (zeroPrefix--) {
result = alphabet[0] + result; result = alphabet[0] + result;
} }

View file

@ -53,6 +53,28 @@ TestRegister.addTests([
}, },
], ],
}, },
{
name: "To Base58 with null prefix and suffix",
input: "\0\0\0Hello\0\0\0",
expectedOutput: "111D7LMXYjHjTu",
recipeConfig: [
{
op: "To Base58",
args: ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],
},
],
},
{
name: "From Base58 with null prefix and suffix",
input: "111D7LMXYjHjTu",
expectedOutput: "\0\0\0Hello\0\0\0",
recipeConfig: [
{
op: "From Base58",
args: ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],
},
],
},
{ {
name: "From Base58 (Bitcoin): 'StV1DL6CwTryKyV'", name: "From Base58 (Bitcoin): 'StV1DL6CwTryKyV'",
input: "StV1DL6CwTryKyV", input: "StV1DL6CwTryKyV",