1
0
mirror of synced 2025-02-22 12:50:36 +01:00

Merge branch 'from-hex-use-delimiter-as-delimiter' of https://github.com/mikecat/CyberChef

This commit is contained in:
n1474335 2022-11-25 11:59:25 +00:00
commit 8349ffc001
2 changed files with 14 additions and 10 deletions

View File

@ -105,13 +105,17 @@ export function fromHex(data, delim="Auto", byteLen=2) {
throw new OperationError("Byte length must be a positive integer"); throw new OperationError("Byte length must be a positive integer");
if (delim !== "None") { if (delim !== "None") {
const delimRegex = delim === "Auto" ? /[^a-f\d]|(0x)/gi : Utils.regexRep(delim); const delimRegex = delim === "Auto" ? /[^a-f\d]|0x/gi : Utils.regexRep(delim);
data = data.replace(delimRegex, ""); data = data.split(delimRegex);
} else {
data = [data];
} }
const output = []; const output = [];
for (let i = 0; i < data.length; i += byteLen) { for (let i = 0; i < data.length; i++) {
output.push(parseInt(data.substr(i, byteLen), 16)); for (let j = 0; j < data[i].length; j += byteLen) {
output.push(parseInt(data[i].substr(j, byteLen), 16));
}
} }
return output; return output;
} }

View File

@ -45,10 +45,10 @@ TestRegister.addApiTests([
const result = chef.ADD("sample input", { const result = chef.ADD("sample input", {
key: { key: {
string: "some key", string: "some key",
option: "Hex" option: "utf8"
} }
}); });
assert.equal(result.toString(), "aO[^ZS\u000eW\\^cb"); assert.equal(result.toString(), "\xe6\xd0\xda\xd5\x8c\xd0\x85\xe2\xe1\xdf\xe2\xd9");
}), }),
@ -121,10 +121,10 @@ Tiger-128`;
const result = chef.AND("Scot-free", { const result = chef.AND("Scot-free", {
key: { key: {
string: "Raining Cats and Dogs", string: "Raining Cats and Dogs",
option: "Hex", option: "utf8",
} }
}); });
assert.strictEqual(result.toString(), "\u0000\"M$(D E"); assert.strictEqual(result.toString(), "Raid)fb A");
}), }),
it("atBash Cipher", () => { it("atBash Cipher", () => {
@ -371,10 +371,10 @@ color: white;
}, },
salt: { salt: {
string: "Market", string: "Market",
option: "Hex", option: "utf8",
}, },
}); });
assert.strictEqual(result.toString(), "7c21a9f5063a4d62fb1050068245c181"); assert.strictEqual(result.toString(), "4930d5d200e80f18c96b5550d13c6af8");
}), }),
it("Derive PBKDF2 Key", () => { it("Derive PBKDF2 Key", () => {