mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -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");
|
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" ? /\s|0x/gi : Utils.regexRep(delim);
|
||||||
data = data.split(delimRegex);
|
data = data.split(delimRegex);
|
||||||
} else {
|
} else {
|
||||||
data = [data];
|
data = [data];
|
||||||
|
@ -113,6 +113,8 @@ export function fromHex(data, delim="Auto", byteLen=2) {
|
||||||
|
|
||||||
const output = [];
|
const output = [];
|
||||||
for (let i = 0; i < data.length; i++) {
|
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) {
|
for (let j = 0; j < data[i].length; j += byteLen) {
|
||||||
output.push(parseInt(data[i].substr(j, byteLen), 16));
|
output.push(parseInt(data[i].substr(j, byteLen), 16));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue