-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleXor.java
More file actions
39 lines (28 loc) · 938 Bytes
/
SimpleXor.java
File metadata and controls
39 lines (28 loc) · 938 Bytes
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
import java.util.Scanner;
public class SimpleXor {
public static void main(String[] args) {
String message, key, result = "", verify = "";
Scanner kb = new Scanner(System.in);
System.out.println("Enter a message to xor:");
message = kb.nextLine();
System.out.println("Enter a key (of the same length for now):");
key = kb.nextLine();
for(int i = 0; i < message.length(); i++) {
result = result + " " + (message.charAt(i) ^ key.charAt(i));
}
System.out.println(result);
verifyXor(message, key, result);
}
private static void verifyXor(String message, String key, String r) {
String[] cmpStr = r.split(" ");
int num;
char xorMe;
String result = "";
for(int i = 1; i < cmpStr.length; i++) {
num = Integer.parseInt(cmpStr[i]);
xorMe = key.charAt(i - 1);
result = result + (char)(num ^ xorMe);
}
System.out.println(result);
}
}