Skip to content

Commit 7a04d2a

Browse files
authored
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
1 parent e41ad76 commit 7a04d2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Ciphers/keyFinder.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ function keyFinder(str){ // str is used to get the input of encrypted string
88
//var shiftNum = 0; //count the number of key shifted
99
var inStr = str.toString(); //convert the input to String
1010
var outStr = ""; // store the output value
11+
var wordInOutStr = ""; // temporary store the word inside the outStr, it is used for comparison
1112
//document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
1213
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
1314
outStr = caesarCipherEncodeAndDecodeEngine(inStr,i); // use the encrytpion engine to decrypt the input string, shiftNum=i
1415
for ( var i=0; i<wordbank.length; i++){
15-
if (wordbank[i] == outStr[i]+outStr[i+1]{
16+
// use a loop to find the next digit of wordbank element and compare with outStr's digit
17+
for ( var j=0; j < wordbank[i].length; j++){
18+
wordInOutStr += outStr[i+j];
19+
}
20+
// this part need to be optimize with the calculation of the number of occurance of word's probabilities
21+
if (wordbank[i] == wordInOutStr){
1622
key=i;
1723
}
1824
}

0 commit comments

Comments
 (0)