2 Commits

Author SHA1 Message Date
Lucàs e3f368390c Ui Interface 2022-11-04 23:02:32 +01:00
Lucàs c0d491826e Refactor du code 2022-11-04 20:36:21 +01:00
9 changed files with 463 additions and 56 deletions
+114 -55
View File
@@ -65,6 +65,9 @@ public class Des {
public ArrayList<int[]> table_cles; public ArrayList<int[]> table_cles;
private int[] masterKey = new int[64]; private int[] masterKey = new int[64];
/**
* Crée un nouveau Des avec une masterKey aléatoire
*/
public Des() { public Des() {
Random random = new Random(); Random random = new Random();
for (int i = 0; i < masterKey.length; i++) for (int i = 0; i < masterKey.length; i++)
@@ -91,7 +94,7 @@ public class Des {
/* Manipulations de bits et String */ /* Manipulations de bits et String */
/** /**
* Converti une chaîne de caractère en sa liste de bits (conversion de caractères ascii en binaire) * Convertis 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 * @param message Chaîne de caractère à convertir
* @return La liste de bits, resultat de la conversion du message en binaire * @return La liste de bits, resultat de la conversion du message en binaire
@@ -197,6 +200,12 @@ public class Des {
return resultat; return resultat;
} }
/**
* Recole une liste de blocs en un seul bloc
*
* @param blocs La liste de bloc à recoller
* @return La liste une fois recollée
*/
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];
@@ -211,6 +220,13 @@ public class Des {
return bloc; return bloc;
} }
/**
* Décalle vers la gauche les bits d'un bloc
*
* @param blocs Le bloc initial (à modifier)
* @param nbCran Le le nombre décalage à apporter
* @return Le bloc une fois décalé
*/
public static int[] decaleGauche(int[] blocs, int nbCran) { public static int[] decaleGauche(int[] blocs, int nbCran) {
int[] newBloc = new int[blocs.length]; int[] newBloc = new int[blocs.length];
@@ -222,7 +238,13 @@ public class Des {
return newBloc; return newBloc;
} }
/* Permutations */ /**
* Déplace les bits d'un blocs par rapport à un tableau de permutation
*
* @param tableauPermutation Tableau contenant la liste des indices de manière non ordonnée
* @param bloc Le bloc a permuté
* @return Le bloc une fois permutée
*/
public static int[] permutation(int[] tableauPermutation, int[] bloc) { public static int[] permutation(int[] tableauPermutation, int[] bloc) {
if (tableauPermutation.length != bloc.length) if (tableauPermutation.length != bloc.length)
throw new IllegalArgumentException("tableauPermutation et bloc n'ont pas la même taille"); throw new IllegalArgumentException("tableauPermutation et bloc n'ont pas la même taille");
@@ -236,6 +258,13 @@ public class Des {
return resultat; return resultat;
} }
/**
* Inverse la permuation
*
* @param tableauPermutation Tableau contenant la liste des indices de manière non ordonnées
* @param bloc Le bloc qui a été permuté
* @return La valeur initiale du bloc (annule la permutation)
*/
public static int[] invPermutation(int[] tableauPermutation, int[] bloc) { public static int[] invPermutation(int[] tableauPermutation, int[] bloc) {
if (tableauPermutation.length != bloc.length) if (tableauPermutation.length != bloc.length)
throw new IllegalArgumentException("tableauPermutation et bloc n'ont pas la même taille"); throw new IllegalArgumentException("tableauPermutation et bloc n'ont pas la même taille");
@@ -248,6 +277,13 @@ public class Des {
return resultat; return resultat;
} }
/**
* Génère aléatoirement un tableau de permuation d'une taille définie
* (il n'y a pas de doublons et toutes les valeurs sont positives)
*
* @param taille Entier qui définis la taille du tableau à générer
* @return Le tableau de permutation une fois générée
*/
public static int[] generePermutation(int taille) { public static int[] generePermutation(int taille) {
int[] listePermut = new int[taille]; int[] listePermut = new int[taille];
ArrayList<Integer> listeIndice = new ArrayList<>(); ArrayList<Integer> listeIndice = new ArrayList<>();
@@ -268,12 +304,12 @@ public class Des {
/** /**
* Remove the last character if it contains only zeros * Remove the last character if it contains only zeros
* *
* @param message_decrypte * @param messageDecrypte Tableau de bit qui possède des caractères nulls
* @return int[] = array without the last 8 bits if they were all zeroes * @return int[] = array without the last 8 bits if they were all zeroes
*/ */
public static int[] removeCharNull(int[] message_decrypte) { public static int[] removeCharNull(int[] messageDecrypte) {
int[][] blocsOfOctet = decoupage(message_decrypte, message_decrypte.length / 8); int[][] blocsOfOctet = decoupage(messageDecrypte, messageDecrypte.length / 8);
ArrayList<Integer> msg_decrypt = new ArrayList<>(); ArrayList<Integer> msg_decrypt = new ArrayList<>();
@@ -291,27 +327,39 @@ public class Des {
return msg_decrypt.stream().mapToInt(i -> i).toArray(); return msg_decrypt.stream().mapToInt(i -> i).toArray();
} }
/* Fonctions */ /**
public int[] fonction_S(int[] tab, int index_S) { * Calcul de la fonction S
*
* @param tab Tableau
* @param indiceS Indice
* @return Le résultat de la fonction S
*/
public int[] fonction_S(int[] tab, int indiceS) {
String l = "" + tab[0] + tab[5]; String ligneStr = String.format("%d%d", tab[0], tab[5]);
int ligne = Integer.parseInt(l, 2); String colonneStr = String.format("%d%d%d%d", tab[1], tab[2], tab[3], tab[4]);
String c = "" + tab[1] + tab[2] + tab[3] + tab[4];
int colonne = Integer.parseInt(c, 2); int ligne = Integer.parseInt(ligneStr, 2);
int colonne = Integer.parseInt(colonneStr, 2);
// chaque blocs de 6 bits on fait le truc avec bit 1 et bit 6 et l'autre truc pour avoir ligne et colonne de S // chaque blocs de 6 bits on fait le truc avec bit 1 et bit 6 et l'autre truc pour avoir ligne et colonne de S
String coordonneeStr = Integer.toString(this.table_S.get(index_S)[ligne][colonne], 2); String coordonneeStr = Integer.toString(this.table_S.get(indiceS)[ligne][colonne], 2);
int coordonneeInt = Integer.parseInt(coordonneeStr); int coordonnee = Integer.parseInt(coordonneeStr);
int[] resultat = new int[4]; int[] resultat = new int[4];
for (int i = 0; i < resultat.length; i++, coordonneeInt /= 10) { for (int i = 0; i < resultat.length; i++, coordonnee /= 10)
resultat[resultat.length - i - 1] = coordonneeInt % 10; resultat[resultat.length - i - 1] = coordonnee % 10;
}
return resultat; return resultat;
} }
/* Genere */ /**
* Calcule la clé de la n ième ronde.
* Stocke la clée dans tab_clés
*
* @param n La ronde de la clé à calculer
* @return La clée calculée
*/
public int[][] genereCle(int n) { public int[][] genereCle(int n) {
int[] newCle = new int[56]; int[] newCle = new int[56];
int[] lastCle = new int[48]; int[] lastCle = new int[48];
@@ -339,19 +387,26 @@ public class Des {
int[][] newS = new int[4][16]; int[][] newS = new int[4][16];
Random random = new Random(); Random random = new Random();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
ArrayList<Integer> liste_valeurs = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)); ArrayList<Integer> listeValeurs = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
int index = random.nextInt(liste_valeurs.size()); int index = random.nextInt(listeValeurs.size());
newS[i][y] = liste_valeurs.get(index); newS[i][y] = listeValeurs.get(index);
liste_valeurs.remove(index); listeValeurs.remove(index);
} }
} }
this.table_S.add(n, newS); this.table_S.add(n, newS);
} }
public int[] fonction_F(int indice_cle, int[] Dn) { /**
* Calcul de la fonction F
*
* @param indiceCle Indice
* @param Dn Tableau Dn
* @return
*/
public int[] fonction_F(int indiceCle, 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(indiceCle);
int[] d_prime_n = new int[48]; int[] d_prime_n = new int[48];
for (int i = 0; i < E.length; i++) { for (int i = 0; i < E.length; i++) {
d_prime_n[i] = Dn[E[i] % Dn.length]; d_prime_n[i] = Dn[E[i] % Dn.length];
@@ -369,52 +424,56 @@ public class Des {
return recollageBloc(bloc); return recollageBloc(bloc);
} }
/* Methodes générales */ /**
public int[] crypte(String message_clair) { * Crypte un message
*
* @param messageClair Chaine de caractère à crypter (attention uniquement des caractères ascii)
* @return Le message crypté en binaire
*/
public int[] crypte(String messageClair) {
int[] msg_bit = stringToBits(message_clair); int[] messageBinaire = stringToBits(messageClair);
int taille = (int) Math.ceil(msg_bit.length / (float) TAILLE_BLOC) * 64; int taille = (int) Math.ceil(messageBinaire.length / (float) TAILLE_BLOC);
int[] msgBit = new int[taille]; // Crée un tableau de taille fixe avec le messageBinaire (l'espace vide est comblé par des bits 0)
Arrays.fill(msgBit, 0); int[] messageBinaireTailleFixe = new int[taille * TAILLE_BLOC];
Arrays.fill(messageBinaireTailleFixe, 0);
// boucle du XOR System.arraycopy(messageBinaire, 0, messageBinaireTailleFixe, 0, messageBinaire.length);
for (int y = 0; y < msg_bit.length; y++) {
msgBit[y] = (msgBit[y] + msg_bit[y]) % 2;
}
int[][] decoupe = decoupage(msgBit, (int) Math.ceil(msg_bit.length / (float) TAILLE_BLOC));
int[][] msg_crypte_bit = new int[(int) Math.ceil(msg_bit.length / (float) TAILLE_BLOC)][TAILLE_BLOC];
int[][] decoupe = decoupage(messageBinaireTailleFixe, taille);
int[][] messageBinaireCrypte = new int[taille][TAILLE_BLOC];
//Boucle de génération 16 des clés //Boucle de génération 16 des clés
for (int n = 0; n < (TAILLE_BLOC / 4); n++) { for (int n = 0;
this.genereCle(n); n < (TAILLE_BLOC / 4);
this.genereS(n); this.genereCle(n), this.genereS(n), n++)
} ; // Empty body
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]);
int[][] decoupe2 = decoupage(decoupe[i], 2); int[][] secondeDecoupe = decoupage(decoupe[i], 2);
for (int n = 0; n < 16; n++) { for (int n = 0; n < 16; n++) {
int[] Gn1 = new int[decoupe2[1].length]; int[] Gn1 = new int[secondeDecoupe[1].length];
System.arraycopy(decoupe2[1], 0, Gn1, 0, Gn1.length); System.arraycopy(secondeDecoupe[1], 0, Gn1, 0, Gn1.length);
int[] F = fonction_F(n, decoupe2[1]); int[] F = fonction_F(n, secondeDecoupe[1]);
decoupe2[1] = xor(decoupe2[0], F); secondeDecoupe[1] = xor(secondeDecoupe[0], F);
decoupe2[0] = Gn1; secondeDecoupe[0] = Gn1;
} }
msg_crypte_bit[i] = recollageBloc(decoupe2); messageBinaireCrypte[i] = recollageBloc(secondeDecoupe);
invPermutation(PERM_INITIALE, msg_crypte_bit[i]); invPermutation(PERM_INITIALE, messageBinaireCrypte[i]);
} }
return recollageBloc(msg_crypte_bit); return recollageBloc(messageBinaireCrypte);
} }
/**
* Décrypte un message
*
* @param messageCode Message encrypté en binaire
* @return Le message décrypté
*/
public String decrypte(int[] messageCode) { public String decrypte(int[] messageCode) {
int[][] decoupe = decoupage(messageCode, messageCode.length / TAILLE_BLOC); int[][] decoupe = decoupage(messageCode, messageCode.length / TAILLE_BLOC);
@@ -432,9 +491,9 @@ 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[] messageDecrypte = recollageBloc(decoupe);
return bitsToString(removeCharNull(message_decrypte)); return bitsToString(removeCharNull(messageDecrypte));
} }
} }
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ui.App">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="9daab" class="javax.swing.JButton" binding="desButton" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Des"/>
</properties>
</component>
<hspacer id="3812b">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="acc45">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="6cd6a" class="javax.swing.JButton" binding="tripleDesButton" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="TripleDes"/>
</properties>
</component>
<component id="4d39c" class="javax.swing.JButton" binding="quitterButton" default-binding="true">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-12828863"/>
<enabled value="true"/>
<foreground color="-12828863"/>
<hideActionText value="false"/>
<text value="Quitter"/>
</properties>
</component>
<hspacer id="8cfce">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="fb80b" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Application Des"/>
</properties>
</component>
<vspacer id="6a02a">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
+27
View File
@@ -0,0 +1,27 @@
package ui;
import javax.swing.*;
public class App extends JFrame {
private JPanel mainPanel;
private JButton desButton, tripleDesButton, quitterButton;
public App() {
super("Projet Cryptographie");
this.add(mainPanel);
// Actions
desButton.addActionListener(e -> new FenetreDes());
tripleDesButton.addActionListener(e -> new FenetreTripleDes());
quitterButton.addActionListener(e -> System.exit(0));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 250);
this.setVisible(true);
}
public static void main(String[] args) {
new App();
}
}
+76
View File
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ui.FenetreDes">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="a9395" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Message clair"/>
</properties>
</component>
<component id="72826" class="javax.swing.JTextField" binding="inputMsgClair">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="53911" class="javax.swing.JButton" binding="crypterButton" default-binding="true">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Crypter"/>
</properties>
</component>
<component id="f854e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Message crypté"/>
</properties>
</component>
<component id="e0e86" class="javax.swing.JTextField" binding="inputMsgCrypte">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="a3b5f" class="javax.swing.JButton" binding="decrypterButton">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Décrypter"/>
</properties>
</component>
<vspacer id="2e16">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="1def4">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="6d5ec">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
+42
View File
@@ -0,0 +1,42 @@
package ui;
import cryptography.Des;
import javax.swing.*;
public class FenetreDes extends JFrame {
private final Des des;
private JPanel mainPanel;
private JTextField inputMsgClair, inputMsgCrypte;
private JButton crypterButton, decrypterButton;
public FenetreDes() {
super("Des");
des = new Des();
this.add(mainPanel);
crypterButton.addActionListener(e -> {
String messageClair = inputMsgClair.getText();
try {
int[] messageCrypte = des.crypte(messageClair);
inputMsgCrypte.setText(Des.bitsToString(messageCrypte));
} catch (Exception ignored) {
new FenetreErreur("Impossible de crypter le message", this);
}
});
decrypterButton.addActionListener(e -> {
int[] messageCrypte = Des.stringToBits(inputMsgCrypte.getText());
try {
String messageClair = des.decrypte(messageCrypte);
inputMsgClair.setText(messageClair);
} catch (Exception ignored) {
new FenetreErreur("Impossible de décrypter le message", this);
}
});
this.setSize(400, 250);
this.setVisible(true);
}
}
+15
View File
@@ -0,0 +1,15 @@
package ui;
import javax.swing.*;
public class FenetreErreur {
public FenetreErreur(String message, JFrame parent) {
final String TITLE = "Erreur";
JOptionPane.showMessageDialog(parent, message, TITLE, JOptionPane.ERROR_MESSAGE);
}
public static void main(String[] args) {
new FenetreErreur("Message", null);
}
}
+76
View File
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ui.FenetreTripleDes">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="5" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="216e9" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Message Clair"/>
</properties>
</component>
<component id="ac8e" class="javax.swing.JTextField" binding="inputMsgClair">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="c28d7" class="javax.swing.JButton" binding="crypterButton" default-binding="true">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Crypter"/>
</properties>
</component>
<component id="f982c" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Message Crypté"/>
</properties>
</component>
<component id="3b648" class="javax.swing.JTextField" binding="inputMsgCrypte">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="d6dd4" class="javax.swing.JButton" binding="decrypterButton">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Decrypter"/>
</properties>
</component>
<vspacer id="a8b11">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="4663d">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="e0141">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
+44
View File
@@ -0,0 +1,44 @@
package ui;
import cryptography.Des;
import cryptography.TripleDes;
import javax.swing.*;
public class FenetreTripleDes extends JFrame {
private JPanel mainPanel;
private JTextField inputMsgClair, inputMsgCrypte;
private JButton crypterButton, decrypterButton;
private final TripleDes tripleDes;
public FenetreTripleDes() {
super("Triple Des");
tripleDes = new TripleDes();
this.add(mainPanel);
crypterButton.addActionListener(e -> {
String messageClair = inputMsgClair.getText();
try {
int[] messageCrypte = tripleDes.crypte(messageClair);
inputMsgCrypte.setText(Des.bitsToString(messageCrypte));
} catch (Exception ignored) {
new FenetreErreur("Impossible de crypter le message", this);
}
});
decrypterButton.addActionListener(e -> {
int[] messageCrypte = Des.stringToBits(inputMsgCrypte.getText());
try {
String messageClair = tripleDes.decrypte(messageCrypte);
inputMsgClair.setText(messageClair);
} catch (Exception ignored) {
new FenetreErreur("Impossible de décrypter le message", this);
}
});
this.setSize(400, 250);
this.setVisible(true);
}
}
-1
View File
@@ -426,7 +426,6 @@ class DesTest {
@Test @Test
void genereCle() { void genereCle() {
for (Des des : FIXTURE) { for (Des des : FIXTURE) {
System.out.println(des);
// 1 élément généré // 1 élément généré
assertEquals(1, des.genereCle(1).length); assertEquals(1, des.genereCle(1).length);