Cryptage

Fermé
david - 13 déc. 2011 à 19:43
KX Messages postés 16668 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 17 mars 2023 - 13 déc. 2011 à 22:33
Bonjour,

Je suis en train de créer un programme de cryptage suivant le code de César, je suis arrivé a coder mais une seule lettre et je voudrais coder un mot entier, voici mon code

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;


public class Cryptage {

//premier tableau x
String [] x={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

//deuxieme tableau x2

String [] x2={"e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","a","b","c","d"};

int i;



Text text;
Text text2;
Button button;
Shell shell;

public Cryptage(){
Display display= new Display();
shell= new Shell(display);

// zone de texte dans la quelle on écris le mot qu'on veut coder

text= new Text(shell, SWT.LEFT);


//label dans lequel on veut afficher le mot aprés le codage

label= new Text(shell, SWT.LEFT);

button= new Button(shell, SWT.PUSH);
button.setText("crypter");


text.getText().toCharArray();


//action du boutton crypter

Listener listener= new Listener(){
public void handleEvent (Event event){

// tt se passe ici

for (i=0; i<26;i++){

if (text.getText().equals(x[i])){
label.setText(x2[i]);
}


}


}
};
button.addListener(SWT.Selection, listener);

public static void main (String [] args){}}


est ce que quelqu'un peut m'aider, et me montrer comment coder un mot entier svpp??

2 réponses

rominail Messages postés 30 Date d'inscription vendredi 23 avril 2010 Statut Membre Dernière intervention 3 novembre 2012 3
13 déc. 2011 à 20:10
avec quel langage crypte tu?...
C?
0
KX Messages postés 16668 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 17 mars 2023 3 004
13 déc. 2011 à 22:28
Vu son code, il est assez évident que c'est du Java...
0
KX Messages postés 16668 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 17 mars 2023 3 004
13 déc. 2011 à 22:33
Commence par décomposer ton problème pour faire des petites méthodes assez simple, avec éventuellement un affichage console, car là tu essayes de faire une interface graphique inutile que tu ne maîtrise de toute façon pas !

Idée :

public static char crypterUneLettre(char c);
public static char decrypterUneLettre(char c);

public static String crypterUnMot(String s);
public static String decrypterUnMot(String s);

public static void main(String...args)
{
    System.out.print("Texte à crypter : ");
    String s1 = new Scanner(System.in).nextLine();
    String s2 = crypterUnMot(s1);
    System.out.println("Texte crypté : "+s2);
    String s3 = decrypterUnMot(s2);
    System.out.println("Texte décrypté : "+s3);
}
0