Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Encryption/ Decryption Help!!! (http://www.go4expert.com/forums/encryption-decryption-help-t23503/)

gonphishin7 6Oct2010 23:16

Encryption/ Decryption Help!!!
 
I am having a LOT of trouble trying to do this assignment for my computer science class. I am not sure how to do this assignment using two classes. Any help would be greatly appreciated. Thank you!

I have to write two classes. (SecretCode and CodeTester)

The SecretCode class should use this template:

public class SecretCode
{
public static final String ORDERED="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno pqrstuvwxyz0123456789";
private String key;
public SecretCode(String theKey)
{
}
public String encrypt(String clearText)
{
}
public String decrypt(String cipherText)
{
}
}

The CodeTester should contain the secret keys, like this:
public class CodeTester
{
private static final String JAMES_KEY = "0Okfohb4IQAJjgDNCe6HFtL7TndZVBYq2SpmrEa98KU3GW1cu sRPzMlwX5xyiv";
private static final String AUSTIN_KEY = "Ia6EJzc0nymk34LHY8gjldN7sBQqpMKZCof2iPbr9uGvtRxDF AU5WeS1wTVOXh";
private static final String NATASHA_KEY = "sbzrfcX7x9wPFnELyGqNj8mlo1D3QgZTA0eaVuh5WBIktdpHR 6MU42vOCSiYKJ";

To encrypt, you have to encrypt each letter separately from the ORDERED string. For example, “J” is the 9th character in the ORDERED string (remember we start at zero), and the 9th character in James’ key is Q.

To decrypt a message: reverse the process. Find each character in the key, and select the
corresponding character from the ORDERED string.

The CodeTester class should handle all user interaction, using JOptionPane for both input and
output (no System.out.print or println, or Scanner).

I want to be able to ask whether to encrypt or decrypt.... if its encrypt, then i want to show the message to each of the spies (James, Austin, and Natasha). If decrypt, then just reverse the process and ask who it was from.

The keys appear in the CodeTester class, and should be given to the constructor of the SecretCode
class. The SecretCode class can then encrypt or decrypt messages based on this key.

The SecretCode class should do no input or output, except for debugging.

If you can help at all i would really appreciate it...im struggling a lot on this. Thanks!

virxen 7Oct2010 02:50

Re: Encryption/ Decryption Help!!!
 
Code:

.........
private String key;
public SecretCode(String theKey)
{
this.key=theKey;
}
public String encrypt(String clearText)
{
String encryptedText="";
.......
return encryptedText;

}
public String decrypt(String cipherText)
{
String decryptedText="";
.......
return decryptedText;

}

this is a small help to help you start.

now from what i understood from this you want to do:
first of all Encrypt
==================
you have a string-->clearText
you have a key-->key
you have the ORDERED Key.

you must process each letter of clearText (for loop)
find its order inside ORDERED string (for loop) and get the char at the same position from
the key and replace the unEncrypted char with the encrypted one,
finally return encrypted string.

now with this in mind send your new code in order to help you.

ManzZup 16Oct2010 11:29

Re: Encryption/ Decryption Help!!!
 
yes, you need to loop around the characters
make use of the charAt so you can extract the integer at the place, then use the same to replace the character


All times are GMT +5.5. The time now is 09:51.