From 6d5c9921233c883643d508c4ba84a8ca781ffcd1 Mon Sep 17 00:00:00 2001 From: Kaustubh BM Date: Thu, 13 May 2021 21:56:43 +0530 Subject: [PATCH] Add MultiTapCipherEncode.mjs This is the code to execute the Multi Tap Cipher Encode operation. It takes a string input and returns the number of taps required separated by a delimiter which can be chosen by the user. More info - https://en.wikipedia.org/wiki/Multi-tap --- src/core/operations/MultiTapCipherEncode.mjs | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/core/operations/MultiTapCipherEncode.mjs diff --git a/src/core/operations/MultiTapCipherEncode.mjs b/src/core/operations/MultiTapCipherEncode.mjs new file mode 100644 index 00000000..0db95ef5 --- /dev/null +++ b/src/core/operations/MultiTapCipherEncode.mjs @@ -0,0 +1,62 @@ +/** + * @author Necron3574 [kaustubhbm3574@gmail.com] + * @copyright Crown Copyright 2021 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import Utils from "../Utils.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.

e.g. adg becomes 2-3-4"; + 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"] + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const delim = Utils.charRep(args[0] || "Hyphen"); + var emap = {"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"," ":" "}; + input = input.toUpperCase(); + var plaintext = ""; + for(let i= 0;i