From 75d7ef53dc7553a274ac0ff980940794e7ba880b Mon Sep 17 00:00:00 2001 From: Wan Cheuk Lun Date: Wed, 31 Oct 2018 16:54:20 +0800 Subject: [PATCH] Update keyFinder.js Finally, there are several changes in the function keyFinder(str) that make it works well --- Ciphers/keyFinder.js | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/Ciphers/keyFinder.js b/Ciphers/keyFinder.js index 8e16dedb5..4186eae0a 100644 --- a/Ciphers/keyFinder.js +++ b/Ciphers/keyFinder.js @@ -3,24 +3,40 @@ Find and retrieve the encryption key automatically 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 + const wordbank =[" the ","The "," of "," is ","Is "," am ","Am "," are ","Are "," have ","Have "," has ","Has "," may ","May "," be ","Be "]; + //let wordbankelementCounter = 0; + //let key = 0; // return zero means the key can not be found 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 - 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