-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathECB.java
46 lines (30 loc) · 1.18 KB
/
ECB.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
package com.houarizegai.cryptography.symmetric;
/* Electronic Code Book */
public class ECB {
public String encrypt(String input, String key) {
// This function receive bits and encrypt
input = Tools.wordsToBits(input);
input = Tools.fillBy0(input, key.length());
String blocs[] = Tools.deviseToBloc(input, key.length());
for(int i=0; i < blocs.length; i++) {
blocs[i] = Tools.e(blocs[i], key);
}
String result = "";
for(String str : blocs)
result += str;
return Tools.bitsToWords(result);
}
public String decrypt(String input, String key) {
// This function receive bits and decrypt
input = Tools.wordsToBits(input);
input = Tools.fillBy0(input, key.length());
String blocs[] = Tools.deviseToBloc(input, key.length());
for(int i=0; i < blocs.length; i++) {
blocs[i] = Tools.d(blocs[i], key);
}
String result = "";
for(String str : blocs)
result += str;
return Tools.bitsToWords(result);
}
}