mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 07:16:17 -04:00
Update Hex.mjs
This commit is contained in:
parent
fed10f3ee6
commit
0e44e9c5ce
1 changed files with 3 additions and 1 deletions
|
@ -105,7 +105,7 @@ 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);
|
||||
const delimRegex = delim === "Auto" ? /\s|0x/gi : Utils.regexRep(delim);
|
||||
data = data.split(delimRegex);
|
||||
} else {
|
||||
data = [data];
|
||||
|
@ -113,6 +113,8 @@ export function fromHex(data, delim="Auto", byteLen=2) {
|
|||
|
||||
const output = [];
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (/[^a-f\d]/.test(data[i]))
|
||||
throw new OperationError("Hex input must only contain hex digits");
|
||||
for (let j = 0; j < data[i].length; j += byteLen) {
|
||||
output.push(parseInt(data[i].substr(j, byteLen), 16));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue