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:
+143
-75
@@ -5,7 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package cryptography;
|
package cryptography;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -59,9 +58,8 @@ public class Des {
|
|||||||
24, 25, 26, 27, 28, 29,
|
24, 25, 26, 27, 28, 29,
|
||||||
28, 29, 30, 31, 32, 1,
|
28, 29, 30, 31, 32, 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
private final int[] masterKey = new int[64];
|
|
||||||
public ArrayList<int[]> table_cles;
|
public ArrayList<int[]> table_cles;
|
||||||
|
private int[] masterKey = new int[64];
|
||||||
|
|
||||||
public Des() {
|
public Des() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -71,65 +69,83 @@ public class Des {
|
|||||||
this.table_cles = new ArrayList<>();
|
this.table_cles = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crée un nouveau Des avec une masterKey définie (Test/Debug)
|
||||||
|
*
|
||||||
|
* @param masterKey Liste d'entiers qui définie la master key (Doit avoir une taille de 64)
|
||||||
|
*/
|
||||||
|
public Des(int[] masterKey) {
|
||||||
|
if (masterKey.length != 64) {
|
||||||
|
throw new IllegalArgumentException("La masterKey n'est pas composée de 64 bits");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.masterKey = masterKey;
|
||||||
|
this.table_cles = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Manipulations de bits et String */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converti une chaîne de caractère en sa liste de bits (conversion de caractères ascii en binaire)
|
||||||
|
*
|
||||||
|
* @param message Chaîne de caractère à convertir
|
||||||
|
* @return La liste de bits, resultat de la conversion du message en binaire
|
||||||
|
*/
|
||||||
public static int[] stringToBits(String message) {
|
public static int[] stringToBits(String message) {
|
||||||
char[] bitsInCharList = new BigInteger(message.getBytes())
|
if (message.length() == 0) return new int[]{};
|
||||||
.toString(2)
|
|
||||||
.toCharArray();
|
ArrayList<Integer> resultat = new ArrayList<>();
|
||||||
int[] bits = new int[bitsInCharList.length];
|
for (char c : message.toCharArray()) {
|
||||||
for (int i = 0; i < bitsInCharList.length; i++) {
|
|
||||||
bits[i] = Integer.parseInt(String.valueOf(bitsInCharList[i]));
|
// Ajoute au résultat la valeur du caractère en binaire
|
||||||
|
String binaryStringValue = Integer.toBinaryString(c);
|
||||||
|
String formatedStringValue = String.format("%08d", Integer.parseInt(binaryStringValue));
|
||||||
|
for (char bit : formatedStringValue.toCharArray()) {
|
||||||
|
int binaryIntValue = Character.getNumericValue(bit);
|
||||||
|
resultat.add(binaryIntValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return bits;
|
|
||||||
}
|
return resultat.stream().mapToInt(i -> i).toArray();
|
||||||
|
|
||||||
public static int[] generePermutation(int taille) {
|
|
||||||
int[] listePermut = new int[taille];
|
|
||||||
ArrayList<Integer> listeIndice = new ArrayList<>();
|
|
||||||
|
|
||||||
// Remplir le tableau d'indice
|
|
||||||
for (int i = 0; i < taille; i++) {
|
|
||||||
listeIndice.add(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
Random r = new Random();
|
|
||||||
for (int i = taille; i > 0; i--) {
|
|
||||||
listePermut[taille - i] = listeIndice.remove(r.nextInt(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return listePermut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converti une liste de bits en chaîne de caractères
|
||||||
|
*
|
||||||
|
* @param blocs liste de bits à convertir
|
||||||
|
* @return La chaine de caractère
|
||||||
|
*/
|
||||||
public static String bitsToString(int[] blocs) {
|
public static String bitsToString(int[] blocs) {
|
||||||
|
if (blocs.length == 0) return "";
|
||||||
|
|
||||||
StringBuilder bit = new StringBuilder();
|
// On découpe en bloc de 8bits
|
||||||
for (int b : blocs) bit.append(b);
|
int[][] blocsOfOctet = decoupage(blocs, blocs.length / 8);
|
||||||
|
|
||||||
return new String(new BigInteger(bit.toString(), 2).toByteArray());
|
StringBuilder resultat = new StringBuilder();
|
||||||
}
|
for (int[] octet : blocsOfOctet) {
|
||||||
|
// Convertis l'octet en chaine de caractère
|
||||||
|
// Ex: [0, 1, 1, 0, 0, 0, 0, 1] -> "01100001"
|
||||||
|
StringBuilder stringBuilderOctet = new StringBuilder();
|
||||||
|
for (int i : octet) stringBuilderOctet.append(i);
|
||||||
|
String stringOctet = stringBuilderOctet.toString();
|
||||||
|
|
||||||
public static void permutation(int[] tab_permutation, int[] bloc) {
|
// On convertis la chaine de caractère en entier (base 2 -> 10)
|
||||||
int[] newTab = new int[bloc.length];
|
int c = Integer.parseInt(stringOctet, 2);
|
||||||
for (int i = 0; i < bloc.length; i++) {
|
|
||||||
|
|
||||||
newTab[i] = bloc[tab_permutation[i] % tab_permutation.length];
|
// On convertis l'entier en caractère et on l'ajoute au message final résultat
|
||||||
|
resultat.append((char) c);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.arraycopy(newTab, 0, bloc, 0, newTab.length);
|
return resultat.toString();
|
||||||
}
|
|
||||||
|
|
||||||
public static void invPermutation(int[] tab_permutation, int[] bloc) {
|
|
||||||
int[] newTab = new int[bloc.length];
|
|
||||||
|
|
||||||
//// System.out.println(bloc.length);
|
|
||||||
for (int i = 0; i < bloc.length; i++) {
|
|
||||||
//// System.out.println(tab_permutation[i] % tab_permutation.length);
|
|
||||||
|
|
||||||
newTab[tab_permutation[i] % tab_permutation.length] = bloc[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
System.arraycopy(newTab, 0, bloc, 0, newTab.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Découpe un liste de bits en nbBlocs
|
||||||
|
*
|
||||||
|
* @param bloc Liste de bits
|
||||||
|
* @param nbBlocs Nombre de bloc demandé
|
||||||
|
* @return Une liste de bloc contenant le même nombre de bits
|
||||||
|
*/
|
||||||
public static int[][] decoupage(int[] bloc, int nbBlocs) {
|
public static int[][] decoupage(int[] bloc, int nbBlocs) {
|
||||||
int surplu = bloc.length % nbBlocs;
|
int surplu = bloc.length % nbBlocs;
|
||||||
int z = (bloc.length) / nbBlocs;
|
int z = (bloc.length) / nbBlocs;
|
||||||
@@ -152,6 +168,29 @@ public class Des {
|
|||||||
return newTab;
|
return newTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effectue un OU exclusif entre deux liste de bits.
|
||||||
|
* Rappel:
|
||||||
|
* <ul>
|
||||||
|
* <li>0 XOR 0 -> 0</li>
|
||||||
|
* <li>0 XOR 1 -> 1</li>
|
||||||
|
* <li>1 XOR 0 -> 1</li>
|
||||||
|
* <li>1 XOR 1 -> 0</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param tab1 Première liste de bits
|
||||||
|
* @param tab2 Seconde liste de bits
|
||||||
|
* @return Le résultat du OU exclusif entre tab1 et tab2
|
||||||
|
*/
|
||||||
|
public static int[] xor(int[] tab1, int[] tab2) {
|
||||||
|
int[] resultat = new int[tab1.length];
|
||||||
|
for (int i = 0; i < resultat.length; i++) {
|
||||||
|
resultat[i] = (tab1[i] + tab2[i]) % 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultat;
|
||||||
|
}
|
||||||
|
|
||||||
public static int[] recollageBloc(int[][] blocs) {
|
public static int[] recollageBloc(int[][] blocs) {
|
||||||
|
|
||||||
int[] bloc = new int[blocs.length * blocs[0].length];
|
int[] bloc = new int[blocs.length * blocs[0].length];
|
||||||
@@ -177,38 +216,48 @@ public class Des {
|
|||||||
return newBloc;
|
return newBloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] xor(int[] tab1, int[] tab2) {
|
/* Permutations */
|
||||||
int[] resultat = new int[tab1.length];
|
public static void permutation(int[] tab_permutation, int[] bloc) {
|
||||||
// System.out.println(resultat.length);
|
int[] newTab = new int[bloc.length];
|
||||||
|
for (int i = 0; i < bloc.length; i++) {
|
||||||
|
|
||||||
for (int i = 0; i < resultat.length; i++) {
|
newTab[i] = bloc[tab_permutation[i] % tab_permutation.length];
|
||||||
resultat[i] = (tab1[i] + tab2[i]) % 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultat;
|
System.arraycopy(newTab, 0, bloc, 0, newTab.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void genereCle(int n) {
|
public static void invPermutation(int[] tab_permutation, int[] bloc) {
|
||||||
int[] newCle = new int[56];
|
int[] newTab = new int[bloc.length];
|
||||||
int[] lastCle = new int[48];
|
|
||||||
int[] permInit = generePermutation(newCle.length);
|
|
||||||
permutation(permInit, newCle);
|
|
||||||
|
|
||||||
System.arraycopy(this.masterKey, 0, newCle, 0, newCle.length);
|
//// System.out.println(bloc.length);
|
||||||
|
for (int i = 0; i < bloc.length; i++) {
|
||||||
|
//// System.out.println(tab_permutation[i] % tab_permutation.length);
|
||||||
|
|
||||||
int[][] cleDecoupe = decoupage(newCle, 2);
|
newTab[tab_permutation[i] % tab_permutation.length] = bloc[i];
|
||||||
assert cleDecoupe != null;
|
}
|
||||||
cleDecoupe[0] = decaleGauche(cleDecoupe[0], TAB_DECALAGE[n]);
|
|
||||||
cleDecoupe[1] = decaleGauche(cleDecoupe[1], TAB_DECALAGE[n]);
|
|
||||||
|
|
||||||
newCle = recollageBloc(cleDecoupe);
|
System.arraycopy(newTab, 0, bloc, 0, newTab.length);
|
||||||
|
|
||||||
int[] lastPerm = generePermutation(lastCle.length);
|
|
||||||
System.arraycopy(newCle, 0, lastCle, 0, lastCle.length);
|
|
||||||
permutation(lastPerm, lastCle);
|
|
||||||
this.table_cles.add(lastCle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] generePermutation(int taille) {
|
||||||
|
int[] listePermut = new int[taille];
|
||||||
|
ArrayList<Integer> listeIndice = new ArrayList<>();
|
||||||
|
|
||||||
|
// Remplir le tableau d'indice
|
||||||
|
for (int i = 0; i < taille; i++) {
|
||||||
|
listeIndice.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
Random r = new Random();
|
||||||
|
for (int i = taille; i > 0; i--) {
|
||||||
|
listePermut[taille - i] = listeIndice.remove(r.nextInt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return listePermut;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fonctions */
|
||||||
public static int[] fonction_S(int[] tab) {
|
public static int[] fonction_S(int[] tab) {
|
||||||
|
|
||||||
String l = "" + tab[0] + tab[5];
|
String l = "" + tab[0] + tab[5];
|
||||||
@@ -228,6 +277,27 @@ public class Des {
|
|||||||
return resultat;
|
return resultat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Genere */
|
||||||
|
public void genereCle(int n) {
|
||||||
|
int[] newCle = new int[56];
|
||||||
|
int[] lastCle = new int[48];
|
||||||
|
int[] permInit = generePermutation(newCle.length);
|
||||||
|
permutation(permInit, newCle);
|
||||||
|
|
||||||
|
System.arraycopy(this.masterKey, 0, newCle, 0, newCle.length);
|
||||||
|
|
||||||
|
int[][] cleDecoupe = decoupage(newCle, 2);
|
||||||
|
cleDecoupe[0] = decaleGauche(cleDecoupe[0], TAB_DECALAGE[n]);
|
||||||
|
cleDecoupe[1] = decaleGauche(cleDecoupe[1], TAB_DECALAGE[n]);
|
||||||
|
|
||||||
|
newCle = recollageBloc(cleDecoupe);
|
||||||
|
|
||||||
|
int[] lastPerm = generePermutation(lastCle.length);
|
||||||
|
System.arraycopy(newCle, 0, lastCle, 0, lastCle.length);
|
||||||
|
permutation(lastPerm, lastCle);
|
||||||
|
this.table_cles.add(lastCle);
|
||||||
|
}
|
||||||
|
|
||||||
public int[] fonction_F(int indice_cle, int[] Dn) {
|
public int[] fonction_F(int indice_cle, int[] Dn) {
|
||||||
//xor entre this.E et la cle trouvé à cette ronde
|
//xor entre this.E et la cle trouvé à cette ronde
|
||||||
int[] cle = this.table_cles.get(indice_cle);
|
int[] cle = this.table_cles.get(indice_cle);
|
||||||
@@ -248,6 +318,7 @@ public class Des {
|
|||||||
return recollageBloc(bloc);
|
return recollageBloc(bloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Methodes générales */
|
||||||
public int[] crypte(String message_clair) {
|
public int[] crypte(String message_clair) {
|
||||||
|
|
||||||
int[] msg_bit = stringToBits(message_clair);
|
int[] msg_bit = stringToBits(message_clair);
|
||||||
@@ -293,9 +364,7 @@ public class Des {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String decrypte(int[] messageCode) {
|
public String decrypte(int[] messageCode) {
|
||||||
|
int[][] decoupe = decoupage(messageCode, messageCode.length / TAILLE_BLOC);
|
||||||
|
|
||||||
int[][] decoupe = decoupage(messageCode, (int) (messageCode.length / TAILLE_BLOC));
|
|
||||||
|
|
||||||
for (int i = 0; i < decoupe.length; i++) {
|
for (int i = 0; i < decoupe.length; i++) {
|
||||||
permutation(PERM_INITIALE, decoupe[i]);
|
permutation(PERM_INITIALE, decoupe[i]);
|
||||||
@@ -313,7 +382,6 @@ public class Des {
|
|||||||
}
|
}
|
||||||
decoupe[i] = recollageBloc(bloc32);
|
decoupe[i] = recollageBloc(bloc32);
|
||||||
invPermutation(PERM_INITIALE, decoupe[i]);
|
invPermutation(PERM_INITIALE, decoupe[i]);
|
||||||
|
|
||||||
}
|
}
|
||||||
int[] message_decrypte = recollageBloc(decoupe);
|
int[] message_decrypte = recollageBloc(decoupe);
|
||||||
return bitsToString(message_decrypte);
|
return bitsToString(message_decrypte);
|
||||||
|
|||||||
+294
-22
@@ -2,6 +2,7 @@ package cryptography;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -11,75 +12,346 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
class DesTest {
|
class DesTest {
|
||||||
|
|
||||||
@BeforeEach
|
// @BeforeEach
|
||||||
void setUp() {
|
// void setUp() {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@AfterEach
|
// @AfterEach
|
||||||
void tearDown() {
|
// void tearDown() {
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void stringToBits() {
|
void stringToBits() {
|
||||||
HashMap<String, int[]> attendu = new HashMap<>() {{
|
HashMap<String, int[]> TESTS = 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});
|
// 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()) {
|
for (Map.Entry<String, int[]> test : TESTS.entrySet()) {
|
||||||
assertArrayEquals(Des.stringToBits(test.getKey()), test.getValue());
|
assertArrayEquals(test.getValue(), Des.stringToBits(test.getKey()));
|
||||||
|
System.out.println(test.getKey() + " -> Ok");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void generePermutation() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void bitsToString() {
|
void bitsToString() {
|
||||||
}
|
HashMap<int[], String> TESTS = new HashMap<>() {{
|
||||||
|
// Empty string
|
||||||
|
put(new int[]{}, "");
|
||||||
|
|
||||||
@Test
|
// abc, maj
|
||||||
void permutation() {
|
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
|
put(new int[]{
|
||||||
void invPermutation() {
|
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
|
@Test
|
||||||
void decoupage() {
|
void decoupage() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void generePermutation() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void permutation() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void invPermutation() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void recollageBloc() {
|
void recollageBloc() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void decaleGauche() {
|
void decaleGauche() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void xor() {
|
void xor() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void genereCle() {
|
void genereCle() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fonction_S() {
|
void fonction_S() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void fonction_F() {
|
void fonction_F() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void crypte() {
|
void crypte() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void decrypte() {
|
void decrypte() {
|
||||||
|
assertTrue(false); // TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user