mirror of
https://github.com/LucasVbr/data-encryption-standard.git
synced 2026-05-13 17:12:10 +00:00
Fin des tests unitaires
This commit is contained in:
@@ -437,25 +437,24 @@ class DesTest {
|
||||
|
||||
@Test
|
||||
void fonction_S() {
|
||||
// TODO
|
||||
Des des = new Des();
|
||||
for (Des des : FIXTURE) {
|
||||
des.genereS(0);
|
||||
|
||||
des.genereS(0);
|
||||
int resultat_attendu_int = des.tableS.get(3).get(9);
|
||||
String coordonneeStr = Integer.toString(des.table_S.get(0)[3][9], 2);
|
||||
int resultat_attendu_int = Integer.parseInt(coordonneeStr);
|
||||
|
||||
int[] resultat_attendu = new int[4];
|
||||
for (int i = 0; i < resultat_attendu.length; i++, resultat_attendu_int /= 10) {
|
||||
resultat_attendu[resultat_attendu.length - i - 1] = resultat_attendu_int % 10;
|
||||
int[] resultat_attendu = new int[4];
|
||||
for (int i = 0; i < resultat_attendu.length; i++, resultat_attendu_int /= 10)
|
||||
resultat_attendu[resultat_attendu.length - i - 1] = resultat_attendu_int % 10;
|
||||
|
||||
assertArrayEquals(resultat_attendu, des.fonction_S(new int[]{1, 1, 0, 0, 1, 1}, 0));
|
||||
}
|
||||
|
||||
|
||||
assertArrayEquals(resultat_attendu, des.fonction_S(new int[] {1,1,0,0,1,1}));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void fonction_F() {
|
||||
// System.out.println(Arrays.toString(des.fonction_F(1, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17})));
|
||||
// Impossible à tester, dépend fortement du Random
|
||||
// System.out.println(Arrays.toString(des.fonction_F(1, new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17})));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,14 +1,63 @@
|
||||
package cryptography;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TripleDesTest {
|
||||
|
||||
@Test
|
||||
void crypte() {
|
||||
private final ArrayList<TripleDes> FIXTURE = new ArrayList<>();
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
int[][][] MASTER_KEYS =
|
||||
{{{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}, {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}, {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
}}, {{
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
}, {
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
}, {
|
||||
1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
|
||||
0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1,
|
||||
1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1,
|
||||
}}
|
||||
};
|
||||
|
||||
for (int[][] masterKeys : MASTER_KEYS) FIXTURE.add(new TripleDes(masterKeys));
|
||||
}
|
||||
|
||||
@Test
|
||||
void decrypte() {
|
||||
@DisplayName("crypte() & decrypte()")
|
||||
void crypteDecrypte() {
|
||||
for (TripleDes tripleDes : FIXTURE) {
|
||||
String message = "Hello World!";
|
||||
int[] messageCrypte = tripleDes.crypte(message);
|
||||
assertEquals(message, tripleDes.decrypte(messageCrypte));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user