-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncode.java
More file actions
26 lines (21 loc) · 838 Bytes
/
Encode.java
File metadata and controls
26 lines (21 loc) · 838 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
class Encode {
public static void main(String args[]) {
String msg = "This is test";
String encmsg = "";
String decmsg = "";
char[] key = {'D', 'r', 'e', 'w', '.', 'i', 'n', 'c'};
System.out.println("Start message: " + msg);
int msgLen = msg.length();
int keyLen = key.length;
for(int i = 0, k = 0; i < msgLen; i++, k++){
if(k == keyLen) k = 0;
encmsg = encmsg + (char) (msg.charAt(i) ^ key[k]);
}
System.out.println("Encoded message: " + encmsg);
for(int i = 0, k = 0; i < msgLen; i++, k++){
if(k == keyLen) k = 0;
decmsg = decmsg + (char) (encmsg.charAt(i) ^ key[k]);
}
System.out.println("Decoded message: " + decmsg);
}
}