Urgent! What is wrong with this program? Part 1


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Urgent! What is wrong with this program? Part 1

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Unhappy Urgent! What is wrong with this program? Part 1

    Please, i am writing a project on implementation of Rivest-Shamir-Adleman(RSA) algorithm on local area network(LAN).But the JAVA program i wrote refused to work. please, can anyone help me with this.The program is given below is only a part of the entire program due to space constraint. The remain program will be sent in the next post.Thanks
    Code:
      import java.awt.*;
       import java.awt.event.*;
       import javax.swing.*;
       import java.lang.*;
    public class My_RSA extends JFrame {
                   private Container  container;
                   private JFrame iFrame,jFrame, kFrame;
                   private GridBagLayout layout;
                   private GridBagConstraints constraints;
                   private JTextField nField, dField;
                   private JTextArea messageArea, cypherArea, plainArea,keysArea;
                   private  JScrollPane messagescroll, cypherScroll, plainScroll;
                   private JButton readButton, sendButton, okButton, cancelButton;
                   private JPanel jPanel, nPanel,dPanel, okPanel,myPanel, mePanel,
       statusPanel, progressPanel,cancelPanel;
                   private JPanel boardPanel1, boardPanel2, cypherPanel,plainPanel, 
      messagePanel, readPanel, sendPanel;
                   private JLabel emptyLabel, jLabel, nLabel, dLabel, dumLabel1, dumLabel2, 
       statusLabel;
                   private  JLabel emptyLabel1,  emptyLabel2 , emptyLabel3, emptyLabel4;
                   private  JPanel emptyPanel,  emptyPanel1, emptyPanel2, emptyPanel3,
        emptyPanel4;
                    private String message = "", plaintext = "", cyphertext = "", publish = "";
                    private long d, e, m, n, p, q;
                     private final JProgressBar  current = new JProgressBar(0, 100);
               
                         private  KeyGenerator gen;
                         private  Encryption enc;
                         private  Decryption dec;
                         private  Sending go;
      public My_RSA()
       {
                    Super("RSA Encryption System");
    
                     Container = getContentPane();
                     layout = new GridBagLayout();
                     container.setLayout(layout);
                     constraints = new GridBagConstraints();
                     gen = new KeyGenerator();
                     kFrame = new JFrame("Sending...");
                     mePanel = new JPanel();
                     mePanel.setLayout(layout);
                     progressPanel = new JPanel();
                     progressPanel.add(current);
                       cancelPanel = new JPanel();
                       statusPanel = new JPanel();
                       statusPanel = new JLabel(" From A to B");
                       statusPanel.add(statusLabel);
                       cancelButton = new JButton("cancel");
                       cancelButton.addActionListener(
                  new ActionListener() {
                                 public void actionPerformed(ActionEvent event)
                                 {
                                                Current.setValue(0);
                                                 kFrame.setVisible(false);
                                    }
                         }
      );
       Current.setSize(100, 5);
       cancelPanel.add(cancelButton);
       emptyLabel1 = new JLabel("");
       emptyLabel2 = new JLabel("");
       emptyLabel3 = new JLabel("");
       emptyLabel4 = new JLabel("");
        emptyPanel1 = new JPanel();
        emptyPanel2 = new JPanel();
        emptyPanel3 = new JPanel();
        emptyPanel4= new JPanel();
            readPanel = new JPanel();
            sendPanel = new JPanel();
            messagePanel = new JPanel();
            cypherPanel = new JPanel();
            plainPanel = new JPanel()
             boardPanel1 = new JPanel();
             boardPanel1.setLayout(new FlowLayout()); 
             boardPanel2 = new JPanel();
             boardPanel2.setLayout(new FlowLayout());
               messageArea = new JTextArea(5,60);
               messageArea.setLineWrap(true);
               messageArea.setWrapStyleWord(true);
               messageArea.setFont(new Font("Monospaced",  Font.PLAIN, 12));
               messageArea.setEditable(true);
              cypherArea = new JTextArea(20,20);
              cypherArea.setLineWrap(true);
              cypherArea.setWrapStyleWord(true);
              cypherArea.setFont(new Font(" Serif",  Font.PLAIN, 12));
               cypherArea.setEditable(false);
               plainArea = new JTextArea(20,22);
               plainArea.setLineWrap(true);
               plainArea.setWrapStyleWord(true);
               plainArea.setFont(new Font(" Monospaced",  Font.PLAIN, 12));
               plainArea.setEditable(false);
               messageScroll = new JScrollPane(messageArea,
      ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEVER);
                  cypherScroll = new JScrollPane(cypherArea,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                 plainScroll = new JScrollPane(plainArea, 
     ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
     ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                 readButton = new JButton("read>>>");
                 readButton.addActionListener(
                             new  ActionListener()  {
                                            public void actionPerformed(ActionEvent event)
                                             {
                                                          secretKey();
                                              }
                              }
     );
     sendButton = new JButton("send");
    sendButton.addActionListener(
                  new ActionListner() {
                                public void actionPerformed(ActionEvent event)
                                {
                                                  kFrame.setVisible(false);
                                                  publish = "";
                                                  do {
                                                                  p = gen.primeNumber();
                                                 }while(!(p > 10)  || !(p < 26) );
                                                 do {
                                                               q = gen.primeNumber();
    
                                                  }while( (q <=p)  || !((q-p) >2) );
                                                  n  = p*q;
                                                  m = (p-1) * (q-1);
                                                  e = gen.coprime(m);
                                                  d = gen.find_d(m,e);
                                                   message = messageArea.getText();
                                                   enc = new Encryption(message);
                                                    cyphertext = enc.encrypt(e,n);
                                                    publish_Keys();
                                                    kFrame.setVisible(true);
                                                    go = newSending(cyphertext,kFrame,iFrame, 
         cypherArea, current, container);
                                                    go.start();
                     kFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                     container.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                                                 }
                                    }
                      );
                     cypherPanel.add(cypherScroll);
                     cypherPanel.setBorder(BorderFactory.createTitledBorder("cyphertext"));
                     readPanel.add(readButton);
                     plainPanel.add(plainScroll);
                    plainPanel.setBorder(BorderFactory.createTitledBorder("recovered plaintext")); 
                      messagePanel.add(messageScroll);
                           sendPanel.add(sendButton);
                           emptyPanel1.add(emptyLabel1);
                           emptyPanel2.add(emptyLabel2);
                           emptyPanel3.add(emptyLabel3);
                           emptyPanel4.add(emptyLabel4);
                           boardPanel1.add(cypherPanel);
                           boardPanel1.add(readPanel);
                           boardPanel1.add(plainPanel);

  2. #2
    Join Date
    Nov 2009
    Posts
    2

    Urgent! What is wrong with this program? Part 2

    This is the continuation of the program.
    Code:
    boardPanel1.setBorder(BorderFactory.createTitledBorder("incoming message"));
                           boardPanel2.add(messagePanel);
                           boardPanel2.add(sendPanel);
                           boardPanel2.setBorder(BorderFactory.createTitledBorder("outgoing message"));
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent3(emptyPanel1, 0, 0, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent3(emptyPanel2, 1, 0, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent3(statusPanel, 2, 0, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent3(progressPanel, 3, 0, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent3(cancelPanel, 3, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(emptyPanel1, 0, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(emptyPanel1, 0, 1, 1, 1); 
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(boardPanel1, 1, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(emptyPanel2, 2, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(emptyPanel3, 3, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(emptyPanel4, 4, 1, 1, 1);
                            constraints.fill = GridBagConstraints.BOTH;
                            addComponent(boardPanel2, 5, 1, 1, 1);
                             kFrame.getContentPane().add(mePanel, BorderLayout.CENTER);
                             kFrame.setResizable(false);
                             kFrame.setSize(310,150);
                             kFrame.setVisible(false);
                             kFrame.setLocation(270, 390);
                             setResizable(false);
                             setSize(550,680);
                             setVisible(true);
                             setLocation(250,42);
      }
    
    private void publish_Keys()
      {
                     iFrame = new JFrame("Publishing Keys");
                     publish += "\n PUBLIC KEY:\n (n, e) = ("+n+", "+e+")";
                     publish += "\n \n SECRET KEY:\n (n, d) = ("+n+", "+d+")";
                    keysArea = new JTextArea();
                    keysArea.setFont( new Font("Monospaced",  Font.BOLD, 14) );
                    keysArea.setEditable(false);
                      keysArea.setText(publish);
                     iFrame.getContentPane().add(new JScrollPane(keysArea),
     Borderlayout.CENTER);
                     iFrame.setResizable(false);
                     iFrame.setSize(210, 220);
                     iFrame.setVisible(false);
                     iFrame.setLocation(570, 390);
     }
     private void secretKey()
    {
                      jFrame = new JFrame("SECRET KEY");
                      myPanel = new JPanel();
                      jPanel = new JPanel();
                      nPanel = new JPanel();
                      dPanel = new JPanel();
                       emptyPanel = new JPanel();
                       okPanel = new JPanel();
                       emptyLabel = new JLabel("");
                       nLabel = new JLabel("n: ");
                        dLabel = new JLabel("d: ");
                        dumLabel1 = new JLabel(" ");
                       jLabel = new JLabel("Enter the Secret Key:");
                       jPanel.add(jlabel);
                       okButton = new JButton("OK");
                       okButton.addActionListener(
                                     new ActionListener()  {
                                                   public void actionPerformed(ActionEvent event)
                                                    {
                                                                  jFrame.setVisible(false);
                                                                   n = Long.parseLong(nField.getText());
                                                                   d = Long.parseLong(dField.getText());
                                                                    cyphertext = cypherArea.getText();
                                                                    dec = new  Decryption(cyphertext);
                                                                    plaintext = dec.decrypt(d,n);
                                                                    plainArea.setText(plaintext);
                                       }
                        }
       );
        myPanel.setLayout(layout);
        nField = new JTextField(10);
        nField.setFont(new Font("Monospaced" , Font.PLAIN, 14));
        dField = new JTextField(10);
        dField.setFont(new Font("Monospaced" , Font

  3. #3
    Join Date
    Nov 2009
    Posts
    2

    Unhappy Urgent! What is wrong with this program? Part 3

    This is the last part of the program.Thank you for your anticipated cooperation.
    Code:
        dField.setFont(new Font("Monospaced" , Font.PLAIN, 14));
         nPanel.setLayout(new FlowLayout());
         nPanel.add(nLabel);
         nPanel.add(nField);          
         dPanel.setLayout(new FlowLayout());
         dPanel.add(dLabel);
         dPanel.add(dField);
         emptyPanel.add(emptyLabel);
          okPanel.add(okButton);
           constraints.fill = GridBagConstraints.BOTH;
           addComponent2(jPanel, 0, 0, 1, 1);
    
             constraints.fill = GridBagConstraints.BOTH;
             addComponent2(nPanel, 1, 1, 1, 1);
        
             constraints.fill = GridBagConstraints.BOTH;
             addComponent2(dPanel, 2, 1, 1, 1);
            constraints.fill = GridBagConstraints.BOTH;
            addComponent2(emptyPanel, 3, 1, 1, 1);
            constraints.fill = GridBagConstraints.BOTH;
            addComponent2(okButton, 4, 1, 1, 1);
            jFrame.getContentPane().add(myPanel);
             jFrame.setLocation(438, 360);
             jFrame.setResizable(false);
             jFrame.setSize(200, 220);
             jFrame.setVisible(true);
    }
    private void addComponent(Component component, int row, int column, int width,
     int height)
    {
                constraints.gridx = column;
                constraints.gridy = row;
                 constraints.gridwidth = width;
                 constraints.gridheight = height;
                 layout.setConstraints(component, constraints);
                container.add(component);
      }
      private void addComponent2(Component component, int row, int column, int width, int height)
      {
                 constraints.gridx = column;
                constraints.gridy = row;
                 constraints.gridwidth = width;
                 constraints.gridheight = height;
                 layout.setConstraints(component, constraints);
                myPanel.add(component);
    }
     private void addComponent3(Component component, int row, int column, int width, int height)
    {
                constraints.gridx = column;
                constraints.gridy = row;
                 constraints.gridwidth = width;
                 constraints.gridheight = height;
                 layout.setConstraints(component, constraints);
                mePanel.add(component);
    }
    public static void main(String args[])
    {
                My_RSA app = new My_RSA();
                app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I put all the code in one thread...there is no need for three separate threads.

    Also, I'm pretty confident that no one is going to wade through all of that code just to try and figure out what you mean by "But the JAVA program i wrote refused to work."

    Could you provide some specific examples of what isn't working, what it should do, and what it is doing?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Nov 2009
    Posts
    10
    In which thread you put the whole code. Please give link to that?
    Last edited by cyrus12009; 12-04-2009 at 02:23 AM.
    6600 games are cool stuff for your mobile phone.

  6. #6
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by cyrus12009 View Post
    In which thread you put the whole code. Please give link to that?
    This one...they were in 3 separate, individual, threads.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. small issues with a program
    By jimJohnson in forum Java
    Replies: 1
    Last Post: 05-05-2008, 12:44 AM
  2. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++
    Replies: 1
    Last Post: 08-01-2007, 10:44 PM
  3. Connecting to a Server Program HELP
    By sedricbenson@ho in forum C++
    Replies: 2
    Last Post: 11-07-2006, 08:58 AM
  4. Noob Questions - Part 1
    By gfry81 in forum .NET
    Replies: 1
    Last Post: 06-29-2005, 02:07 AM
  5. How can I build copy protection into my program
    By W.Pierce in forum VB Classic
    Replies: 1
    Last Post: 12-11-2001, 09:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center