mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
added choice for base85 all-zero character
This commit is contained in:
parent
d77f8ba747
commit
bf4e62b4b7
1 changed files with 9 additions and 3 deletions
|
@ -37,6 +37,11 @@ class FromBase85 extends Operation {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
value: true
|
value: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "All-zero group char",
|
||||||
|
type: "binaryShortString",
|
||||||
|
value: "z"
|
||||||
|
},
|
||||||
];
|
];
|
||||||
this.checks = [
|
this.checks = [
|
||||||
{
|
{
|
||||||
|
@ -78,6 +83,7 @@ class FromBase85 extends Operation {
|
||||||
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
||||||
encoding = alphabetName(alphabet),
|
encoding = alphabetName(alphabet),
|
||||||
removeNonAlphChars = args[1],
|
removeNonAlphChars = args[1],
|
||||||
|
allZeroGroupChar = args[2],
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
if (alphabet.length !== 85 ||
|
if (alphabet.length !== 85 ||
|
||||||
|
@ -91,7 +97,7 @@ class FromBase85 extends Operation {
|
||||||
|
|
||||||
// Remove non-alphabet characters
|
// Remove non-alphabet characters
|
||||||
if (removeNonAlphChars) {
|
if (removeNonAlphChars) {
|
||||||
const re = new RegExp("[^" + "z~" +alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
const re = new RegExp("[^~" + allZeroGroupChar +alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
||||||
input = input.replace(re, "");
|
input = input.replace(re, "");
|
||||||
// Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)
|
// Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)
|
||||||
const matches = input.match(/^<~(.+?)~>$/);
|
const matches = input.match(/^<~(.+?)~>$/);
|
||||||
|
@ -103,7 +109,7 @@ class FromBase85 extends Operation {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let block, blockBytes;
|
let block, blockBytes;
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
if (encoding === "Standard" && input[i] === "z") {
|
if (encoding === "Standard" && input[i] === allZeroGroupChar) {
|
||||||
result.push(0, 0, 0, 0);
|
result.push(0, 0, 0, 0);
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -113,7 +119,7 @@ class FromBase85 extends Operation {
|
||||||
.split("")
|
.split("")
|
||||||
.map((chr, idx) => {
|
.map((chr, idx) => {
|
||||||
const digit = alphabet.indexOf(chr);
|
const digit = alphabet.indexOf(chr);
|
||||||
if ((digit < 0 || digit > 84) && chr !== "z") {
|
if ((digit < 0 || digit > 84) && chr !== allZeroGroupChar) {
|
||||||
throw `Invalid character '${chr}' at index ${i + idx}`;
|
throw `Invalid character '${chr}' at index ${i + idx}`;
|
||||||
}
|
}
|
||||||
return digit;
|
return digit;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue