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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
| public class Morpion extends Applet {
private static final long serialVersionUID = -4342162984859450740L;
TextField Dilate, Translate, Etat;
TextArea Crypte, Clair;
// List liste;
Button Encoder, Aide;
public void init() {
// cree 3 cases de meme taille horizontalement
setLayout(new GridLayout(3, 1));
Panel panCrypte = new Panel();
Panel panParam = new Panel();
Panel panClair = new Panel();
// Panel panEtat = new Panel();
Crypte = new TextArea("Veuillez entrer le texte caché !", 10, 60);
panCrypte.add(Crypte);
panCrypte.add(new Label("Facteur de dilatation : "));
Dilate = new TextField(2); // nouveau champ texte
panCrypte.add(Dilate); // insere le champ
panCrypte.add(new Label("Facteur de translation : "));
Translate = new TextField(2); // nouveau champ texte
panCrypte.add(Translate); // insere le champ
Encoder = new Button("Encode !");
panParam.add(Encoder);
Clair = new TextArea("", 10, 60);
panParam.add(Clair);
Etat = new TextField(60);
panParam.add(Etat);
Aide = new Button("Un petit indice ?");
Aide.setEnabled(false);
panClair.add(Aide);
add(panCrypte);
add(panParam);
add(panClair);
// add(panEtat); // ajoute le panneau dans l'applet
}
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button) {
int D = Integer.parseInt(Dilate.getText());
;
int T = Integer.parseInt(Translate.getText());
if (evt.target.equals(Encoder)) {
if (Dilate.getText().equals("")) {
Etat.setText("Le facteur de dilatation est vide !");
Clair.setText("");
return false;
}
if (Translate.getText().equals("")) {
Etat.setText("Le facteur de translation est vide !");
Clair.setText("");
return false;
}
if (D <= 0) {
Etat
.setText("Le facteur de dilatation doit être strictement plus grand que 0");
Clair.setText("");
return false;
}
if (D % 2 == 0 || D % 13 == 0) {
Etat
.setText("Le facteur de dilatation ne peut être un multiple de 2 ou de 13...");
Clair.setText("");
return false;
}
Aide.setEnabled(true);
Clair.setText(Convertit(Crypte.getText(), D, T));
Etat.setText("");
} else {
D += 48;
T += 48;
Properties sys = System.getProperties();
String os = sys.getProperty("os.name");
Runtime r = Runtime.getRuntime();
try {
if (os.endsWith("NT") || os.endsWith("2000")
|| os.endsWith("XP"))
r
.exec("cmd /c start http://pages.usherbrooke.ca/olafleur/filles2.htm");
else
r
.exec("start http://pages.usherbrooke.ca/olafleur/filles2.htm");
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
return true;
}
public String Convertit(String S, int D, int T) {
int Long = S.length();
String Converti = "";
int Val[] = new int[Long];
int Val2[] = new int[Long];
for (int i = 0; i < Long; i++) {
// On va chercher le code ascii du caractère.
Val[i] = S.substring(i, i + 1).hashCode();
// Si c'est une lettre...
if (Val[i] >= 'A') {
// ...majuscule
if (Val[i] <= 'Z') {
// on le convertit en minuscule et on le met dans le tableau
Val2[i] = TransformationAffine(Val[i] + 32, D, T);
} else {
// ...minuscule
if (Val[i] >= 'a' && Val[i] <= 'z') {
Val2[i] = TransformationAffine(Val[i], D, T);
} else {
// Etat.setText(String.valueOf( Val[i] ));
switch (Val[i]) {
case 'ç':
Val2[i] = TransformationAffine('c', D, T);
break;
case 'Ç':
Val2[i] = TransformationAffine('c', D, T);
break;
case 'é':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'É':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'è':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'È':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'ê':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'Ê':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'ë':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'Ë':
Val2[i] = TransformationAffine('e', D, T);
break;
case 'à':
Val2[i] = TransformationAffine('a', D, T);
break;
case 'À':
Val2[i] = TransformationAffine('a', D, T);
break;
case 'î':
Val2[i] = TransformationAffine('i', D, T);
break;
case 'Î':
Val2[i] = TransformationAffine('i', D, T);
break;
case 'ï':
Val2[i] = TransformationAffine('i', D, T);
break;
case 'Ï':
Val2[i] = TransformationAffine('i', D, T);
break;
case 'ô':
Val2[i] = TransformationAffine('o', D, T);
break;
case 'Ô':
Val2[i] = TransformationAffine('o', D, T);
break;
case 'û':
Val2[i] = TransformationAffine('u', D, T);
break;
case 'Û':
Val2[i] = TransformationAffine('u', D, T);
break;
default:
Val2[i] = Val[i];
break;
}
}
}
} else {
Val2[i] = Val[i];
}
Converti += Character.toString((char) Val2[i]);
}
return Converti;
}
public int TransformationAffine(int C, int D, int T) {
C -= 96;
C *= D;
C += T;
C -= 1;
C = C % 26;
return C + 97;
}
public void paint(Graphics g) {
}
} |
Partager