-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnigma.java
More file actions
32 lines (29 loc) · 1.24 KB
/
Enigma.java
File metadata and controls
32 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright Joan Montas & Andrew Bernal
// All rights reserved.
//
// License under GNU General Public License v3.0
public class Enigma {
private Rotors rotors = new Rotors();
private PlugBoard plugboard = new PlugBoard();
/**Orchestrate the encryption using Enigma's components.
* @param plainText plain text that is to be encrypted.
* @return The cipherText
*/
public String encrypt(String plainText) {
plainText = plainText.toLowerCase();
String cipherText = "";
char c;
for (int i = 0; i < plainText.length(); i++) {
c = plainText.charAt(i);
// NOTE(Andrew) this is debatable, including non alphabetical character
// will expose our secret message. - Joan
if (Character.isAlphabetic(c)) {
c = this.plugboard.plugIn(c);
c = this.rotors.plugIn(c);
c = this.plugboard.plugIn(c);
cipherText = cipherText + c;
}
}
return cipherText;
}
}