Created
October 30, 2018 18:18
-
-
Save m-242/e3dc38fe306ef54a16b7d4fd0960bd5d to your computer and use it in GitHub Desktop.
Une résolution d'exo pour un td
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ex3 | |
{ | |
//fonctions de chiffrement et déchiffrement | |
public static String chiffre(String message, String cle) | |
{ | |
String renvoi = ""; | |
for(int i =0; i<message.length(); i++) | |
{ | |
renvoi += chiffreLettre(message.charAt(i), cle.charAt(i%cle.length())); | |
} | |
return renvoi; | |
} | |
public static String dechiffre(String message, String cle) | |
{ | |
String renvoi = ""; | |
for(int i =0; i<message.length(); i++) | |
{ | |
renvoi += dechiffreLettre(message.charAt(i), cle.charAt(i%cle.length())); | |
} | |
return renvoi; | |
} | |
public static void main(String[] args) | |
{ | |
System.out.println(chiffre("Allo Ali", "yes")); | |
} | |
//Fonctions d'aide pour ne pas utiliser ce que je ne connais pas. | |
public static char chiffreLettre(char m, char c) | |
{ | |
int[] cle = bin(ord(c)); | |
int[] message = bin(ord(m)); | |
int[] renvoi = new int[7]; | |
for(int i=0; i<7; i++) | |
{ | |
renvoi[i] = xor(message[i], cle[i]); | |
} | |
return asc(dec(renvoi)); | |
} | |
public static char dechiffreLettre(char m, char c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment