-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharistocratencrypt.java
55 lines (44 loc) · 2.34 KB
/
aristocratencrypt.java
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package willcrack;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class aristocratencrypt {
String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String[] shuffle2 = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
String[] capitalLetters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
String[] shuffle3 = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
String letterIndividual = "";
public aristocratencrypt(String msg) {
Collections.shuffle(Arrays.asList(shuffle2));
Collections.shuffle(Arrays.asList(shuffle3));
for (int i = 0; i < msg.length(); i++) {
letterIndividual = msg.substring(i, i+1);
// Check if letterIndividual is a lowercase letter
int lowercaseIndex = Arrays.asList(letters).indexOf(letterIndividual);
if (lowercaseIndex >= 0) {
System.out.print(shuffle2[lowercaseIndex]);
}
// Check if letterIndividual is a capital letter
else {
int capitalIndex = Arrays.asList(capitalLetters).indexOf(letterIndividual);
if (capitalIndex >= 0) {
System.out.print(shuffle3[capitalIndex]);
}
// letterIndividual is not a letter, print it out as is
else {
System.out.print(letterIndividual);
}
}
}
System.out.println("");
}
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
System.out.println("Enter plaintext");
System.out.print("Original: ");
String cipher = myObj.nextLine();
// System.out.println("Cipher: " + cipher);
System.out.print("Encoded message: ");
aristocratencrypt decode = new aristocratencrypt(cipher);
}
}