Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathDESTest.java
More file actions
Latest commit
55 lines (44 loc) · 2.04 KB
/
Copy pathDESTest.java
File metadata and controls
55 lines (44 loc) · 2.04 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
packagecom.thealgorithms.ciphers;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importorg.junit.jupiter.api.BeforeEach;
importorg.junit.jupiter.api.Test;
// Test example taken from https://page.math.tu-berlin.de/~kant/teaching/hess/krypto-ws2006/des.htm
publicclassDESTest {
DESdes;
@BeforeEach
publicvoidsetUp() {
des = newDES("0000111000110010100100100011001011101010011011010000110101110011");
}
@Test
voidtestEncrypt() {
// given
StringplainText = "Your lips are smoother than vaseline\r\n";
// This is equal to
// c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in
// hexadecimal
StringexpectedOutput = "11000000100110011001111111011101111000110111100011010111111"
+ "011010111001001111101101000000000101111001010010110101000010011101110010001111111001"
+ "001101001101001001101011001000011100000011001000011011001110101010010111101111000111"
+ "101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
// when
StringcipherText = des.encrypt(plainText);
// then
assertEquals(expectedOutput, cipherText);
}
@Test
voidtestDecrypt() {
// given
// This is equal to
// c0999fdde378d7ed727da00bca5a84ee47f269a4d6438190d9d52f78f5358499828ac9b453e0e653 in
// hexadecimal
StringcipherText = "11000000100110011001111111011101111000110111100011010111111"
+ "011010111001001111101101000000000101111001010010110101000010011101110010001111111001"
+ "001101001101001001101011001000011100000011001000011011001110101010010111101111000111"
+ "101010011010110000100100110011000001010001010110010011011010001010011111000001110011001010011";
StringexpectedOutput = "Your lips are smoother than vaseline\r\n";
// when
StringplainText = des.decrypt(cipherText);
// then
assertEquals(expectedOutput, plainText);
}
}