Skip to content

Commit 6331056

Browse files
authored
Create keyFinder
Find and retrieve the encryption key automatically Note: This is a draft version, please help to modify, Thanks!
1 parent 7b82729 commit 6331056

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Ciphers/keyFinder

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/******************************************************
2+
Find and retrieve the encryption key automatically
3+
Note: This is a draft version, please help to modify, Thanks!
4+
******************************************************/
5+
function keyFinder(){
6+
var result = "";
7+
var key = 0;
8+
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
11+
var inStr = str.toString(); //convert the input to String
12+
var outStr = ""; // store the output value
13+
document.getElementById("debug").innerHTML = shiftNum;
14+
for (var i=0; i<26; i++){
15+
outStr = caesarCipherEncodeAndDecodeEngine(inStr,i); // use the encrytpion engine to decrypt the input string, shiftNum=i
16+
for ( var i=0; i<wordbank.length; i++){
17+
if (wordbank[i] == outStr[i]+outStr[i+1]{
18+
key=i;
19+
}
20+
}
21+
}
22+
return key;
23+
}

0 commit comments

Comments
 (0)