mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-24 00:36:16 -04:00
Merge branch 'master' of https://github.com/TheSavageTeddy/CyberChef
This commit is contained in:
commit
157346b055
2 changed files with 34 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,8 +97,11 @@ class FromBase85 extends Operation {
|
|||
|
||||
// Remove non-alphabet characters
|
||||
if (removeNonAlphChars) {
|
||||
const re = new RegExp("[^" + 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(/^<~(.+?)~>$/);
|
||||
if (matches !== null) input = matches[1];
|
||||
}
|
||||
|
||||
if (input.length === 0) return [];
|
||||
|
@ -100,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 {
|
||||
|
@ -110,7 +119,7 @@ class FromBase85 extends Operation {
|
|||
.split("")
|
||||
.map((chr, idx) => {
|
||||
const digit = alphabet.indexOf(chr);
|
||||
if (digit < 0 || digit > 84) {
|
||||
if ((digit < 0 || digit > 84) && chr !== allZeroGroupChar) {
|
||||
throw `Invalid character '${chr}' at index ${i + idx}`;
|
||||
}
|
||||
return digit;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue