CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    1

    Exclamation Problem With RSA Interface

    Problem is that the result is not showing in the actual output window of the interface, what is causing this?


    All Im getting in the general output of JCreator is this:

    Plaintext:
    Plaintext:
    Plaintext:
    Plaintext:
    Plaintext:
    Plaintext:
    Plaintext:

    This repeats depending on how many times Ive clicked the Run button.


    Thanks.


    Code:
    package newpackage4;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    
    public class NewClass5 extends JFrame implements ActionListener{
    
       public NewClass5() {
            initiateComponents(); 
        }
            
        private JLabel TitleLabel;
          
        private JPanel innerPanel;
        
        private JLabel StringInputLabel;
        
        private JTextField InputStringTextField;
            
        private JButton RunButton;
        private JButton SaveButton;
        private JButton ResetButton;
        private JButton ExitButton;
        
        private JTextArea OutputWindow;
        
        private char[] plainText = new char[25];
          
        private void initiateComponents() {
            getContentPane().setLayout(null);
            setTitle("Simplified Simulation: RSA Security Algorithm");
            setSize(new Dimension(1025, 703));
            setLocation(0,0);
            setResizable(false);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            getContentPane().setBackground(new Color(100,200,200));
        
            getContentPane().add(getInnerPanel());
            getContentPane().add(getTitleLabel());
            populateInnerPanel();
        }
    
        private JLabel getTitleLabel() {
            TitleLabel = new JLabel();
            TitleLabel.setFont(new Font("Arial",1,44));
            TitleLabel.setText("        RSA Algorithm");
            TitleLabel.setBackground(new Color(255,255,255));
            TitleLabel.setBorder(new EtchedBorder());
            TitleLabel.setBounds(300,40,500,60);
            return TitleLabel;
        }
        
         private JPanel getInnerPanel() {
            innerPanel = new JPanel();
            innerPanel.setLayout(null);
            innerPanel.setBackground(new Color(190,255,255));
            innerPanel.setBorder(new TitledBorder(
                    new TitledBorder(null, "",
                        TitledBorder.DEFAULT_JUSTIFICATION,
                        TitledBorder.DEFAULT_POSITION,
                        new Font("Times New Roman", 1, 12))));
            innerPanel.setBounds(40,160,930,460);
            return innerPanel;
        }
    
        private void populateInnerPanel() {
            StringInputLabel = new JLabel();
            StringInputLabel.setFont(new Font("Bookman Old Style",0,13));
            StringInputLabel.setText("Enter in a word:");
            innerPanel.add(StringInputLabel);
            StringInputLabel.setBounds(65,20,110,20);
      
            InputStringTextField = new JTextField();
            InputStringTextField.setText("");
            innerPanel.add(InputStringTextField);
            InputStringTextField.setBounds(180,20,220,20);
                
            RunButton = new JButton();
            RunButton.setFont(new Font("Bookman Old Style",1,13));
            RunButton.setText("Run");
            innerPanel.add(RunButton);
            RunButton.setBounds(65,420,70,20);
                   
            SaveButton = new JButton();
            SaveButton.setFont(new Font("Bookman Old Style",1,13));
            SaveButton.setText("Save");
            innerPanel.add(SaveButton);
            SaveButton.setBounds(305,420,70,20);
          
            ResetButton = new JButton();
            ResetButton.setFont(new Font("Bookman Old Style",1,13));
            ResetButton.setText("Reset");
            innerPanel.add(ResetButton);
            ResetButton.setBounds(555,420,80,20);
            
            ExitButton = new JButton();
            ExitButton.setFont(new Font("Bookman Old Style",1,13));
            ExitButton.setText("Exit");
            innerPanel.add(ExitButton);
            ExitButton.setBounds(794,420,70,20);
            
            OutputWindow = new JTextArea();
            Font equalSpacedFont = new Font("Monospaced",Font.PLAIN,14);
            OutputWindow.setFont(equalSpacedFont);
            OutputWindow.setEditable(false);
            JScrollPane scrollPane = new JScrollPane(OutputWindow);
            scrollPane.setBounds(65,70,800,330);
            innerPanel.add(scrollPane);
    
        }
        
        private void setActionListener(ActionListener e){
         RunButton.addActionListener(this);  
         ExitButton.addActionListener(this);  
      }
      		
        public void actionPerformed(ActionEvent event) {
        	String arg = event.getActionCommand();
        			
        		if(arg.equals("Run"))
        		{
        			try
        			{
        				int plainTextLength = plainText.length;
        				String inputString = InputStringTextField.getText();
        				int inputStringLength = inputString.length();
        				char[] result = new char[inputStringLength];
        				//char currentSource = inputString.charAt(i);
        				
        			int [] cipherText = new int[plainText.length];
        		
        			System.out.print("\nPlaintext:\t ");
        			for(int i = 0; i < plainText.length; i++)
        			{
        			   int tmp = (int)plainText[i]-64;
        			   cipherText[i] = (tmp*tmp*tmp)%33;
        			   System.out.print("\t"+plainText[i]);	
        			}
        			System.out.print("\nCiphertext:\t");
        			for(int i = 0; i < cipherText.length; i++)
        			{
        				System.out.print("\t"+cipherText[i]);
        			}
        			  
        			}
        			catch (Exception e) {
        			   
        			}
        			
        		}
        		else if(arg.equals("Save")){
        			
        		}
        		else if(arg.equals("Reset")){
        			
        		}
        		else if(arg.equals("Exit"))
        		{
        		   System.exit(0);	
        		}
        }
        
         public static void main(String args[]) {
            SwingUtilities.invokeLater(new Runnable() {
                //@Override
                public void run() {
                    JFrame.setDefaultLookAndFeelDecorated(true);
                    NewClass5 nc5 = new NewClass5();
                    nc5.setVisible(true);
                    nc5.setActionListener(nc5);
                }
                
            }); 
                  
          }
    }

  2. #2
    Join Date
    Apr 2007
    Posts
    442

    Re: Problem With RSA Interface

    Correct me if I am wrong, but I dont see anything ever set to your plainText array. It is initialized once, and thats it. And while default value for char is the null character '\u0000', could it be that there simply just is nothing to print out.

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Problem With RSA Interface

    It would really help when trying to read your code if you followed the Java naming conventions (variable names start with a lowercase letter).

    Programs must be written for people to read, and only incidentally for machines to execute...
    H. Abelson & G. Sussman
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured