Skip to content

Commit

Permalink
have "From Hex" treat the delimiter as delimiter, not what to erase
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecat committed Nov 2, 2022
1 parent ed8bd34 commit c046cf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/core/lib/Hex.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ export function fromHex(data, delim="Auto", byteLen=2) {
throw new OperationError("Byte length must be a positive integer");

if (delim !== "None") {
const delimRegex = delim === "Auto" ? /[^a-f\d]|(0x)/gi : Utils.regexRep(delim);
data = data.replace(delimRegex, "");
const delimRegex = delim === "Auto" ? /[^a-f\d]|0x/gi : Utils.regexRep(delim);
data = data.split(delimRegex);
} else {
data = [data];
}

const output = [];
for (let i = 0; i < data.length; i += byteLen) {
output.push(parseInt(data.substr(i, byteLen), 16));
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].length; j += byteLen) {
output.push(parseInt(data[i].substr(j, byteLen), 16));
}
}
return output;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/node/tests/operations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ TestRegister.addApiTests([
const result = chef.ADD("sample input", {
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");
}),


Expand Down Expand Up @@ -121,10 +121,10 @@ Tiger-128`;
const result = chef.AND("Scot-free", {
key: {
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", () => {
Expand Down Expand Up @@ -371,10 +371,10 @@ color: white;
},
salt: {
string: "Market",
option: "Hex",
option: "utf8",
},
});
assert.strictEqual(result.toString(), "7c21a9f5063a4d62fb1050068245c181");
assert.strictEqual(result.toString(), "4930d5d200e80f18c96b5550d13c6af8");
}),

it("Derive PBKDF2 Key", () => {
Expand Down

0 comments on commit c046cf5

Please sign in to comment.