From 7a04d2ad867fb7081fae96452561a20549d7235b Mon Sep 17 00:00:00 2001 From: Wan Cheuk Lun Date: Tue, 30 Oct 2018 11:20:32 +0800 Subject: [PATCH] Update keyFinder.js Made 2 changes to optimize the match results: 1. use a loop to find the next digit of wordbank element and compare with outStr's digit 2. this part need to be optimize with the calculation of the number of occurance of word's probabilities --- Ciphers/keyFinder.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Ciphers/keyFinder.js b/Ciphers/keyFinder.js index 30b02097e..8dda33c3e 100644 --- a/Ciphers/keyFinder.js +++ b/Ciphers/keyFinder.js @@ -8,11 +8,17 @@ function keyFinder(str){ // str is used to get the input of encrypted string //var shiftNum = 0; //count the number of key shifted var inStr = str.toString(); //convert the input to String var outStr = ""; // store the output value + var 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 (var 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 ( var i=0; i