My teacher said that we needed to perform 3 mathematical actions on the chars so it works when I encrypt the textboxes but then it doesn't work when I decrypt them. I think it might be the order of my math operations in the decryption code?
For example:
I put into Encrypt: hello
Decrypts to : +*--.
Try to decrypt that back and it comes out to fcllo
public void actionPerformed(ActionEvent ae){
if(ae.getActionCommand().equals("Encrypt")){
if(!jtf.getText().equals("")){
String text=jtf.getText();
String ciph="";
for(int i=0; i<text.length(); i++) {
char c=text.charAt(i);
int j=(int) c;
j=((j/3)-5) + 14;
ciph+=(char) j;
}
jtf2.setText(ciph);
//jtf2.setText(Calculation.this.encrypt(jtf.getText()));
}
}
if(ae.getActionCommand().equals("Decrypt")){
if(!jtf2.getText().equals("")){
//undo using math operations
String text=jtf2.getText();
String undone="";
for(int i=0; i<text.length(); i++) {
char c=text.charAt(i);
int j=(int) c;
j=(j+5-14)*3;
undone+=(char) j;
}
jtf.setText(undone);
}
}
if(ae.getActionCommand().equals("Reset")){
jtf.setText("");
jtf2.setText("");
}
}
Thanks guys!