@@ -5,25 +5,25 @@ public class CaesarBruteForce {
5
5
/**
6
6
* Recursively Brute forces a parsed encrypted text, trying out all shifting keys from 1-26, printing out all decryption attempts
7
7
* @param message (String) The encrypted text.
8
- * @param Key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
8
+ * @param key (int) The key used to decrypt the encrypted text and is increment upon a recursive call.
9
9
* @return (String) Concatenated string of all decryption attempts (For unit testing purposes).
10
10
*/
11
- public String decrypt (String message , int Key ) {
11
+ public String decrypt (String message , int key ) {
12
12
final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
13
- if (Key > 26 ){ System .out .println (); return null ; }
13
+ if (key > 26 ){ System .out .println (); return null ; }
14
14
15
15
StringBuilder plainText = new StringBuilder ();
16
16
for (char character : message .toUpperCase ().toCharArray ()) {
17
17
int index = LETTERS .indexOf (character );
18
18
19
19
if (index != -1 ) {
20
- index -= Key ;
20
+ index -= key ;
21
21
//Wrap around index value range[1-26]
22
22
if (index < 0 ) { index += LETTERS .length (); }
23
23
plainText .append (LETTERS .toCharArray ()[index ]);
24
24
} else { plainText .append (character ); }
25
25
}
26
- System .out .println (String .format ("Current Decryption Key %d : %s" , Key , plainText ));
27
- return plainText .append (decrypt (message , Key +1 )).toString ();
26
+ System .out .println (String .format ("Current Decryption Key %d : %s" , key , plainText ));
27
+ return plainText .append (decrypt (message , key +1 )).toString ();
28
28
}
29
29
}
0 commit comments