mirror of
https://github.com/gchq/CyberChef
synced 2025-02-15 04:48:23 +00: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",
|
||||
value: true
|
||||
},
|
||||
{
|
||||
name: "All-zero group char",
|
||||
type: "binaryShortString",
|
||||
value: "z"
|
||||
},
|
||||
];
|
||||
this.checks = [
|
||||
{
|
||||
|
@ -78,6 +83,7 @@ class FromBase85 extends Operation {
|
|||
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
||||
encoding = alphabetName(alphabet),
|
||||
removeNonAlphChars = args[1],
|
||||
allZeroGroupChar = args[2],
|
||||
result = [];
|
||||
|
||||
if (alphabet.length !== 85 ||
|
||||
|
@ -91,7 +97,7 @@ class FromBase85 extends Operation {
|
|||
|
||||
// Remove non-alphabet characters
|
||||
if (removeNonAlphChars) {
|
||||
const re = new RegExp("[^" + "z~" +alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
||||
const re = new RegExp("[^~" + allZeroGroupChar +alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
||||
input = input.replace(re, "");
|
||||
// Remove delimiters again if present (incase of non-alphabet characters in front/behind delimiters)
|
||||
const matches = input.match(/^<~(.+?)~>$/);
|
||||
|
@ -103,7 +109,7 @@ class FromBase85 extends Operation {
|
|||
let i = 0;
|
||||
let block, blockBytes;
|
||||
while (i < input.length) {
|
||||
if (encoding === "Standard" && input[i] === "z") {
|
||||
if (encoding === "Standard" && input[i] === allZeroGroupChar) {
|
||||
result.push(0, 0, 0, 0);
|
||||
i++;
|
||||
} else {
|
||||
|
@ -113,7 +119,7 @@ class FromBase85 extends Operation {
|
|||
.split("")
|
||||
.map((chr, idx) => {
|
||||
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}`;
|
||||
}
|
||||
return digit;
|
||||
|
|
Loading…
Add table
Reference in a new issue