From a93d5cfe671a12df945e4085958df2fc11b6303b Mon Sep 17 00:00:00 2001 From: Wan Cheuk Lun Date: Wed, 31 Oct 2018 10:10:17 +0800 Subject: [PATCH] Update keyFinder.js 1. modified the identifiers and used the suitable identifiers for the variables 2. leave the loop when a key is match and found to increase the speed of searching in this stage of development 3. return the key number if founded, return 0 if found nothing --- Ciphers/keyFinder.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Ciphers/keyFinder.js b/Ciphers/keyFinder.js index cb4160c45..b223096c3 100644 --- a/Ciphers/keyFinder.js +++ b/Ciphers/keyFinder.js @@ -5,11 +5,9 @@ Note: This is a draft version, please help to modify, Thanks! function keyFinder(str){ // str is used to get the input of encrypted string const wordbank =["is","Is","am","Am","are","Are","have","Have","has","Has","may","May","be","Be"]; let key = 0; // return zero means the key can not be found - //var shiftNum = 0; //count the number of key shifted let inStr = str.toString(); //convert the input to String let outStr = ""; // store the output value let wordInOutStr = ""; // temporary store the word inside the outStr, it is used for comparison - //document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s) for (let i=0; i<(52); i++){ //try the number of key shifted, the sum of character from a-z and A-Z is 26*2=52 outStr = caesarCipherEncodeAndDecodeEngine(inStr,i); // use the encrytpion engine to decrypt the input string, shiftNum=i for ( let i=0; i