-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.java
More file actions
62 lines (44 loc) · 1.72 KB
/
Copy pathMessage.java
File metadata and controls
62 lines (44 loc) · 1.72 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package otp;
public class Message {
private String key;
private String message;
private String binaryCipher;
private String binaryText;
private String binaryKey;
private String cipherText;
/*
* -----------------------------------------------------
* Encryption
* -----------------------------------------------------
* get the message and convert it to binary
* generate random key and convert it to binary
* apply OTP algorithms
* generate cipther binary
* convert it to string [option]
*/
public String encrypt(String message) {
this.message = message;
this.key = RandomKey.generate(this.message.length());
this.binaryText = BinarySystem.convertDecimalToBinary(this.message);
this.binaryKey = BinarySystem.convertDecimalToBinary(this.key);
this.binaryCipher = Encryption.generateBinaryCipher(this.binaryText, this.binaryKey);
// should cipher convert to text and diplay it in the screen;
this.cipherText = BinarySystem.convertBinaryToString(this.binaryCipher);
return this.cipherText;
}
/*
* -------------------------------------------------------
* Decryption
* -------------------------------------------------------
* get the cipher binary and key binary
* apply logical operator
* reverse each 8 bits
* convert each 8 bits from binary to decimal system
* return the plain text
*/
public String decrypt() {
// it takes key binary and cipher binary
String textBinaryDecrypted = Decryption.generatePlainText(this.binaryCipher, this.binaryKey);
return BinarySystem.convertBinaryToString(textBinaryDecrypted);
}
}