mirror of
https://github.com/gchq/CyberChef.git
synced 2026-02-05 06:50:35 -08:00
Check that the entered dictionary is valid to remove the default dictionary
This commit is contained in:
parent
67dc0f7412
commit
b1105b0e21
3 changed files with 80 additions and 3 deletions
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
|
||||
|
||||
|
|
@ -65,11 +66,14 @@ class FromBase32 extends Operation {
|
|||
run(input, args) {
|
||||
if (!input) return [];
|
||||
|
||||
const alphabet = args[0] ?
|
||||
Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
||||
const alphabet = Utils.expandAlphRange(args[0]).join(""),
|
||||
removeNonAlphChars = args[1],
|
||||
output = [];
|
||||
|
||||
if (alphabet.length !== 33) {
|
||||
throw new OperationError("Alphabet must be of length 33"); // 32 characters + 1 padding
|
||||
}
|
||||
|
||||
let chr1, chr2, chr3, chr4, chr5,
|
||||
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
|
||||
i = 0;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import {ALPHABET_OPTIONS} from "../lib/Base32.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* To Base32 operation
|
||||
|
|
@ -43,7 +44,11 @@ class ToBase32 extends Operation {
|
|||
if (!input) return "";
|
||||
input = new Uint8Array(input);
|
||||
|
||||
const alphabet = args[0] ? Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=";
|
||||
const alphabet = Utils.expandAlphRange(args[0]).join("");
|
||||
if (alphabet.length !== 33) {
|
||||
throw new OperationError("Alphabet must be of length 33"); // 32 characters + 1 padding
|
||||
}
|
||||
|
||||
let output = "",
|
||||
chr1, chr2, chr3, chr4, chr5,
|
||||
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ const ALL_BYTES_EXTENDED_OUT = "000G40O40K30E209185GO38E1S8124GJ2GAHC5OO34D1M70T
|
|||
const ALL_BYTES_STANDARD_OUT = "AAAQEAYEAUDAOCAJBIFQYDIOB4IBCEQTCQKRMFYYDENBWHA5DYPSAIJCEMSCKJRHFAUSUKZMFUXC6MBRGIZTINJWG44DSOR3HQ6T4P2AIFBEGRCFIZDUQSKKJNGE2TSPKBIVEU2UKVLFOWCZLJNVYXK6L5QGCYTDMRSWMZ3INFVGW3DNNZXXA4LSON2HK5TXPB4XU634PV7H7AEBQKBYJBMGQ6EITCULRSGY5D4QSGJJHFEVS2LZRGM2TOOJ3HU7UCQ2FI5EUWTKPKFJVKV2ZLNOV6YLDMVTWS23NN5YXG5LXPF5X274BQOCYPCMLRWHZDE4VS6MZXHM7UGR2LJ5JVOW27MNTWW33TO55X7A4HROHZHF43T6R2PK5PWO33XP6DY7F47U6X3PP6HZ7L57Z7P674======";
|
||||
const ALL_BYTES_CROCKFORD_OUT = "000G40R40M30E209185GR38E1W8124GK2GAHC5RR34D1P70X3RFJ08924CJ2A9H750MJMASC5MQ2YC1H68SK8D9P6WW3JEHV7GYKWFT085146H258S3MGJAA9D64TKJFA18N4MTMANB5EP2SB9DNRQAYBXG62RK3CHJPCSV8D5N6PV3DDSQQ0WBJEDT7AXKQF1WQMYVWFNZ7Z041GA1R91C6GY48K2MBHJ6RX3WGJ699754NJTBSH6CTKEE9V7MZM2GT58X4MPKAFA59NANTSBDENYRB3CNKPJTVDDXRQ6XBQF5XQTZW1GE2RF2CBHP7S34WNJYCSQ7CZM6HTB9X9NEPTZCDKPPVVKEXXQZ0W7HE7S75WVKYHTFAXFPEVVQFY3RZ5WZMYQVFFY7SZBXZSZFYZW======";
|
||||
|
||||
const WRONG_ALPHABET = "Alphabet must be of length 33"
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base32 Standard: nothing",
|
||||
|
|
@ -243,5 +245,71 @@ TestRegister.addTests([
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Standard: wrong alphabet",
|
||||
input: STANDARD_INP,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [""],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Hex Extended: wrong alphabet",
|
||||
input: EXTENDED_INP,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [""],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base32 Crockford: wrong alphabet",
|
||||
input: CROCKFORD_INP,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base32",
|
||||
args: [""],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Standard: wrong alphabet",
|
||||
input: STANDARD_OUT,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: ["", false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Hex Extended: wrong alphabet",
|
||||
input: EXTENDED_OUT,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: ["", false],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base32 Crockford: wrong alphabet",
|
||||
input: CROCKFORD_OUT,
|
||||
expectedOutput: WRONG_ALPHABET,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base32",
|
||||
args: ["", false],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue