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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
public static void main(String [] args)
{
char [][] tabLettres = {{'A','B','C','D','E'},{'F','G','H','I','J'},{'K','L','M','N','O'},{'P','Q','R','S','T'},{'U','V','X','Y','Z'}};
String [][] tabChiffres = new String[5][5];
String chaine = "";
int compteur = 0;
String texteClair = "JE PENSE DONC JE SUIS.";
String texteCode="";
//transformer les alphabets en nombre correspondant au nombre de la ligne et de au nombre de la colonne de l'alphabet
for(int i=0;i<tabLettres.length;i++)
{
for(int j=0;j<tabLettres.length;j++)
{
int ligne = (i+1);
int colonne = (j+1);
chaine = chaine + Integer.toString(ligne) + Integer.toString(colonne);
}
}
//System.out.println(chaine);
//construction du tableau des chiffres
for(int j=0;j<tabLettres.length ;j++)
{
tabChiffres[0][j] = chaine.substring(compteur, compteur +2 );
chaine = chaine.substring(compteur + 2,chaine.length() - 1);
}
for(int j=0;j<tabLettres.length ;j++)
{
tabChiffres[1][j] = chaine.substring(compteur, compteur +2 );
chaine = chaine.substring(compteur + 2,chaine.length() - 1);
}
for(int j=0;j<tabLettres.length ;j++)
{
tabChiffres[2][j] = chaine.substring(compteur, compteur +2 );
chaine = chaine.substring(compteur + 2,chaine.length() - 1);
}
chaine = "41424344455152535455";
for(int j=0;j<tabLettres.length ;j++)
{
tabChiffres[3][j] = chaine.substring(compteur, compteur +2 );
chaine = chaine.substring(compteur + 2,chaine.length() - 1);
}
for(int j=0;j<tabLettres.length ;j++)
{
tabChiffres[4][0] = "51";
tabChiffres[4][1] = "52";
tabChiffres[4][2] = "53";
tabChiffres[4][3] = "54";
tabChiffres[4][4] = "55";
}
//affichage du tableau des chiffres
System.out.println();
for(int i=0;i<tabLettres.length;i++)
{
for(int j=0;j<tabLettres.length;j++)
{
System.out.println("tabChiffres["+(i+1)+"]["+(j+1)+"] = "+tabChiffres[i][j]);
}
}
for(int k=0;k<texteClair.length();k++)
{
for(int i=0;i<tabLettres.length;i++)
{
for(int j=0;j<tabLettres.length;j++)
{
if(texteClair.charAt(k) == 'W')
{
texteClair = texteClair.replace('W', 'V');
}
if(texteClair.charAt(k) == tabLettres[i][j])
{
texteCode = texteCode + tabChiffres[i][j];
}
}
}
}
System.out.println(texteCode);
} |
Partager