mirror of
https://github.com/LucasVbr/data-encryption-standard.git
synced 2026-05-13 17:12:10 +00:00
Add comments
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* cryptography.Des.java, 13/09/2022
|
* Des.java, 13/09/2022
|
||||||
* INU Champollion 2022-2023, L3 INFO
|
* INU Champollion 2022-2023, L3 INFO
|
||||||
* pas de copyright, aucun droits
|
* pas de copyright, aucun droits
|
||||||
*/
|
*/
|
||||||
@@ -11,7 +11,9 @@ import java.util.Random;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lucàs VABRE et les 2 autres
|
* @author Gaël BURGUÈS
|
||||||
|
* @author Laurian DUFRECHOU
|
||||||
|
* @author Lucàs VABRE
|
||||||
*/
|
*/
|
||||||
public class Des {
|
public class Des {
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,21 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class testDes {
|
public class testDes {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static void testStringToBits() {
|
public static void testStringToBits() {
|
||||||
System.out.println(Arrays.toString(Des.stringToBits("Bonjour")));
|
System.out.println(Arrays.toString(Des.stringToBits("Bonjour")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static void testBitsToString() {
|
public static void testBitsToString() {
|
||||||
System.out.println(Des.bitsToString(Des.stringToBits("Bonjour")));
|
System.out.println(Des.bitsToString(Des.stringToBits("Bonjour")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testGenerePermutation(){
|
public static void testGenerePermutation() {
|
||||||
System.out.println(Arrays.toString(Des.generePermutation(64)));
|
System.out.println(Arrays.toString(Des.generePermutation(64)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +28,7 @@ public class testDes {
|
|||||||
int[] permutation = Des.generePermutation(64);
|
int[] permutation = Des.generePermutation(64);
|
||||||
int[] bloc = new int[permutation.length];
|
int[] bloc = new int[permutation.length];
|
||||||
|
|
||||||
for(int i = 0; i < bloc.length; i++){
|
for (int i = 0; i < bloc.length; i++) {
|
||||||
bloc[i] = i;
|
bloc[i] = i;
|
||||||
}
|
}
|
||||||
System.out.println(Arrays.toString(bloc));
|
System.out.println(Arrays.toString(bloc));
|
||||||
@@ -34,7 +40,7 @@ public class testDes {
|
|||||||
int[] permutation = Des.generePermutation(64);
|
int[] permutation = Des.generePermutation(64);
|
||||||
int[] bloc = new int[permutation.length];
|
int[] bloc = new int[permutation.length];
|
||||||
int[] bloc2 = new int[permutation.length];
|
int[] bloc2 = new int[permutation.length];
|
||||||
for(int i = 0; i < bloc.length; i++) {
|
for (int i = 0; i < bloc.length; i++) {
|
||||||
bloc[i] = i;
|
bloc[i] = i;
|
||||||
bloc2[i] = i;
|
bloc2[i] = i;
|
||||||
}
|
}
|
||||||
@@ -69,6 +75,9 @@ public class testDes {
|
|||||||
System.out.println(Arrays.toString(Des.decaleGauche(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, 4)));
|
System.out.println(Arrays.toString(Des.decaleGauche(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, 4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
public static void testXor() {
|
public static void testXor() {
|
||||||
System.out.println(Arrays.toString(Des.xor(new int[]{1, 1, 0, 0}, new int[]{1, 0, 1, 0})));
|
System.out.println(Arrays.toString(Des.xor(new int[]{1, 1, 0, 0}, new int[]{1, 0, 1, 0})));
|
||||||
}
|
}
|
||||||
@@ -82,6 +91,7 @@ public class testDes {
|
|||||||
public static void testFonctionS() {
|
public static void testFonctionS() {
|
||||||
System.out.println(Arrays.toString(Des.fonction_S(new int[]{1, 1, 1, 1, 1, 1})));
|
System.out.println(Arrays.toString(Des.fonction_S(new int[]{1, 1, 1, 1, 1, 1})));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testFonctionF() {
|
public static void testFonctionF() {
|
||||||
Des des = new Des();
|
Des des = new Des();
|
||||||
|
|
||||||
@@ -90,16 +100,16 @@ public class testDes {
|
|||||||
|
|
||||||
private static void testCrypte() {
|
private static void testCrypte() {
|
||||||
Des des = new Des();
|
Des des = new Des();
|
||||||
int [] msg = des.crypte("Bonjour");
|
int[] msg = des.crypte("Bonjour");
|
||||||
System.out.println("en bit : " +Arrays.toString(msg));
|
System.out.println("en bit : " + Arrays.toString(msg));
|
||||||
System.out.println("en string :"+Des.bitsToString(msg));
|
System.out.println("en string :" + Des.bitsToString(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testDecrypte() {
|
private static void testDecrypte() {
|
||||||
Des des = new Des();
|
Des des = new Des();
|
||||||
int[] msg = des.crypte("Bonjour");
|
int[] msg = des.crypte("Bonjour");
|
||||||
System.out.println("Message crypté : " + Des.bitsToString(msg));
|
System.out.println("Message crypté : " + Des.bitsToString(msg));
|
||||||
System.out.println(des.decrypte(msg));;
|
System.out.println(des.decrypte(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -116,7 +126,7 @@ public class testDes {
|
|||||||
// testFonctionS();// corrigé
|
// testFonctionS();// corrigé
|
||||||
// testFonctionF(); // il a l'air bon
|
// testFonctionF(); // il a l'air bon
|
||||||
// testCrypte(); //Il a l'air bon (si on regarde decoupe[0]et [1] à chaque itérations on voit que c'est cohérent)
|
// testCrypte(); //Il a l'air bon (si on regarde decoupe[0]et [1] à chaque itérations on voit que c'est cohérent)
|
||||||
testDecrypte(); // Un truc est normal c'est que jusqu'à la deniere itération sur les 16 ,
|
testDecrypte(); // Un truc est normal c'est que jusqu'à la deniere itération sur les 16 ,
|
||||||
// les clés sont randoms jusqu'à la dernière itération ou elle est tout le temps la meme
|
// les clés sont randoms jusqu'à la dernière itération ou elle est tout le temps la meme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* DesTest.java, 26/10/2022
|
||||||
|
* INU Champollion 2022-2023, L3 INFO
|
||||||
|
* pas de copyright, aucun droits
|
||||||
|
*/
|
||||||
package cryptography;
|
package cryptography;
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gaël BURGUÈS
|
||||||
|
* @author Laurian DUFRECHOU
|
||||||
|
* @author Lucàs VABRE
|
||||||
|
*/
|
||||||
class DesTest {
|
class DesTest {
|
||||||
|
|
||||||
// @BeforeEach
|
|
||||||
// void setUp() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @AfterEach
|
|
||||||
// void tearDown() {
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("stringToBits")
|
@DisplayName("stringToBits")
|
||||||
void stringToBits() {
|
void stringToBits() {
|
||||||
@@ -153,7 +155,7 @@ class DesTest {
|
|||||||
|
|
||||||
for (Map.Entry<String, int[]> test : TESTS.entrySet()) {
|
for (Map.Entry<String, int[]> test : TESTS.entrySet()) {
|
||||||
assertArrayEquals(test.getValue(), Des.stringToBits(test.getKey()));
|
assertArrayEquals(test.getValue(), Des.stringToBits(test.getKey()));
|
||||||
System.out.println(test.getKey() + " -> Ok");
|
System.out.printf("\"%s\" -> OK\n", test.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +293,29 @@ class DesTest {
|
|||||||
|
|
||||||
for (Map.Entry<int[], String> test : TESTS.entrySet()) {
|
for (Map.Entry<int[], String> test : TESTS.entrySet()) {
|
||||||
assertEquals(test.getValue(), Des.bitsToString(test.getKey()));
|
assertEquals(test.getValue(), Des.bitsToString(test.getKey()));
|
||||||
System.out.println(test.getValue() + " -> Ok");
|
System.out.printf("\"%s\" -> OK\n", test.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("xor")
|
||||||
|
void xor() {
|
||||||
|
|
||||||
|
final int[][][] TESTS = {
|
||||||
|
{
|
||||||
|
{0, 1, 0, 1}, // Table 1
|
||||||
|
{0, 0, 1, 1}, // Table 2
|
||||||
|
{0, 1, 1, 0}, // Result expected
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int[][] test : TESTS) {
|
||||||
|
assertArrayEquals(Des.xor(test[0], test[1]), test[2]);
|
||||||
|
System.out.printf(
|
||||||
|
"%s XOR %s -> OK\n",
|
||||||
|
Arrays.toString(test[0]),
|
||||||
|
Arrays.toString(test[1])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,20 +384,4 @@ class DesTest {
|
|||||||
void decrypte() {
|
void decrypte() {
|
||||||
fail(); // TODO
|
fail(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("xor")
|
|
||||||
void xor() {
|
|
||||||
final int[][][] TESTS = {
|
|
||||||
{
|
|
||||||
{0, 1, 0, 1}, // Table 1
|
|
||||||
{0, 0, 1, 1}, // Table 2
|
|
||||||
{0, 1, 1, 0}, // Result expected
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int[][] test : TESTS) {
|
|
||||||
assertArrayEquals(Des.xor(test[0], test[1]), test[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user