Skip to content

Commit e41ad76

Browse files
authored
Update keyFinder.js
some changes is made to optimize the function
1 parent e0fa99b commit e41ad76

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Ciphers/keyFinder.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
Find and retrieve the encryption key automatically
33
Note: This is a draft version, please help to modify, Thanks!
44
******************************************************/
5-
function keyFinder(){
6-
var result = "";
7-
var key = 0;
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
87
var wordbank =["is","Is","am","Am","are","Are","have","Have","has","Has","may","May","be","Be"];
9-
var shiftNum = 0; //count the number of key shifted
10-
var str = document.getElementById("encryptedID").value; //get the input string
8+
//var shiftNum = 0; //count the number of key shifted
119
var inStr = str.toString(); //convert the input to String
1210
var outStr = ""; // store the output value
13-
document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
14-
for (var i=0; i<26; i++){
11+
//document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
12+
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
1513
outStr = caesarCipherEncodeAndDecodeEngine(inStr,i); // use the encrytpion engine to decrypt the input string, shiftNum=i
1614
for ( var i=0; i<wordbank.length; i++){
1715
if (wordbank[i] == outStr[i]+outStr[i+1]{

0 commit comments

Comments
 (0)