From ae5bc9c5b97395446e15a31e4087f549a2a23cd1 Mon Sep 17 00:00:00 2001 From: Kaustubh BM Date: Fri, 14 May 2021 18:29:39 +0530 Subject: [PATCH] Update Ciphers.mjs Added a method called getMultiTapMap() which takes the arguments of toggle{int} and space_delim {string}. This function creates a dictionary for the Multi Tap Cipher Encoding Scheme. If the toggle is 1, it returns the dictionary directly. else it reverses the dictionary and returns it, enabling it to be used in the decode operation. --- src/core/lib/Ciphers.mjs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/lib/Ciphers.mjs b/src/core/lib/Ciphers.mjs index a4d174b5..1f741db3 100644 --- a/src/core/lib/Ciphers.mjs +++ b/src/core/lib/Ciphers.mjs @@ -65,6 +65,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. *