mirror of https://github.com/gchq/CyberChef.git
Merge ae5bc9c5b9
into bbebba6481
This commit is contained in:
commit
3a5a3321ee
|
@ -1292,9 +1292,13 @@ class Utils {
|
|||
return {
|
||||
"Space": " ",
|
||||
"Percent": "%",
|
||||
"Period": ".",
|
||||
"Comma": ",",
|
||||
"Semi-colon": ";",
|
||||
"Colon": ":",
|
||||
"Hyphen": "-",
|
||||
"Hash": "#",
|
||||
"Ampersand": "&",
|
||||
"Tab": "\t",
|
||||
"Line feed": "\n",
|
||||
"CRLF": "\r\n",
|
||||
|
|
|
@ -154,6 +154,8 @@
|
|||
"Enigma",
|
||||
"Bombe",
|
||||
"Multiple Bombe",
|
||||
"Multi Tap Cipher Encode",
|
||||
"Multi Tap Cipher Decode",
|
||||
"Typex",
|
||||
"Lorenz",
|
||||
"Colossus",
|
||||
|
|
|
@ -71,6 +71,27 @@ export function genPolybiusSquare (keyword) {
|
|||
return polybius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a mapping for the MultiTap
|
||||
*
|
||||
* @private
|
||||
* @author Necron3574 [kaustubhbm3574@gmail.com]
|
||||
* @param {int,string} toggle - 1 for encode , 2 for decode, space_delim
|
||||
* @returns {dict}
|
||||
*/
|
||||
export function getMultiTapMap (toggle,space_delim) {
|
||||
var mapping = {"A" :"2","B":"22","C":"222","D":"3","E":"33","F":"333","G":"4","H":"44","I":"444","J":"5","K":"55","L":"555","M":"6","N":"66","O":"666","P":"7","Q":"77","R":"777","S":"7777","T":"8","U":"88","V":"888","W":"9","X":"99","Y":"999","Z":"9999"," ":space_delim};
|
||||
if(toggle == 1)
|
||||
return mapping;
|
||||
else{
|
||||
var ret = {};
|
||||
for(var key in mapping){
|
||||
ret[mapping[key]] = key;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A mapping of string formats to their classes in the CryptoJS library.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author Necron3574 [kaustubhbm3574@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Utils from "../Utils.mjs";
|
||||
import Operation from "../Operation.mjs";
|
||||
import { getMultiTapMap } from "../lib/Ciphers.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Multi Tap Cipher Decode operation
|
||||
*/
|
||||
class MultiTapCipherDecode extends Operation {
|
||||
|
||||
/**
|
||||
* MultiTapCipherDecode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Multi Tap Cipher Decode";
|
||||
this.module = "Default";
|
||||
this.description = "It is a simple substitution cipher which substitutes the alphabets to their corresponding taps on a mobile phone.<br><br>e.g. <code>adg</code> becomes <code>2-3-4</code>";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Multi-tap";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: ["Hyphen","Space", "Comma", "Semi-colon", "Colon", "Line feed"]
|
||||
},
|
||||
{
|
||||
name : "Representation of Space",
|
||||
type: "option",
|
||||
value: ["Hash","Period","Percent","Ampersand"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
if(input.length == 0)
|
||||
return "";
|
||||
const delim = Utils.charRep(args[0] || "Hyphen");
|
||||
const space_delim = Utils.charRep(args[1] || "Hash");
|
||||
var dmap = getMultiTapMap(2,space_delim);
|
||||
var enc_list = input.split(delim);
|
||||
var plaintext = "";
|
||||
for(let i=0;i<enc_list.length;i++){
|
||||
if(dmap[enc_list[i]] == undefined)
|
||||
throw new OperationError("Invalid Input\nThe numbers must range from 2-9 and must be separated by the delimiter chosen");
|
||||
plaintext += dmap[enc_list[i]];
|
||||
}
|
||||
return plaintext;
|
||||
}
|
||||
}
|
||||
|
||||
export default MultiTapCipherDecode;
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* @author Necron3574 [kaustubhbm3574@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import { getMultiTapMap } from "../lib/Ciphers.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
/**
|
||||
* Multi Tap Cipher Encode operation
|
||||
*/
|
||||
class MultiTapCipherEncode extends Operation {
|
||||
|
||||
/**
|
||||
* MultiTapCipherEncode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Multi Tap Cipher Encode";
|
||||
this.module = "Default";
|
||||
this.description = "It is a simple substitution cipher which substitutes the alphabets to their corresponding taps on a mobile phone.<br><br>e.g. <code>adg</code> becomes <code>2-3-4</code>";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Multi-tap";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Delimiter",
|
||||
type: "option",
|
||||
value: ["Hyphen","Space", "Comma", "Semi-colon", "Colon", "Line feed"]
|
||||
},
|
||||
{
|
||||
name : "Representation of Space",
|
||||
type: "option",
|
||||
value: ["Hash","Period","Percent","Ampersand"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const delim = Utils.charRep(args[0] || "Hyphen");
|
||||
const space_delim = Utils.charRep(args[1] || "Hash");
|
||||
var emap = getMultiTapMap(1,space_delim);
|
||||
var plaintext = input.toUpperCase();
|
||||
var ciphertext = "";
|
||||
for(let i=0;i<plaintext.length;++i){
|
||||
if(emap[plaintext.charAt(i)] == undefined)
|
||||
throw new OperationError("The input must be only alphabets");
|
||||
ciphertext += emap[plaintext.charAt(i)];
|
||||
if(i!=plaintext.length-1)
|
||||
ciphertext += delim;
|
||||
}
|
||||
return ciphertext;
|
||||
}
|
||||
}
|
||||
|
||||
export default MultiTapCipherEncode;
|
Loading…
Reference in New Issue