sajjads programming blog

publish my programming stuffs on web

Sunday, August 13, 2006

caeser cypher java applet

################ created by sajjad##########################################
import java .applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class caeser extends Applet implements ActionListener
{
TextField plain,cypher;
Button enc, dec,flp,flc;
Label l1,l2,l3;
String str1,str2;

char ch[]=new char[100];
//={'a','s','b','s','d','r','e','d','w','3','4'};

public void init() {
setLayout(new FlowLayout(4));
setBackground(Color.ORANGE);
l3= new Label("caeser cypher ");
add(l3);
l1= new Label("plain text");
add(l1);
plain= new TextField("Enter plain text", 20);
add(plain);
enc= new Button("encrypt");
add(enc);
enc.addActionListener(this);

dec= new Button("decrypt");
add(dec);
dec.addActionListener(this);

flp=new Button("Flush plain");
add(flp);
flp.addActionListener(this);

flc=new Button("Flush cypher");
add(flc);
flc.addActionListener(this);

l2= new Label("cypher text");
add(l2);
cypher= new TextField("decrypted text",20);
add(cypher);


// TODO start asynchronous download of heavy resources
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==enc)
{
str1= new String(plain.getText());
for(int i=0;i {
ch[i]=str1.charAt(i);
for(int j=0;j<5;j++)
ch[i]++ ;
}
String str2= new String(ch,0,str1.length());
cypher.setText(str2);
}
if(e.getSource()==dec)
{
str1= new String(cypher.getText());
for(int i=0;i {
ch[i]=str1.charAt(i);
for(int j=0;j<5;j++)
ch[i]-- ;
}
String str2= new String(ch,0,str1.length());
plain.setText(str2);
}
if(e.getSource()==flp)
plain.setText("");

if(e.getSource()==flc)
cypher.setText("");
}
}

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home