I really need to know how you would code this or something similar in Java: http://www.cs.carleton.edu/faculty/adalal/teaching/f05/107/applets/ascii.html
Here is my attempt I've been at it the whole day (literally) and have had to search on how to do it on the internet because but because my Java knowledge not so great I can't understand any (At the start of today I didn't know anything to do with arrays) of it all I need is a little help or a push in the right direction.
[edit] Sorry forgot to point out the question. What I'm having trouble with is not converting and ciphering the PlainText but trying to convert a encoded message (ciphered with my program of course) to PlainText (i.e I can't just reverse it with the variable in my program I actually have to be able to read it and decode it)
private void encryptBUTActionPerformed(java.awt.event.ActionEvent evt)
{
int encryptLength=encryptTXT.getText().length();
int[] anArray=new int[encryptLength];
String key=encryptKey.getText();
if(key.isEmpty())
{
decryptTXT.setText(""+"INVALID KEY");
}
else
{
int key2=Integer.parseInt(key);
for(int i=0;i<encryptLength;i++)
{
int letter = encryptTXT.getText().toLowerCase().charAt(i);
System.out.println(letter);
System.out.println((char)letter);
int letterCiphered= (letter-key2);
anArray[i]=letterCiphered;
}
String output=(Arrays.toString(anArray));
decryptTXT.setText(output);
}
}
private void clearBUTActionPerformed(java.awt.event.ActionEvent evt)
{
mainPassword.setText("");
encryptTXT.setText("");
decryptTXT.setText("");
encryptKey.setText("");
decryptKey.setText("");
}
private void decryptBUTActionPerformed(java.awt.event.ActionEvent evt)
{
int textLength=decryptTXT.getText().length();
ArrayList list=new ArrayList();
String text=decryptTXT.getText();
int count=1;
String key=decryptKey.getText();
if(key.isEmpty())
{
encryptTXT.setText(""+"INVALID KEY");
}
else
{
int key2=Integer.parseInt(key);
for(int i=0;i<textLength;i++)
{
if(text.charAt(i)=='['||text.charAt(i)==','||text.charAt(i)==']')
{
count=count+1;
}
else if(count%2==0)
{
char number=text.charAt(i);
char number2=text.charAt(i+1);
int num=(int)number;
int num2=(int)number2;
int num3=num;
int num4=num3+num2-15;
int num5=num4+key2;
char letter2=(char)num5;
list.add(letter2);
count=count+1;
}
else
{
}
}
Object[] obj=(list.toArray());
String out=Arrays.toString(obj);
encryptTXT.setText(out);
}
}
Solved
This is how I encrypted my text:
int encryptLength=encryptTXT.getText().length();
String key=encryptKey.getText();
String text="";
if(key.isEmpty())
{
decryptTXT.setText(""+"INVALID KEY");
}
else
{
int key2=Integer.parseInt(key);
for(int i=0;i<encryptLength;i++)
{
int letter = encryptTXT.getText().toLowerCase().charAt(i);
int letterCiphered = (letter-key2);
text=text+letterCiphered+" ";
}
decryptTXT.setText(""+text);
}
This is how I decrypted my text
try
{
String text=decryptTXT.getText();
String key=decryptKey.getText();
String[] decrypt=text.split(" ");
String sentance="";
if(key.isEmpty())
{
encryptTXT.setText(""+"INVALID KEY");
}
else
{
int key2=Integer.parseInt(key);
for(int i=0;i<decrypt.length;i++)
{
int number=Integer.parseInt(decrypt[i]);
char letter=(char)(number+key2);
sentance=sentance+letter;
}
encryptTXT.setText(""+sentance);
}
}
catch(NumberFormatException e)
{
encryptTXT.setText(""+"Please enter a valid encoded message");
}
Thanks for all the help guys turned out a lot simpler than I thought.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With