-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.java
More file actions
30 lines (22 loc) · 792 Bytes
/
Copy pathEncryption.java
File metadata and controls
30 lines (22 loc) · 792 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
package otp;
public class Encryption {
public static String generateBinaryCipher(String binaryText, String binaryKey) {
// Applying XOR logical operator;
String binaryCipher = "";
int len;
String sub = "";
// substring should not include the last index of shorter string
if (binaryText.length() < binaryKey.length()) {
len = binaryText.length();
sub = binaryKey.substring(len);
} else {
len = binaryKey.length();
sub = binaryText.substring(len);
}
for (int i = 0; i < len; i++) {
int result = binaryText.charAt(i) ^ binaryKey.charAt(i);
binaryCipher += String.valueOf(result);
}
return binaryCipher.concat(sub);
}
}