6 Replies - 19245 Views - Last Post: 26 March 2010 - 07:06 AM Rate Topic: -----

#1 queen_night  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 07

java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 23 November 2007 - 03:32 PM

hi i really need your help i have an assignment to do Cryptography encryption/decryption using
• Rail Fence Cipher.
• Transposition Cipher ( column permutations)
• Vigenere Cipher

i write my code but i didn't work i don't know what is the wrong please help


import java.awt.FlowLayout;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.*;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.BorderFactory;
import java.awt.SystemColor;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup; 
import java.lang.*;

public class security extends JFrame implements ItemListener
,ActionListener
{
  int R_flag=0,T_flag=0,V_flag=0,en_flag=0,de_flag=0;
  private JButton Encryption = new JButton();
  private JButton Decryption = new JButton();
  private JRadioButton jRadioButton1 = 
new RadioButton("",true);
  private JLabel jLabel1 = new JLabel();
  private JRadioButton jRadioButton2 = 
new JRadioButton("",false);
  private JLabel jLabel5 = new JLabel();
  private JLabel jLabel6 = new JLabel();
  private JLabel jLabel7 = new JLabel();
  private JTextArea plainText = new JTextArea();
  private JTextField  key= new JTextField();
  private JTextField cipherText = new JTextField();
  private JRadioButton jRadioButton3 = 
new JRadioButton("",false);
  private Font f;
  private ButtonGroup radioGroup;
  
  String Keyword[][]={{"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"},

{"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","A"},

{"C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","A","B"},

{"D","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"},

{"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"},

{"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","E"},

{"G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F"},

{"H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V",
"W","X","Y","Z","A","B","C","D","E","F","G"},
							
{"I","J","K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","A","B","C","D","E","F","G","H"},
							
{"J","K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F","G","H","I"},
							
{"K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J"},
							
{"L","M","N","O","P","Q","R","S","T","U","V","W",
"X","Y","Z","A","B","C","D","E","F","G","H","I","J","K"},
						
{"M","N","O","P","Q","R","S","T","U","V","W","
X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L"},
							
{"N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"A","B","C","D","E","F","G","H","I","J","K","L","M"},
					
{"O","P","Q","R","S","T","U","V","W","X","Y",
"Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N"},
							
{"P","Q","R","S","T","U","V","W","X","Y","Z","A",
"B","C","D","E","F","G","H","I","J","K","L","M","N","O"},
							
{"Q","R","S","T","U","V","W","X","Y","Z","A",
"B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"},
							
{"R","S","T","U","V","W","X","Y","Z","A","B","C",
"D","E","F","G","H","I","J","K","L","M","N","O","P","Q"},
							
{"S","T","U","V","W","X","Y","Z","A","B","C",
"D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R"},
							
{"T","U","V","W","X","Y","Z","A","B","C","D","E","F",
"G","H","I","J","K","L","M","N","O","P","Q","R","S"},
							
{"U","V","W","X","Y","Z","A","B","C","D","E","F",
"G","H","I","J","K","L","M","N","O","P","Q","R","S","T"},
							
{"V","W","X","Y","Z","A","B","C","D","E","F","G",
"H","I","J","K","L","M","N","O","P","Q","R","S","T","U"},
							
{"W","X","Y","Z","A","B","C","D","E","F","G","H",
"I","J","K","L","M","N","O","P","Q","R","S","T","U","V"},
							
{"X","Y","Z","A","B","C","D","E","F","G","H","I",
"J","K","L","M","N","O","P","Q","R","S","T","U","V","W"},
							
{"Y","Z","A","B","C","D","E","F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S","T","U","V","W","X"},
							
{"Z","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"}
						 			  
 };

  public security()
  {
	try
	{
	  jbInit();
	}
	catch(Exception e)
	{
	  e.printStackTrace();
	}
setVisible(true);
  }

  private void jbInit() throws Exception
  {
	this.getContentPane().setLayout(null);
	this.setSize(new Dimension(597, 406));
	this.setTitle("Validate Digital Signiture");
	this.setForeground(SystemColor.inactiveCaptionText);
	this.setBackground(Color.white);
	Encryption.setText("Encryption");
	Encryption.setBounds(new Rectangle(165, 315, 115, 30));
	Encryption.setFont(new Font("Dialog", 1, 13));
	Encryption.setForeground(new Color(112, 13, 0));
	 Encryption.addActionListener(this);
	Decryption.setText("Decryption");
	Decryption.setBounds(new Rectangle(385, 315, 125, 30));
	Decryption.setFont(new Font("Dialog", 1, 13));
	Decryption.setForeground(new Color(112, 13, 12));
	 Decryption.addActionListener(this);
	jRadioButton1.setText("Rail Fence Cipher");
	jRadioButton1.setBounds(new Rectangle(205, 55, 125, 15));
	jRadioButton1.setForeground(SystemColor.desktop);
	jRadioButton1.setFont(new Font("Dialog", 1, 12));
	jLabel1.setText("choose the encryption algorithm");
	jLabel1.setBounds(new Rectangle(205, 25, 210, 15));
	jLabel1.setForeground(Color.magenta);
	jLabel1.setFont(new Font("Dialog", 1, 13));
	jRadioButton2.setText("Vigenere Cipher ");
	jRadioButton2.setBounds(new Rectangle(205, 120, 140, 15));
	jRadioButton2.setForeground(SystemColor.desktop);
	jRadioButton2.setFont(new Font("Dialog", 1, 12));
	jLabel5.setText("Plain text");
	jLabel5.setBounds(new Rectangle(195, 170, 70, 20));
	jLabel5.setForeground(Color.magenta);
	jLabel5.setFont(new Font("Dialog", 3, 13));
	jLabel6.setText("Key");
	jLabel6.setBounds(new Rectangle(205, 225, 35, 15));
	jLabel6.setForeground(Color.magenta);
	jLabel6.setFont(new Font("Dialog", 3, 13));
	jLabel7.setText("Ciphertext");
	jLabel7.setBounds(new Rectangle(185, 255, 65, 15));
	jLabel7.setForeground(Color.magenta);
	jLabel7.setFont(new Font("Dialog", 3, 13));
	plainText.setBounds(new Rectangle(270, 165, 200, 35));
	plainText.setSelectedTextColor(SystemColor.desktop);
  //  plainText.setForeground(SystemColor.desktop);
	plainText.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	key.setBounds(new Rectangle(270, 220, 200, 20));
	key.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	 //key.setForeground(SystemColor.desktop);
	cipherText.setBounds(new Rectangle(270, 255, 200, 20));
	cipherText.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	 //cipherText.setForeground(SystemColor.desktop);
	jRadioButton3.setText("Transposition Cipher ");
	jRadioButton3.setBounds(new Rectangle(205, 85, 170, 25));
	jRadioButton3.setFont(new Font("Dialog", 1, 12));
	jRadioButton3.setForeground(SystemColor.desktop);
	this.getContentPane().add(jRadioButton3, null);
	this.getContentPane().add(cipherText, null);
	this.getContentPane().add(key, null);
	this.getContentPane().add(plainText, null);
	this.getContentPane().add(jLabel7, null);
	this.getContentPane().add(jLabel6, null);
	this.getContentPane().add(jLabel5, null);
	this.getContentPane().add(jRadioButton2, null);
	this.getContentPane().add(jLabel1, null);
	this.getContentPane().add(jRadioButton1, null);
	this.getContentPane().add(Decryption, null);
	this.getContentPane().add(Encryption, null);
	 
	 f= new Font("Dialog",Font.BOLD,12);
	 
	 radioGroup= new ButtonGroup();
	 radioGroup.add(jRadioButton1);
	 radioGroup.add(jRadioButton2);
	 radioGroup.add(jRadioButton3);
	 
	 jRadioButton1.addItemListener(this);
	 jRadioButton2.addItemListener(this);
	 jRadioButton3.addItemListener(this);
	 }

public void itemStateChanged(ItemEvent re)
{
String s;
char h;
JRadioButton r;
r=(JRadioButton)re.getSource();
s=r+"";
System.out.println(""+s);
int index=s.indexOf("text=");
h=s.charAt(index+5);
System.out.println(""+h);
String et=plainText.getText();

if(h=='R'){
  R_flag=1;
  System.out.println("Rail cipher");
  }
  else if(h=='V'){
  V_flag=1;
   System.out.println("Vigener cipher");

}
else if(h=='T'){
T_flag=1; 
 System.out.println("Transposition cipher");
}
  }
  
   public void actionPerformed(ActionEvent e) 
	  {
		  JButton b;
		  String str,kt,pt,t="",tt="",st,stt;
		  char ch,c,cc;
		 pt=plainText.getText();
		 
		 kt=key.getText();
				 
		  
		  b=(JButton)e.getSource();
		  str=b+"";
		  ch=str.charAt(21);
		 
		  int res=str.indexOf("text=");
			ch=str.charAt(res+5);
		System.out.println(""+ch);
		 		  
		  switch (ch)	  
		 {

		   case 'E':
			  int plenght;
					 
			 en_flag=1;
		
		  if (R_flag==1&& en_flag==1){
		  char len=kt.charAt(0);
		  
				for(int i=0; i<pt.length()-1; i+=len){
				 c=pt.charAt(i);
				 st=c+"";
				   t.concat(st);
					}
				   for(int j=1; j<pt.length()-1;j+=len){
					cc=pt.charAt(j);
				   stt=cc+"";

					 t.concat(stt);
					 }
					 
					 cipherText.setText(t);	
		 }
				 
		 else if(T_flag==1 && en_flag==1){
		 int cn=1;String mtt="";
			for(int i=0; i<kt.length()-1;){
								
				  char no=kt.charAt(i);
					if(no>cn){
					 i++;
					  no=kt.charAt(i);
					  }
					else if (no ==i){
					 char me=  pt.charAt(no);
					 String mt=me+"";
					 mtt.concat(mt);
					 cn++;  
					 }
					 cipherText.setText(mtt);
					}
					}
		 		 
		 else if(V_flag==1&& en_flag==1){
			int count=0;
			char noo=kt.charAt(count);
			  String y;
			  y=noo+"";
		  while(kt.length()!=pt.length())
			   kt.concat(y);
				count++;
				}
		   for(int i=0; i<pt.length()-1; i++){
			  for(int j=0;j<kt.length()-1;j++){
				char p=pt.charAt(j);
				 char k= kt.charAt(i);
				 int np =pt.indexOf(p);
				 int nk =pt.indexOf(k);

				  for(int x=0; x<25;x++){
				   for (int z=0; z<25; z++){
					   while(z==np && x==nk)
						 cipherText.setText(Keyword[x][z]);
						 }
						 }
					}
		 }
		 

		break;
			 
			 case 'D':
			  de_flag=1;
			  
			  if(de_flag==1)
			  cipherText.setText(pt);
			  break;
		}
					
					
					  
}

 		 
	public static void main(String[] args)
  {
	security f2=new security();
  }
}


i hope u can help me please

This post has been edited by queen_night: 23 November 2007 - 03:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

#2 queen_night  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 07

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 24 November 2007 - 06:19 PM

View Postqueen_night, on 23 Nov, 2007 - 03:32 PM, said:

hi i really need your help i have an assignment to do Cryptography encryption/decryption using
• Rail Fence Cipher.
• Transposition Cipher ( column permutations)
• Vigenere Cipher

i write my code but i didn't work i don't know what is the wrong please help


import java.awt.FlowLayout;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.event.*;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.BorderFactory;
import java.awt.SystemColor;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup; 
import java.lang.*;

public class security extends JFrame implements ItemListener
,ActionListener
{
  int R_flag=0,T_flag=0,V_flag=0,en_flag=0,de_flag=0;
  private JButton Encryption = new JButton();
  private JButton Decryption = new JButton();
  private JRadioButton jRadioButton1 = 
new RadioButton("",true);
  private JLabel jLabel1 = new JLabel();
  private JRadioButton jRadioButton2 = 
new JRadioButton("",false);
  private JLabel jLabel5 = new JLabel();
  private JLabel jLabel6 = new JLabel();
  private JLabel jLabel7 = new JLabel();
  private JTextArea plainText = new JTextArea();
  private JTextField  key= new JTextField();
  private JTextField cipherText = new JTextField();
  private JRadioButton jRadioButton3 = 
new JRadioButton("",false);
  private Font f;
  private ButtonGroup radioGroup;
  
  String Keyword[][]={{"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"},

{"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","A"},

{"C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","A","B"},

{"D","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"},

{"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"},

{"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","E"},

{"G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F"},

{"H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V",
"W","X","Y","Z","A","B","C","D","E","F","G"},
							
{"I","J","K","L","M","N","O","P","Q","R","S","T",
"U","V","W","X","Y","Z","A","B","C","D","E","F","G","H"},
							
{"J","K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F","G","H","I"},
							
{"K","L","M","N","O","P","Q","R","S","T","U",
"V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J"},
							
{"L","M","N","O","P","Q","R","S","T","U","V","W",
"X","Y","Z","A","B","C","D","E","F","G","H","I","J","K"},
						
{"M","N","O","P","Q","R","S","T","U","V","W","
X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L"},
							
{"N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
"A","B","C","D","E","F","G","H","I","J","K","L","M"},
					
{"O","P","Q","R","S","T","U","V","W","X","Y",
"Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N"},
							
{"P","Q","R","S","T","U","V","W","X","Y","Z","A",
"B","C","D","E","F","G","H","I","J","K","L","M","N","O"},
							
{"Q","R","S","T","U","V","W","X","Y","Z","A",
"B","C","D","E","F","G","H","I","J","K","L","M","N","O","P"},
							
{"R","S","T","U","V","W","X","Y","Z","A","B","C",
"D","E","F","G","H","I","J","K","L","M","N","O","P","Q"},
							
{"S","T","U","V","W","X","Y","Z","A","B","C",
"D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R"},
							
{"T","U","V","W","X","Y","Z","A","B","C","D","E","F",
"G","H","I","J","K","L","M","N","O","P","Q","R","S"},
							
{"U","V","W","X","Y","Z","A","B","C","D","E","F",
"G","H","I","J","K","L","M","N","O","P","Q","R","S","T"},
							
{"V","W","X","Y","Z","A","B","C","D","E","F","G",
"H","I","J","K","L","M","N","O","P","Q","R","S","T","U"},
							
{"W","X","Y","Z","A","B","C","D","E","F","G","H",
"I","J","K","L","M","N","O","P","Q","R","S","T","U","V"},
							
{"X","Y","Z","A","B","C","D","E","F","G","H","I",
"J","K","L","M","N","O","P","Q","R","S","T","U","V","W"},
							
{"Y","Z","A","B","C","D","E","F","G","H","I","J","K","L",
"M","N","O","P","Q","R","S","T","U","V","W","X"},
							
{"Z","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"}
						 			  
 };

  public security()
  {
	try
	{
	  jbInit();
	}
	catch(Exception e)
	{
	  e.printStackTrace();
	}
setVisible(true);
  }

  private void jbInit() throws Exception
  {
	this.getContentPane().setLayout(null);
	this.setSize(new Dimension(597, 406));
	this.setTitle("Validate Digital Signiture");
	this.setForeground(SystemColor.inactiveCaptionText);
	this.setBackground(Color.white);
	Encryption.setText("Encryption");
	Encryption.setBounds(new Rectangle(165, 315, 115, 30));
	Encryption.setFont(new Font("Dialog", 1, 13));
	Encryption.setForeground(new Color(112, 13, 0));
	 Encryption.addActionListener(this);
	Decryption.setText("Decryption");
	Decryption.setBounds(new Rectangle(385, 315, 125, 30));
	Decryption.setFont(new Font("Dialog", 1, 13));
	Decryption.setForeground(new Color(112, 13, 12));
	 Decryption.addActionListener(this);
	jRadioButton1.setText("Rail Fence Cipher");
	jRadioButton1.setBounds(new Rectangle(205, 55, 125, 15));
	jRadioButton1.setForeground(SystemColor.desktop);
	jRadioButton1.setFont(new Font("Dialog", 1, 12));
	jLabel1.setText("choose the encryption algorithm");
	jLabel1.setBounds(new Rectangle(205, 25, 210, 15));
	jLabel1.setForeground(Color.magenta);
	jLabel1.setFont(new Font("Dialog", 1, 13));
	jRadioButton2.setText("Vigenere Cipher ");
	jRadioButton2.setBounds(new Rectangle(205, 120, 140, 15));
	jRadioButton2.setForeground(SystemColor.desktop);
	jRadioButton2.setFont(new Font("Dialog", 1, 12));
	jLabel5.setText("Plain text");
	jLabel5.setBounds(new Rectangle(195, 170, 70, 20));
	jLabel5.setForeground(Color.magenta);
	jLabel5.setFont(new Font("Dialog", 3, 13));
	jLabel6.setText("Key");
	jLabel6.setBounds(new Rectangle(205, 225, 35, 15));
	jLabel6.setForeground(Color.magenta);
	jLabel6.setFont(new Font("Dialog", 3, 13));
	jLabel7.setText("Ciphertext");
	jLabel7.setBounds(new Rectangle(185, 255, 65, 15));
	jLabel7.setForeground(Color.magenta);
	jLabel7.setFont(new Font("Dialog", 3, 13));
	plainText.setBounds(new Rectangle(270, 165, 200, 35));
	plainText.setSelectedTextColor(SystemColor.desktop);
  //  plainText.setForeground(SystemColor.desktop);
	plainText.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	key.setBounds(new Rectangle(270, 220, 200, 20));
	key.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	 //key.setForeground(SystemColor.desktop);
	cipherText.setBounds(new Rectangle(270, 255, 200, 20));
	cipherText.setBorder(BorderFactory.createLineBorder(Color.gray, 1));
	 //cipherText.setForeground(SystemColor.desktop);
	jRadioButton3.setText("Transposition Cipher ");
	jRadioButton3.setBounds(new Rectangle(205, 85, 170, 25));
	jRadioButton3.setFont(new Font("Dialog", 1, 12));
	jRadioButton3.setForeground(SystemColor.desktop);
	this.getContentPane().add(jRadioButton3, null);
	this.getContentPane().add(cipherText, null);
	this.getContentPane().add(key, null);
	this.getContentPane().add(plainText, null);
	this.getContentPane().add(jLabel7, null);
	this.getContentPane().add(jLabel6, null);
	this.getContentPane().add(jLabel5, null);
	this.getContentPane().add(jRadioButton2, null);
	this.getContentPane().add(jLabel1, null);
	this.getContentPane().add(jRadioButton1, null);
	this.getContentPane().add(Decryption, null);
	this.getContentPane().add(Encryption, null);
	 
	 f= new Font("Dialog",Font.BOLD,12);
	 
	 radioGroup= new ButtonGroup();
	 radioGroup.add(jRadioButton1);
	 radioGroup.add(jRadioButton2);
	 radioGroup.add(jRadioButton3);
	 
	 jRadioButton1.addItemListener(this);
	 jRadioButton2.addItemListener(this);
	 jRadioButton3.addItemListener(this);
	 }

public void itemStateChanged(ItemEvent re)
{
String s;
char h;
JRadioButton r;
r=(JRadioButton)re.getSource();
s=r+"";
System.out.println(""+s);
int index=s.indexOf("text=");
h=s.charAt(index+5);
System.out.println(""+h);
String et=plainText.getText();

if(h=='R'){
  R_flag=1;
  System.out.println("Rail cipher");
  }
  else if(h=='V'){
  V_flag=1;
   System.out.println("Vigener cipher");

}
else if(h=='T'){
T_flag=1; 
 System.out.println("Transposition cipher");
}
  }
  
   public void actionPerformed(ActionEvent e) 
	  {
		  JButton b;
		  String str,kt,pt,t="",tt="",st,stt;
		  char ch,c,cc;
		 pt=plainText.getText();
		 
		 kt=key.getText();
				 
		  
		  b=(JButton)e.getSource();
		  str=b+"";
		  ch=str.charAt(21);
		 
		  int res=str.indexOf("text=");
			ch=str.charAt(res+5);
		System.out.println(""+ch);
		 		  
		  switch (ch)	  
		 {

		   case 'E':
			  int plenght;
					 
			 en_flag=1;
		
		  if (R_flag==1&& en_flag==1){
		  char len=kt.charAt(0);
		  
				for(int i=0; i<pt.length()-1; i+=len){
				 c=pt.charAt(i);
				 st=c+"";
				   t.concat(st);
					}
				   for(int j=1; j<pt.length()-1;j+=len){
					cc=pt.charAt(j);
				   stt=cc+"";

					 t.concat(stt);
					 }
					 
					 cipherText.setText(t);	
		 }
				 
		 else if(T_flag==1 && en_flag==1){
		 int cn=1;String mtt="";
			for(int i=0; i<kt.length()-1;){
								
				  char no=kt.charAt(i);
					if(no>cn){
					 i++;
					  no=kt.charAt(i);
					  }
					else if (no ==i){
					 char me=  pt.charAt(no);
					 String mt=me+"";
					 mtt.concat(mt);
					 cn++;  
					 }
					 cipherText.setText(mtt);
					}
					}
		 		 
		 else if(V_flag==1&& en_flag==1){
			int count=0;
			char noo=kt.charAt(count);
			  String y;
			  y=noo+"";
		  while(kt.length()!=pt.length())
			   kt.concat(y);
				count++;
				}
		   for(int i=0; i<pt.length()-1; i++){
			  for(int j=0;j<kt.length()-1;j++){
				char p=pt.charAt(j);
				 char k= kt.charAt(i);
				 int np =pt.indexOf(p);
				 int nk =pt.indexOf(k);

				  for(int x=0; x<25;x++){
				   for (int z=0; z<25; z++){
					   while(z==np && x==nk)
						 cipherText.setText(Keyword[x][z]);
						 }
						 }
					}
		 }
		 

		break;
			 
			 case 'D':
			  de_flag=1;
			  
			  if(de_flag==1)
			  cipherText.setText(pt);
			  break;
		}
					
					
					  
}

 		 
	public static void main(String[] args)
  {
	security f2=new security();
  }
}


i hope u can help me please



please if anyone can help i realy need ur help please
even just simple information that shows me what is the wrong coz there is no compiler error
the inteface is good but if i try to do one of the cipher it didn' work
can i know why ?

please and i appreciate ur help

This post has been edited by queen_night: 24 November 2007 - 06:21 PM

Was This Post Helpful? 0
  • +
  • -

#3 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 25 November 2007 - 10:22 AM

Could you specify what does

Quote

it didn't work
mean?
Do you have incorrect results, or nothing happens?
Anyway in both cases debugging can help a lot. If you use an IDE, then try it's debug mdoe, where you can place break points onto lines, and when the program gets there it will stop, and you'll see the current values of your variables, which will show you if you have some problem with your logic, or maybe the program does not even get to the line you expected.
If you don't use an IDE, you can still debug your code by putting plenty of System.out.println commands into it which should display similar information to a debugger: some information where the execution is at the given moment, and the value of variables which might be interesting to you.
Was This Post Helpful? 0
  • +
  • -

#4 queen_night  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 07

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 27 November 2007 - 05:10 PM

hi

Thank u for ur replay

The problem is when i try to set the text in the cipher text either set single character or nothing at all so i don't know is it in the way that i set it of what

for example in the Reail fence cipher i use concat, so it will not replace the privous one withe next

if i enter the plain text and key depending on the key the cipher text will write the plaintext
for example:

plainText: play in the park is fun
key :2

the cipher text should be
cipherText:paiteaksulynhprifn
so i put for loop from 0 to plan text length and increase by the number of key

String s,pt,t="",st;
char key=kt.charAt(0),ch;
for(int i=0;i<pt.length();i+=key){
ch= pt.charAt(i);
s=ch+"";//convert to string
t.concat(s);
}
//the athor for loop from 1 to plan text length and increase by the number of key
for(int j=1; j<pt.length()j+=key){
ch= pt.charAt(j);
st=ch+"";
t.concat(st);
}

cipherText.setText(t);

what is wrong here i donn't know but i think it is the way that i set the string to the cipherText
do i have to put loop so i set the text to it or the concat dosn't work and replace the character every time and i have just singl character

Thank u
queen_night
Was This Post Helpful? 0
  • +
  • -

#5 mp112849  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-November 07

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 29 November 2007 - 06:23 AM

Are you still looking for a solution to your problem? :^:

View Postqueen_night, on 27 Nov, 2007 - 05:10 PM, said:

hi

Thank u for ur replay

The problem is when i try to set the text in the cipher text either set single character or nothing at all so i don't know is it in the way that i set it of what

for example in the Reail fence cipher i use concat, so it will not replace the privous one withe next

if i enter the plain text and key depending on the key the cipher text will write the plaintext
for example:

plainText: play in the park is fun
key :2

the cipher text should be
cipherText:paiteaksulynhprifn
so i put for loop from 0 to plan text length and increase by the number of key

String s,pt,t="",st;
char key=kt.charAt(0),ch;
for(int i=0;i<pt.length();i+=key){
ch= pt.charAt(i);
s=ch+"";//convert to string
t.concat(s);
}
//the athor for loop from 1 to plan text length and increase by the number of key
for(int j=1; j<pt.length()j+=key){
ch= pt.charAt(j);
st=ch+"";
t.concat(st);
}

cipherText.setText(t);

what is wrong here i donn't know but i think it is the way that i set the string to the cipherText
do i have to put loop so i set the text to it or the concat dosn't work and replace the character every time and i have just singl character

Thank u
queen_night

Was This Post Helpful? 0
  • +
  • -

#6 queen_night  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-November 07

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 29 November 2007 - 05:15 PM

hi

yes i really want to know what is the problem on my code and i am still looking for a solution

Thank u for ur asking and i hope that u can help me or anyone know what is the solution.

Thank u
queen_night
Was This Post Helpful? 0
  • +
  • -

#7 Guest_nityashree*


Reputation:

Re: java+encryption/decryption(Rail Fence Cipher,Transposition cipher(colu

Posted 26 March 2010 - 07:06 AM

coloumnnar cipher program code in java
Was This Post Helpful? 0

Page 1 of 1