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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
| package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public abstract class Cryptage implements ActionListener {
public static void main(String[] args) {
final ArrayList crypte = new ArrayList();
final JFrame fenetre = new JFrame();
fenetre.setTitle("Cryptage / décryptage");
fenetre.setResizable(false);
fenetre.setAlwaysOnTop(true);
fenetre.setSize(450,200);
fenetre.setLocationRelativeTo(null);
fenetre.setLayout(new GridLayout(4,1));
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton no_cle = new JButton("TROUVER UNE CLE INCONNUE");
no_cle.setBackground(Color.yellow);
no_cle.setForeground(Color.DARK_GRAY);
JButton quitter = new JButton("Quitter");
quitter.setForeground(Color.red);
JButton crypter = new JButton("Crypter un message");
crypter.setBackground(Color.green);
crypter.setForeground(Color.blue);
JButton decrypter = new JButton("Décrypter un message");
decrypter.setForeground(Color.blue);
decrypter.setBackground(Color.green);
fenetre.add(crypter);
fenetre.add(decrypter);
fenetre.add(no_cle);
fenetre.add(quitter);
fenetre.setVisible(true);
crypter.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
fenetre.dispose();
final String cle= JOptionPane.showInputDialog(null, "Veuillez indiquer la clé de cryptage utilisée :", "Clé de cryptage", JOptionPane.INFORMATION_MESSAGE);
final JFrame fenetre_cryptage = new JFrame();
fenetre_cryptage.setTitle("Cryptage");
fenetre_cryptage.setResizable(false);
fenetre_cryptage.setAlwaysOnTop(true);
fenetre_cryptage.setSize(1300,615);
fenetre_cryptage.setLocationRelativeTo(null);
fenetre_cryptage.setLayout(new FlowLayout());
fenetre_cryptage.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextArea entre = new JTextArea("Tapez le message à crypter ici");
JButton cryptage = new JButton("Crypter le message !");
cryptage.setBackground(Color.orange);
cryptage.setPreferredSize(new Dimension(200,40));
entre.setPreferredSize(new Dimension(1280,530));
entre.setLineWrap(true);
fenetre_cryptage.add(entre);
fenetre_cryptage.add(cryptage);
fenetre_cryptage.setVisible(true);
cryptage.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
String c = "";
fenetre_cryptage.dispose();
JOptionPane.showMessageDialog(null, "Votre message a bien été crypté ", "Information", 1);
for(int i = 0; i < entre.getText().length(); i++){
crypte.add(entre.getText().charAt(i)+cle);
}
for(int i = 0; i < crypte.size(); i++){
c += crypte.get(i);
}
final JFrame fen_crypte = new JFrame();
fen_crypte.setTitle("Cryptage");
fen_crypte.setResizable(false);
fen_crypte.setAlwaysOnTop(true);
fen_crypte.setSize(1355,715);
fen_crypte.setLocationRelativeTo(null);
fen_crypte.setLayout(new FlowLayout());
fen_crypte.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea message_c = new JTextArea(c);
message_c.setEditable(false);
message_c.setLineWrap(true);
message_c.setPreferredSize(new Dimension(1325,630));
JButton menu = new JButton("Menu");
menu.setBackground(Color.gray);
fen_crypte.getContentPane().add(message_c);
fen_crypte.add(menu);
crypte.clear();
fen_crypte.setVisible(true);
menu.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
fen_crypte.dispose();
fenetre.setVisible(true);
}
});
}
});
}
});
decrypter.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
fenetre.dispose();
final String cle_d= JOptionPane.showInputDialog(null, "Veuillez indiquer la clé de cryptage utilisée :", "Clé de cryptage", JOptionPane.INFORMATION_MESSAGE);
final JFrame decrypte = new JFrame();
decrypte.setTitle("Décryptage");
decrypte.setResizable(false);
decrypte.setAlwaysOnTop(true);
decrypte.setSize(1355,715);
decrypte.setLocationRelativeTo(null);
decrypte.setLayout(new FlowLayout());
decrypte.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextArea decrypte1 = new JTextArea("Tapez ici le message à décrypter");
decrypte1.setLineWrap(true);
decrypte1.setPreferredSize(new Dimension(1330,630));
JButton bouton_decrypter = new JButton("Décrypter le message !");
bouton_decrypter.setPreferredSize(new Dimension(200,40));
bouton_decrypter.setBackground(Color.orange);
decrypte.add(decrypte1);
decrypte.add(bouton_decrypter);
crypte.clear();
decrypte.setVisible(true);
bouton_decrypter.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
decrypte.dispose();
JOptionPane.showMessageDialog(null, "Votre message a bien été décrypté ", "Information", 1);
String d = "";
for(int i = 0; i < decrypte1.getText().length(); i++){
crypte.add(decrypte1.getText().charAt(i));
}
for(int i = 0; i < crypte.size(); i++){
d += crypte.get(i);
}
d = d.replace(cle_d,"");
final JFrame decryptage = new JFrame();
decryptage.setTitle("Cryptage");
decryptage.setResizable(false);
decryptage.setAlwaysOnTop(true);
decryptage.setSize(1300,615);
decryptage.setLocationRelativeTo(null);
decryptage.setLayout(new FlowLayout());
decryptage.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextArea message_d = new JTextArea(d);
message_d.setLineWrap(true);
message_d.setPreferredSize(new Dimension( 1280,530));
JButton menu = new JButton("Menu");
menu.setBackground(Color.gray);
message_d.setEditable(false);
decryptage.getContentPane().add(message_d);
decryptage.add(menu);
decryptage.setVisible(true);
menu.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
decryptage.dispose();
fenetre.setVisible(true);
}
});
}
});
}
});
quitter.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
fenetre.dispose();
}
});
no_cle.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
fenetre.dispose();
JOptionPane.showMessageDialog(null, "Si l'algoritme de cryptage qui a été utilisé pour crypter ce message est trop sécurisé , \nil se peut que vous ne parveniez pas à trouver la clé de décryptage même avec ce logiciel !","Avertissement", JOptionPane.WARNING_MESSAGE);
final JFrame find_cle = new JFrame();
find_cle.setTitle("Cle de décryptage");
find_cle.setResizable(false);
find_cle.setAlwaysOnTop(true);
find_cle.setSize(1330,680);
find_cle.setLocationRelativeTo(null);
find_cle.setLayout(new FlowLayout());
find_cle.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton bouton_cle = new JButton("Chercher la clé !");
bouton_cle.setPreferredSize(new Dimension(250,40));
bouton_cle.setBackground(Color.orange);
final JTextArea message_crypte = new JTextArea("Insérez ici un extrait du texte crypté dont vous cherchez la clé (minimum 300 caractères ...) ");
message_crypte.setLineWrap(true);
message_crypte.setPreferredSize(new Dimension(1300,590));
find_cle.add(message_crypte);
find_cle.add(bouton_cle);
find_cle.setVisible(true);
bouton_cle.addActionListener(new ActionListener( )
{
public void actionPerformed(ActionEvent e)
{
String message_final = "";
int compteur = 2;
boolean continuer = false;
while(continuer == false){
for (int i = 0; i<message_crypte.getText().length() ; i++){
crypte.add(message_crypte.getText().charAt(i));
}
find_cle.dispose();
for(int i = 0; i<crypte.size(); i += compteur){
message_final += crypte.get(i);
if(i != 0 && i % 300 == 0){
message_final += "\n";
}
}
int reponse = JOptionPane.showConfirmDialog(null, "Voici un extrait du message obtenu :\n"+message_final+"\nEst-il cohérent ?");
if(reponse == 0){
continuer = true;
}
else if (reponse == 1){
compteur++;
message_final = "";
crypte.clear();
}
else{
compteur++;
message_final = "";
crypte.clear();
}
}
String cle_trouve = "";
for(int i = 1; i <compteur; i++){
cle_trouve += message_crypte.getText().charAt(i);
}
JOptionPane.showMessageDialog(null, "Voici la clé : "+cle_trouve, "Clé de cryptage déchiffrée !",JOptionPane.WARNING_MESSAGE);
fenetre.setVisible(true);
}
});
}
});
}
} |
Partager