Skip to content

Create keyFinder.js #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 30, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Ciphers/keyFinder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/******************************************************
Find and retrieve the encryption key automatically
Note: This is a draft version, please help to modify, Thanks!
******************************************************/
function keyFinder(str){ // str is used to get the input of encrypted string
var key = 0; // return zero means the key can not be found
var wordbank =["is","Is","am","Am","are","Are","have","Have","has","Has","may","May","be","Be"];
//var shiftNum = 0; //count the number of key shifted
var inStr = str.toString(); //convert the input to String
var outStr = ""; // store the output value
//document.getElementById("debug").innerHTML = shiftNum; // debug: display the shifted number(s)
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
outStr = caesarCipherEncodeAndDecodeEngine(inStr,i); // use the encrytpion engine to decrypt the input string, shiftNum=i
for ( var i=0; i<wordbank.length; i++){
if (wordbank[i] == outStr[i]+outStr[i+1]{
key=i;
}
}
}
return key;
}