mirror of
https://github.com/gchq/CyberChef
synced 2025-01-15 22:13:56 +00:00
Tidied up Base45 ops
This commit is contained in:
parent
709b8696fc
commit
4f0b160ed3
4 changed files with 23 additions and 12 deletions
|
@ -24,4 +24,4 @@ export function highlightFromBase45(pos, args) {
|
|||
return pos;
|
||||
}
|
||||
|
||||
export const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
||||
export const ALPHABET = "0-9A-Z $%*+\\-./:";
|
||||
|
|
|
@ -27,6 +27,13 @@ class FromBase45 extends Operation {
|
|||
this.infoURL = "https://wikipedia.org/wiki/List_of_numeral_systems";
|
||||
this.inputType = "string";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [
|
||||
{
|
||||
name: "Alphabet",
|
||||
type: "string",
|
||||
value: ALPHABET
|
||||
}
|
||||
];
|
||||
|
||||
this.highlight = highlightFromBase45;
|
||||
this.highlightReverse = highlightToBase45;
|
||||
|
@ -39,6 +46,7 @@ class FromBase45 extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
if (!input) return [];
|
||||
const alphabet = Utils.expandAlphRange(args[0]);
|
||||
|
||||
const res = [];
|
||||
|
||||
|
@ -46,7 +54,7 @@ class FromBase45 extends Operation {
|
|||
triple.reverse();
|
||||
let b = 0;
|
||||
for (const c of triple) {
|
||||
const idx = ALPHABET.indexOf(c);
|
||||
const idx = alphabet.indexOf(c);
|
||||
if (idx === -1) {
|
||||
throw new OperationError(`Character not in alphabet: '${c}'`);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ToBase45 extends Operation {
|
|||
{
|
||||
name: "Alphabet",
|
||||
type: "string",
|
||||
value: "0-9A-Za-z"
|
||||
value: ALPHABET
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -44,6 +44,7 @@ class ToBase45 extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
input = new Uint8Array(input);
|
||||
const alphabet = Utils.expandAlphRange(args[0]);
|
||||
if (!input) return "";
|
||||
|
||||
const res = [];
|
||||
|
@ -57,7 +58,7 @@ class ToBase45 extends Operation {
|
|||
|
||||
let chars = 0;
|
||||
do {
|
||||
res.push(ALPHABET[b % 45]);
|
||||
res.push(alphabet[b % 45]);
|
||||
chars++;
|
||||
b = Math.floor(b / 45);
|
||||
} while (b > 0);
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const defaultB45Alph = "0-9A-Z $%*+\\-./:";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base45: nothing",
|
||||
|
@ -17,7 +19,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -28,7 +30,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -39,7 +41,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -50,7 +52,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -61,7 +63,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -72,7 +74,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -83,7 +85,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -94,7 +96,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [],
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue