Skip to content

Commit 6c894a2

Browse files
authored
Update keyFinder.js
modified used the suitable identifier for the variables
1 parent 9cabd46 commit 6c894a2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Ciphers/keyFinder.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ Find and retrieve the encryption key automatically
33
Note: This is a draft version, please help to modify, Thanks!
44
******************************************************/
55
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
88
//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
1212
//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
1414
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++){
1616
// 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++){
1818
wordInOutStr += outStr[i+j];
1919
}
2020
// 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
2122
if (wordbank[i] == wordInOutStr){
22-
key=i;
23+
return key=i;
2324
}
2425
}
2526
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy