mirror of
https://github.com/LucasVbr/data-encryption-standard.git
synced 2026-05-13 17:12:10 +00:00
Ajouts de tests unitaires bitToString et stringToBit
- Réécriture de stringToBit - Réécriture de bitToString - Ajout de commentaires - Ajouts de tests unitaires pour stringToBits - Ajouts de tests unitaires pour stringToBits
This commit is contained in:
+294
-22
@@ -2,6 +2,7 @@ package cryptography;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -11,75 +12,346 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DesTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
}
|
||||
// @BeforeEach
|
||||
// void setUp() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @AfterEach
|
||||
// void tearDown() {
|
||||
// }
|
||||
|
||||
@Test
|
||||
void stringToBits() {
|
||||
HashMap<String, int[]> attendu = new HashMap<>() {{
|
||||
put("Bonjour", new int[]{0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0});
|
||||
HashMap<String, int[]> TESTS = new HashMap<>() {{
|
||||
// Empty string
|
||||
put("", new int[]{});
|
||||
|
||||
// abc, maj
|
||||
put("abcdefghijklmnopqrstuvwxyz", new int[]{
|
||||
0, 1, 1, 0, 0, 0, 0, 1, // a
|
||||
0, 1, 1, 0, 0, 0, 1, 0, // b
|
||||
0, 1, 1, 0, 0, 0, 1, 1, // c
|
||||
0, 1, 1, 0, 0, 1, 0, 0, // d
|
||||
0, 1, 1, 0, 0, 1, 0, 1, // e
|
||||
0, 1, 1, 0, 0, 1, 1, 0, // f
|
||||
0, 1, 1, 0, 0, 1, 1, 1, // g
|
||||
0, 1, 1, 0, 1, 0, 0, 0, // h
|
||||
0, 1, 1, 0, 1, 0, 0, 1, // i
|
||||
0, 1, 1, 0, 1, 0, 1, 0, // j
|
||||
0, 1, 1, 0, 1, 0, 1, 1, // k
|
||||
0, 1, 1, 0, 1, 1, 0, 0, // l
|
||||
0, 1, 1, 0, 1, 1, 0, 1, // m
|
||||
0, 1, 1, 0, 1, 1, 1, 0, // n
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 1, 0, 0, 0, 0, // p
|
||||
0, 1, 1, 1, 0, 0, 0, 1, // q
|
||||
0, 1, 1, 1, 0, 0, 1, 0, // r
|
||||
0, 1, 1, 1, 0, 0, 1, 1, // s
|
||||
0, 1, 1, 1, 0, 1, 0, 0, // t
|
||||
0, 1, 1, 1, 0, 1, 0, 1, // u
|
||||
0, 1, 1, 1, 0, 1, 1, 0, // v
|
||||
0, 1, 1, 1, 0, 1, 1, 1, // w
|
||||
0, 1, 1, 1, 1, 0, 0, 0, // x
|
||||
0, 1, 1, 1, 1, 0, 0, 1, // y
|
||||
0, 1, 1, 1, 1, 0, 1, 0, // z
|
||||
});
|
||||
|
||||
put("ABCDEFGHIJKLMNOPQRSTUVWXYZ", new int[]{
|
||||
0, 1, 0, 0, 0, 0, 0, 1, // A
|
||||
0, 1, 0, 0, 0, 0, 1, 0, // B
|
||||
0, 1, 0, 0, 0, 0, 1, 1, // C
|
||||
0, 1, 0, 0, 0, 1, 0, 0, // D
|
||||
0, 1, 0, 0, 0, 1, 0, 1, // E
|
||||
0, 1, 0, 0, 0, 1, 1, 0, // F
|
||||
0, 1, 0, 0, 0, 1, 1, 1, // G
|
||||
0, 1, 0, 0, 1, 0, 0, 0, // H
|
||||
0, 1, 0, 0, 1, 0, 0, 1, // I
|
||||
0, 1, 0, 0, 1, 0, 1, 0, // J
|
||||
0, 1, 0, 0, 1, 0, 1, 1, // K
|
||||
0, 1, 0, 0, 1, 1, 0, 0, // L
|
||||
0, 1, 0, 0, 1, 1, 0, 1, // M
|
||||
0, 1, 0, 0, 1, 1, 1, 0, // N
|
||||
0, 1, 0, 0, 1, 1, 1, 1, // O
|
||||
0, 1, 0, 1, 0, 0, 0, 0, // P
|
||||
0, 1, 0, 1, 0, 0, 0, 1, // Q
|
||||
0, 1, 0, 1, 0, 0, 1, 0, // R
|
||||
0, 1, 0, 1, 0, 0, 1, 1, // S
|
||||
0, 1, 0, 1, 0, 1, 0, 0, // T
|
||||
0, 1, 0, 1, 0, 1, 0, 1, // U
|
||||
0, 1, 0, 1, 0, 1, 1, 0, // V
|
||||
0, 1, 0, 1, 0, 1, 1, 1, // W
|
||||
0, 1, 0, 1, 1, 0, 0, 0, // X
|
||||
0, 1, 0, 1, 1, 0, 0, 1, // Y
|
||||
0, 1, 0, 1, 1, 0, 1, 0, // Z
|
||||
});
|
||||
|
||||
// Numbers
|
||||
put("0123456789", new int[]{
|
||||
0, 0, 1, 1, 0, 0, 0, 0, // 0
|
||||
0, 0, 1, 1, 0, 0, 0, 1, // 1
|
||||
0, 0, 1, 1, 0, 0, 1, 0, // 2
|
||||
0, 0, 1, 1, 0, 0, 1, 1, // 3
|
||||
0, 0, 1, 1, 0, 1, 0, 0, // 4
|
||||
0, 0, 1, 1, 0, 1, 0, 1, // 5
|
||||
0, 0, 1, 1, 0, 1, 1, 0, // 6
|
||||
0, 0, 1, 1, 0, 1, 1, 1, // 7
|
||||
0, 0, 1, 1, 1, 0, 0, 0, // 8
|
||||
0, 0, 1, 1, 1, 0, 0, 1, // 9
|
||||
});
|
||||
|
||||
// Special chars
|
||||
put("+-/*%=", new int[]{
|
||||
0, 0, 1, 0, 1, 0, 1, 1, // +
|
||||
0, 0, 1, 0, 1, 1, 0, 1, // -
|
||||
0, 0, 1, 0, 1, 1, 1, 1, // /
|
||||
0, 0, 1, 0, 1, 0, 1, 0, // *
|
||||
0, 0, 1, 0, 0, 1, 0, 1, // %
|
||||
0, 0, 1, 1, 1, 1, 0, 1, // =
|
||||
});
|
||||
|
||||
put("?!.,;:_ ", new int[]{
|
||||
0, 0, 1, 1, 1, 1, 1, 1, // ?
|
||||
0, 0, 1, 0, 0, 0, 0, 1, // !
|
||||
0, 0, 1, 0, 1, 1, 1, 0, // .
|
||||
0, 0, 1, 0, 1, 1, 0, 0, // ,
|
||||
0, 0, 1, 1, 1, 0, 1, 1, // ;
|
||||
0, 0, 1, 1, 1, 0, 1, 0, // :
|
||||
0, 1, 0, 1, 1, 1, 1, 1, // _
|
||||
0, 0, 1, 0, 0, 0, 0, 0, // space
|
||||
});
|
||||
|
||||
put("(){}[]", new int[]{
|
||||
0, 0, 1, 0, 1, 0, 0, 0, // (
|
||||
0, 0, 1, 0, 1, 0, 0, 1, // )
|
||||
0, 1, 1, 1, 1, 0, 1, 1, // {
|
||||
0, 1, 1, 1, 1, 1, 0, 1, // }
|
||||
0, 1, 0, 1, 1, 0, 1, 1, // [
|
||||
0, 1, 0, 1, 1, 1, 0, 1, // ]
|
||||
});
|
||||
|
||||
put("&@#^\"'`", new int[]{
|
||||
0, 0, 1, 0, 0, 1, 1, 0, // &
|
||||
0, 1, 0, 0, 0, 0, 0, 0, // @
|
||||
0, 0, 1, 0, 0, 0, 1, 1, // #
|
||||
0, 1, 0, 1, 1, 1, 1, 0, // ^
|
||||
0, 0, 1, 0, 0, 0, 1, 0, // "
|
||||
0, 0, 1, 0, 0, 1, 1, 1, // '
|
||||
0, 1, 1, 0, 0, 0, 0, 0, // `
|
||||
});
|
||||
|
||||
// Custom test
|
||||
put("Bonjour", new int[]{
|
||||
0, 1, 0, 0, 0, 0, 1, 0, // B
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 0, 1, 1, 1, 0, // n
|
||||
0, 1, 1, 0, 1, 0, 1, 0, // j
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 1, 0, 1, 0, 1, // u
|
||||
0, 1, 1, 1, 0, 0, 1, 0, // r
|
||||
});
|
||||
}};
|
||||
|
||||
for (Map.Entry<String, int[]> test : attendu.entrySet()) {
|
||||
assertArrayEquals(Des.stringToBits(test.getKey()), test.getValue());
|
||||
for (Map.Entry<String, int[]> test : TESTS.entrySet()) {
|
||||
assertArrayEquals(test.getValue(), Des.stringToBits(test.getKey()));
|
||||
System.out.println(test.getKey() + " -> Ok");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void generePermutation() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bitsToString() {
|
||||
}
|
||||
HashMap<int[], String> TESTS = new HashMap<>() {{
|
||||
// Empty string
|
||||
put(new int[]{}, "");
|
||||
|
||||
@Test
|
||||
void permutation() {
|
||||
}
|
||||
// abc, maj
|
||||
put(new int[]{
|
||||
0, 1, 1, 0, 0, 0, 0, 1, // a
|
||||
0, 1, 1, 0, 0, 0, 1, 0, // b
|
||||
0, 1, 1, 0, 0, 0, 1, 1, // c
|
||||
0, 1, 1, 0, 0, 1, 0, 0, // d
|
||||
0, 1, 1, 0, 0, 1, 0, 1, // e
|
||||
0, 1, 1, 0, 0, 1, 1, 0, // f
|
||||
0, 1, 1, 0, 0, 1, 1, 1, // g
|
||||
0, 1, 1, 0, 1, 0, 0, 0, // h
|
||||
0, 1, 1, 0, 1, 0, 0, 1, // i
|
||||
0, 1, 1, 0, 1, 0, 1, 0, // j
|
||||
0, 1, 1, 0, 1, 0, 1, 1, // k
|
||||
0, 1, 1, 0, 1, 1, 0, 0, // l
|
||||
0, 1, 1, 0, 1, 1, 0, 1, // m
|
||||
0, 1, 1, 0, 1, 1, 1, 0, // n
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 1, 0, 0, 0, 0, // p
|
||||
0, 1, 1, 1, 0, 0, 0, 1, // q
|
||||
0, 1, 1, 1, 0, 0, 1, 0, // r
|
||||
0, 1, 1, 1, 0, 0, 1, 1, // s
|
||||
0, 1, 1, 1, 0, 1, 0, 0, // t
|
||||
0, 1, 1, 1, 0, 1, 0, 1, // u
|
||||
0, 1, 1, 1, 0, 1, 1, 0, // v
|
||||
0, 1, 1, 1, 0, 1, 1, 1, // w
|
||||
0, 1, 1, 1, 1, 0, 0, 0, // x
|
||||
0, 1, 1, 1, 1, 0, 0, 1, // y
|
||||
0, 1, 1, 1, 1, 0, 1, 0, // z
|
||||
}, "abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
@Test
|
||||
void invPermutation() {
|
||||
put(new int[]{
|
||||
0, 1, 0, 0, 0, 0, 0, 1, // A
|
||||
0, 1, 0, 0, 0, 0, 1, 0, // B
|
||||
0, 1, 0, 0, 0, 0, 1, 1, // C
|
||||
0, 1, 0, 0, 0, 1, 0, 0, // D
|
||||
0, 1, 0, 0, 0, 1, 0, 1, // E
|
||||
0, 1, 0, 0, 0, 1, 1, 0, // F
|
||||
0, 1, 0, 0, 0, 1, 1, 1, // G
|
||||
0, 1, 0, 0, 1, 0, 0, 0, // H
|
||||
0, 1, 0, 0, 1, 0, 0, 1, // I
|
||||
0, 1, 0, 0, 1, 0, 1, 0, // J
|
||||
0, 1, 0, 0, 1, 0, 1, 1, // K
|
||||
0, 1, 0, 0, 1, 1, 0, 0, // L
|
||||
0, 1, 0, 0, 1, 1, 0, 1, // M
|
||||
0, 1, 0, 0, 1, 1, 1, 0, // N
|
||||
0, 1, 0, 0, 1, 1, 1, 1, // O
|
||||
0, 1, 0, 1, 0, 0, 0, 0, // P
|
||||
0, 1, 0, 1, 0, 0, 0, 1, // Q
|
||||
0, 1, 0, 1, 0, 0, 1, 0, // R
|
||||
0, 1, 0, 1, 0, 0, 1, 1, // S
|
||||
0, 1, 0, 1, 0, 1, 0, 0, // T
|
||||
0, 1, 0, 1, 0, 1, 0, 1, // U
|
||||
0, 1, 0, 1, 0, 1, 1, 0, // V
|
||||
0, 1, 0, 1, 0, 1, 1, 1, // W
|
||||
0, 1, 0, 1, 1, 0, 0, 0, // X
|
||||
0, 1, 0, 1, 1, 0, 0, 1, // Y
|
||||
0, 1, 0, 1, 1, 0, 1, 0, // Z
|
||||
}, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
|
||||
// Numbers
|
||||
put(new int[]{
|
||||
0, 0, 1, 1, 0, 0, 0, 0, // 0
|
||||
0, 0, 1, 1, 0, 0, 0, 1, // 1
|
||||
0, 0, 1, 1, 0, 0, 1, 0, // 2
|
||||
0, 0, 1, 1, 0, 0, 1, 1, // 3
|
||||
0, 0, 1, 1, 0, 1, 0, 0, // 4
|
||||
0, 0, 1, 1, 0, 1, 0, 1, // 5
|
||||
0, 0, 1, 1, 0, 1, 1, 0, // 6
|
||||
0, 0, 1, 1, 0, 1, 1, 1, // 7
|
||||
0, 0, 1, 1, 1, 0, 0, 0, // 8
|
||||
0, 0, 1, 1, 1, 0, 0, 1, // 9
|
||||
}, "0123456789");
|
||||
|
||||
// Special chars
|
||||
put(new int[]{
|
||||
0, 0, 1, 0, 1, 0, 1, 1, // +
|
||||
0, 0, 1, 0, 1, 1, 0, 1, // -
|
||||
0, 0, 1, 0, 1, 1, 1, 1, // /
|
||||
0, 0, 1, 0, 1, 0, 1, 0, // *
|
||||
0, 0, 1, 0, 0, 1, 0, 1, // %
|
||||
0, 0, 1, 1, 1, 1, 0, 1, // =
|
||||
}, "+-/*%=");
|
||||
|
||||
put(new int[]{
|
||||
0, 0, 1, 1, 1, 1, 1, 1, // ?
|
||||
0, 0, 1, 0, 0, 0, 0, 1, // !
|
||||
0, 0, 1, 0, 1, 1, 1, 0, // .
|
||||
0, 0, 1, 0, 1, 1, 0, 0, // ,
|
||||
0, 0, 1, 1, 1, 0, 1, 1, // ;
|
||||
0, 0, 1, 1, 1, 0, 1, 0, // :
|
||||
0, 1, 0, 1, 1, 1, 1, 1, // _
|
||||
0, 0, 1, 0, 0, 0, 0, 0, // space
|
||||
}, "?!.,;:_ ");
|
||||
|
||||
put(new int[]{
|
||||
0, 0, 1, 0, 1, 0, 0, 0, // (
|
||||
0, 0, 1, 0, 1, 0, 0, 1, // )
|
||||
0, 1, 1, 1, 1, 0, 1, 1, // {
|
||||
0, 1, 1, 1, 1, 1, 0, 1, // }
|
||||
0, 1, 0, 1, 1, 0, 1, 1, // [
|
||||
0, 1, 0, 1, 1, 1, 0, 1, // ]
|
||||
}, "(){}[]");
|
||||
|
||||
put(new int[]{
|
||||
0, 0, 1, 0, 0, 1, 1, 0, // &
|
||||
0, 1, 0, 0, 0, 0, 0, 0, // @
|
||||
0, 0, 1, 0, 0, 0, 1, 1, // #
|
||||
0, 1, 0, 1, 1, 1, 1, 0, // ^
|
||||
0, 0, 1, 0, 0, 0, 1, 0, // "
|
||||
0, 0, 1, 0, 0, 1, 1, 1, // '
|
||||
0, 1, 1, 0, 0, 0, 0, 0, // `
|
||||
}, "&@#^\"'`");
|
||||
|
||||
// Custom test
|
||||
put(new int[]{
|
||||
0, 1, 0, 0, 0, 0, 1, 0, // B
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 0, 1, 1, 1, 0, // n
|
||||
0, 1, 1, 0, 1, 0, 1, 0, // j
|
||||
0, 1, 1, 0, 1, 1, 1, 1, // o
|
||||
0, 1, 1, 1, 0, 1, 0, 1, // u
|
||||
0, 1, 1, 1, 0, 0, 1, 0, // r
|
||||
}, "Bonjour");
|
||||
}};
|
||||
|
||||
for (Map.Entry<int[], String> test : TESTS.entrySet()) {
|
||||
assertEquals(test.getValue(), Des.bitsToString(test.getKey()));
|
||||
System.out.println(test.getValue() + " -> Ok");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void decoupage() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void generePermutation() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void permutation() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void invPermutation() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void recollageBloc() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void decaleGauche() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void xor() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void genereCle() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void fonction_S() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void fonction_F() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void crypte() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
void decrypte() {
|
||||
assertTrue(false); // TODO
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user