From 4c6200f2331328df62e59575c8f196f3578293da Mon Sep 17 00:00:00 2001 From: zb3 Date: Mon, 1 Apr 2024 17:31:36 +0200 Subject: [PATCH 1/3] Fix Base58 handling of strings with only null characters --- src/core/operations/FromBase58.mjs | 8 +++----- src/core/operations/ToBase58.mjs | 8 +++----- tests/operations/tests/Base58.mjs | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/core/operations/FromBase58.mjs b/src/core/operations/FromBase58.mjs index f5a9ac3d..cb491159 100644 --- a/src/core/operations/FromBase58.mjs +++ b/src/core/operations/FromBase58.mjs @@ -60,7 +60,7 @@ class FromBase58 extends Operation { run(input, args) { let alphabet = args[0] || ALPHABET_OPTIONS[0].value; const removeNonAlphaChars = args[1] === undefined ? true : args[1], - result = [0]; + result = []; alphabet = Utils.expandAlphRange(alphabet).join(""); @@ -87,11 +87,9 @@ class FromBase58 extends Operation { } } - let carry = result[0] * 58 + index; - result[0] = carry & 0xFF; - carry = carry >> 8; + let carry = index; - for (let i = 1; i < result.length; i++) { + for (let i = 0; i < result.length; i++) { carry += result[i] * 58; result[i] = carry & 0xFF; carry = carry >> 8; diff --git a/src/core/operations/ToBase58.mjs b/src/core/operations/ToBase58.mjs index 5353c40e..2e71b20e 100644 --- a/src/core/operations/ToBase58.mjs +++ b/src/core/operations/ToBase58.mjs @@ -43,7 +43,7 @@ class ToBase58 extends Operation { run(input, args) { input = new Uint8Array(input); let alphabet = args[0] || ALPHABET_OPTIONS[0].value, - result = [0]; + result = []; alphabet = Utils.expandAlphRange(alphabet).join(""); @@ -60,11 +60,9 @@ class ToBase58 extends Operation { } input.forEach(function(b) { - let carry = (result[0] << 8) + b; - result[0] = carry % 58; - carry = (carry / 58) | 0; + let carry = b; - for (let i = 1; i < result.length; i++) { + for (let i = 0; i < result.length; i++) { carry += result[i] << 8; result[i] = carry % 58; carry = (carry / 58) | 0; diff --git a/tests/operations/tests/Base58.mjs b/tests/operations/tests/Base58.mjs index c23ba9ab..8090b84b 100644 --- a/tests/operations/tests/Base58.mjs +++ b/tests/operations/tests/Base58.mjs @@ -53,6 +53,28 @@ TestRegister.addTests([ }, ], }, + { + name: "To Base58 all null", + input: "\0\0\0\0\0\0", + expectedOutput: "111111", + recipeConfig: [ + { + op: "To Base58", + args: ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"], + }, + ], + }, + { + name: "From Base58 all null", + input: "111111", + expectedOutput: "\0\0\0\0\0\0", + recipeConfig: [ + { + op: "From Base58", + args: ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"], + }, + ], + }, { name: "To Base58 with null prefix and suffix", input: "\0\0\0Hello\0\0\0", From 0717407beaca592502630b74cb10337a0c633d6e Mon Sep 17 00:00:00 2001 From: a3957273 <89583054+a3957273@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:59:49 +0000 Subject: [PATCH 2/3] Disable 'Extract ID3' Nightwatch tests --- tests/browser/02_ops.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/browser/02_ops.js b/tests/browser/02_ops.js index 7cb0e941..e2b9b28a 100644 --- a/tests/browser/02_ops.js +++ b/tests/browser/02_ops.js @@ -126,8 +126,8 @@ module.exports = { // testOp(browser, "Extract email addresses", "test input", "test_output"); // testOp(browser, "Extract file paths", "test input", "test_output"); testOpFile(browser, "Extract Files", "files/Hitchhikers_Guide.jpeg", ".card:last-child .collapsed", "extracted_at_0x3d38.zlib"); - testOpFile(browser, "Extract ID3", "files/mp3example.mp3", "tr:last-child td:last-child", "Kevin MacLeod"); - // testOp(browser, "Extract IP addresses", "test input", "test_output"); + // This test seems unreliable on GitHub Actions, not reproducible locally. + // testOpFile(browser, "Extract ID3", "files/mp3example.mp3", "tr:last-child td:last-child", "Kevin MacLeod"); // testOp(browser, "Extract IP addresses", "test input", "test_output"); // testOp(browser, "Extract LSB", "test input", "test_output"); // testOp(browser, "Extract MAC addresses", "test input", "test_output"); // testOp(browser, "Extract RGBA", "test input", "test_output"); From 52709f0ecb24d509241c1ab03cc98027d78d1c77 Mon Sep 17 00:00:00 2001 From: zb3 Date: Mon, 1 Apr 2024 18:40:00 +0200 Subject: [PATCH 3/3] Fix Ciphersaber2 key concatenation The concat method does not handle typed arrays as arguments. --- src/core/lib/CipherSaber2.mjs | 2 +- tests/operations/tests/CipherSaber2.mjs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/lib/CipherSaber2.mjs b/src/core/lib/CipherSaber2.mjs index bf3954e9..8189d961 100644 --- a/src/core/lib/CipherSaber2.mjs +++ b/src/core/lib/CipherSaber2.mjs @@ -4,7 +4,7 @@ * @license Apache-2.0 */ export function encode(tempIVP, key, rounds, input) { - const ivp = new Uint8Array(key.concat(tempIVP)); + const ivp = new Uint8Array([...key, ...tempIVP]); const state = new Array(256).fill(0); let j = 0, i = 0; const result = []; diff --git a/tests/operations/tests/CipherSaber2.mjs b/tests/operations/tests/CipherSaber2.mjs index dd675d45..9872c7ef 100644 --- a/tests/operations/tests/CipherSaber2.mjs +++ b/tests/operations/tests/CipherSaber2.mjs @@ -21,13 +21,16 @@ TestRegister.addTests([ ], }, { + // input taken from https://ciphersaber.gurus.org/ name: "CipherSaber2 Decrypt", - input: "\x5d\xd9\x7f\xeb\x77\x3c\x42\x9d\xfe\x9c\x3b\x21\x63\xbd\x53\x38\x18\x7c\x36\x37", - expectedOutput: "helloworld", + input: "\x6f\x6d\x0b\xab\xf3\xaa\x67\x19\x03\x15\x30\xed\xb6\x77" + + "\xca\x74\xe0\x08\x9d\xd0\xe7\xb8\x85\x43\x56\xbb\x14\x48\xe3" + + "\x7c\xdb\xef\xe7\xf3\xa8\x4f\x4f\x5f\xb3\xfd", + expectedOutput: "This is a test of CipherSaber.", recipeConfig: [ { op: "CipherSaber2 Decrypt", - args: [{ "option": "Latin1", "string": "test" }, 20], + args: [{ "option": "Latin1", "string": "asdfg" }, 1], }, ], },