convertir un ascii to string
Bonjour,
je cherche à convertir une chaine en ascii, aprés décaler ces ascii d'un entier,
à la fin je veux récupérer le code ascii de chaque caractére et le convertir en string:
voilà mon rogramme:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public String declerCesar(int d)
{
String chaine = new String();
String ch = new String();
try {
// traduction en tableau de code ASCII :
byte[] bytes = chaine.getBytes("ASCII");
int temp=0;
//décalage et convertion en string
for( int i=0; i<bytes.length; i++ ) {
//System.out.println( bytes[i]+1 );
temp = (bytes[i] + (byte) d) % 26;
ch += Integer.tostring(temp);
}
}
catch( java.io.UnsupportedEncodingException e ) {
// Le codage n'est pas reconnu.
//e.printStackTrace();
}
return ch;
} |