Chiffrement/dechiffrement Elgamal

Fermé
cheman - Modifié par crapoulou le 19/03/2017 à 17:17
 cheman - 19 mars 2017 à 18:18
Salut, j’aimerais faire un programme de chiffrement et de déchiffrement Elgamal en java en utilisant GUI j'ai des soucis a le compile
voile le code source

package projet.java.cryptographie;

/* @author pc */

import java.io.Serializable;
import java.math.BigInteger;
import java.security.SecureRandom;
public class essai {
    public static void main (String[] args ){ 

class chiffre  {
        public BigInteger p,g,a,h,d;
          SecureRandom sr = new SecureRandom ();
          chiffre (BigInteger p,BigInteger g,BigInteger a,BigInteger h, BigInteger d ){
             this p= p;
             this g = g;
             this a= a;
             this h= h;
             this d= d;
         }
   public BigInteger[]  cle1(){
        p = BigInteger.probablePrime(1024, sr);
        d =p.subtract(java.math.BigInteger.ONE);
        do{
            g=new java.math.BigInteger (64,sr);
        }
        while(g.modPow(d,p).intValue() != 1);

a=new BigInteger(512,sr);
        h=g.modPow(a, p);
         BigInteger k = new BigInteger (128,sr);
        BigInteger c1=g.modPow(k,p);
        BigInteger c2= (h.modPow(k, p).mod(p));
BigInteger [] c = { c1 , c2 };
return c;
   } 

}

public class essai extends javax.swing.JPanel {

}

/* Creates new form essai */


/* This method is called from within the constructor to initialize the form.
WARNING: Do NOT modify this code. The content of this method is always
regenerated by the Form Editor. */

@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(205, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jButton1)
                .addContainerGap(163, Short.MAX_VALUE))
        );
    }// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
cle1();
        String mess = jTextArea1.getText();
BigInteger m = new BigInteger(mess.getBytes());
      cle chiffre = new chiffre;
        chiffre = c[1].multiply(m);
   c2 = c2.mod(p);

}                                        


// Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration                   
}


EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ici : ICI

Merci d'y penser dans tes prochains messages.

1 réponse

KX Messages postés 16733 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 31 janvier 2024 3 015
19 mars 2017 à 17:29
Bonjour,

Pour commencer, créer une interface graphique avec NetBeans est une mauvaise idée pour apprendre à programmer car le code généré est vraiment moche.

Quant à tes problèmes de compilation :
  • tu as deux classes essai... il n'en faut qu'une
  • la méthode main commence ligne 9 mais ne se termine jamais
  • il faut remplacer les
    this x
    par des
    this.x
    ...
  • la méthode jButton1ActionPerformed ligne 98 utilise des méthodes et objets qui ne sont pas déclarés.
0
merci, le prof nous impose Netbeans il nous a donne le code ci dessous et nous a dit de réalise ce programme en interface graphique
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Scanner;

/**
 *
 * @author pc
 */
public class ELGamal1 {
    public static void main (String[] args ){
        SecureRandom sr = new SecureRandom ();
        BigInteger p,g,a,h,d;
        p=BigInteger.probablePrime(1024, sr);
        d =p.subtract(BigInteger.ONE);
        do{
            g=new BigInteger (64,sr);
        }
        while(g.modPow(d,p).intValue() != 1);

        a=new BigInteger(512,sr);
        h=g.modPow(a, p);
        Scanner sc = new Scanner(System.in);
        System.out.println("entre le message");
        String mess = sc.nextLine();
        BigInteger m = new BigInteger(mess.getBytes());
        BigInteger k = new BigInteger(128,sr);
        BigInteger c1=g.modPow(k,p);
        BigInteger c2= m.multiply(h.modPow(k, p).mod(p));
        BigInteger dechiffre = c1.modPow(d.subtract(a), p).multiply(c2).mod(p);
        System.out.println("le message chiffre est :"+new String(c2.toByteArray()));
        System.out.println("le dechiffre est :"+new String(dechiffre.toByteArray()));
    }
}
0