import java.util.List; public class AES { // Constantes private static final int taille_bloc = 128; private static final List Rcon = List.of(); private static final List> SBox = List.of(); private static final List> SBoxInv = List.of(); // Attributs private int taille_cle_maitre; private int nb_ronde ; private List> master_key; private List> keys; // Constructeur public AES (int tailleCleMaitre){ this.taille_cle_maitre = tailleCleMaitre; } // Méthodes public int[] stringToBits(String message) { // chaque caractère if (message == null || message.isEmpty()) { return new int[0]; } int totalBits = message.length() * 8; // Calculer la taille totale en bits (chaque char = 8 bits en UTF-8) int[] bits = new int[totalBits]; for (int i = 0; i < message.length(); i++) { char c = message.charAt(i); int charIndex = i * 8; // Extraire chaque bit du caractère for (int j = 0; j < 8; j++) { // Déplacer le bit j à la position la moins significative et masquer int bit = (c >> (7 - j)) & 0x01; bits[charIndex + j] = bit; } } return bits; } public String bitsToString(int[] bits) { if (bits == null || bits.length == 0) { return ""; } if (bits.length % 8 != 0) { // Vérifier que la taille est un multiple de 8 (car chaque caractère = 8 bits) throw new IllegalArgumentException("La taille du tableau de bits doit être un multiple de 8."); } StringBuilder result = new StringBuilder(); int numChars = bits.length / 8; for (int i = 0; i < numChars; i++) { int charIndex = i * 8; char c = 0; for (int j = 0; j < 8; j++) { // Reconstruire le caractère à partir des 8 bits if (bits[charIndex + j] != 0 && bits[charIndex + j] != 1) { throw new IllegalArgumentException("Le tableau doit contenir uniquement des 0 ou des 1."); } // Déplacer le bit à sa position et l'ajouter au caractère c = (char) ((c << 1) | bits[charIndex + j]); } result.append(c); } return result.toString(); } public List genereMasterKey() { List L = List.of(); for (int i = 1 ; i <= 128 ; i ++){ L.add((int) (Math.random()*101)%2); // Ajoute aléatoirement 0 ou 1 } return L; } }