You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//var shiftNum = 0; //count the number of key shifted
9
-
varinStr=str.toString();//convert the input to String
10
-
varoutStr="";// store the output value
11
-
varwordInOutStr="";// temporary store the word inside the outStr, it is used for comparison
12
-
//document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
13
-
for(vari=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
-
outStr=caesarCipherEncodeAndDecodeEngine(inStr,i);// use the encrytpion engine to decrypt the input string, shiftNum=i
15
-
for(vari=0;i<wordbank.length;i++){
16
-
// use a loop to find the next digit of wordbank element and compare with outStr's digit
17
-
for(varj=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){
22
-
key=i;
6
+
constwordbank=["I ","You ","We ","They ","He ","She ","It "," the ","The "," of "," is ","Is "," am ","Am "," are ","Are "," have ","Have "," has ","Has "," may ","May "," be ","Be "];
7
+
//let wordbankelementCounter = 0;
8
+
//let key = 0; // return zero means the key can not be found
9
+
letinStr=str.toString();//convert the input to String
10
+
letoutStr="";// store the output value
11
+
letoutStrElement="";// temporary store the word inside the outStr, it is used for comparison
12
+
for(letk=0;k<26;k++){//try the number of key shifted, the sum of character from a-z or A-Z is 26
13
+
outStr=caesarCipherEncodeAndDecodeEngine(inStr,k);// use the encrytpion engine to decrypt the input string
14
+
15
+
//loop through the whole input string
16
+
for(lets=0;s<outStr.length;s++){
17
+
18
+
for(leti=0;i<wordbank.length;i++){
19
+
20
+
// initialize the outStrElement which is a temp output string for comparison,
21
+
// use a loop to find the next digit of wordbank element and compare with outStr's digit
22
+
for(letw=0;w<wordbank[i].length;w++){
23
+
outStrElement+=outStr[s+w];
24
+
}
25
+
26
+
//console.log( k + outStrElement + wordbank[i] );//debug
27
+
28
+
// this part need to be optimize with the calculation of the number of occurance of word's probabilities
29
+
// linked list will be used in the next stage of development to calculate the number of occurace of the key
30
+
if(wordbank[i]==outStrElement){
31
+
returnk;// return the key number if founded
32
+
}
33
+
34
+
outStrElement="";//reset the temp word
35
+
36
+
}// end for ( let i=0; i < wordbank.length; i++)
37
+
38
+
}
39
+
40
+
}
41
+
return0;// return 0 if found nothing
42
+
}
43
+
44
+
/* this sub-function is used to assist the keyfinder to find the key */
0 commit comments