@@ -3,23 +3,24 @@ Find and retrieve the encryption key automatically
3
3
Note: This is a draft version, please help to modify, Thanks!
4
4
******************************************************/
5
5
function keyFinder ( str ) { // str is used to get the input of encrypted string
6
- var key = 0 ; // return zero means the key can not be found
7
- var wordbank = [ "is" , "Is" , "am" , "Am" , "are" , "Are" , "have" , "Have" , "has" , "Has" , "may" , "May" , "be" , "Be" ] ;
6
+ const wordbank = [ "is" , "Is" , "am" , "Am" , "are" , "Are" , "have" , "Have" , "has" , "Has" , "may" , "May" , "be" , "Be" ] ;
7
+ let key = 0 ; // return zero means the key can not be found
8
8
//var shiftNum = 0; //count the number of key shifted
9
- var inStr = str . toString ( ) ; //convert the input to String
10
- var outStr = "" ; // store the output value
11
- var wordInOutStr = "" ; // temporary store the word inside the outStr, it is used for comparison
9
+ let inStr = str . toString ( ) ; //convert the input to String
10
+ let outStr = "" ; // store the output value
11
+ let wordInOutStr = "" ; // temporary store the word inside the outStr, it is used for comparison
12
12
//document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
13
- 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
13
+ 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
14
14
outStr = caesarCipherEncodeAndDecodeEngine ( inStr , i ) ; // use the encrytpion engine to decrypt the input string, shiftNum=i
15
- for ( var i = 0 ; i < wordbank . length ; i ++ ) {
15
+ for ( let i = 0 ; i < wordbank . length ; i ++ ) {
16
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 ++ ) {
17
+ for ( let j = 0 ; j < wordbank [ i ] . length ; j ++ ) {
18
18
wordInOutStr += outStr [ i + j ] ;
19
19
}
20
20
// this part need to be optimize with the calculation of the number of occurance of word's probabilities
21
+ // linked list will be used in the next stage of development to calculate the number of occurace of the key
21
22
if ( wordbank [ i ] == wordInOutStr ) {
22
- key = i ;
23
+ return key = i ;
23
24
}
24
25
}
25
26
}
0 commit comments