1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Encryption/ Decryption Help!!!

Discussion in 'Java' started by gonphishin7, Oct 6, 2010.

  1. gonphishin7

    gonphishin7 New Member

    Joined:
    Oct 6, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    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 = "0Okfohb4IQAJjgDNCe6HFtL7TndZVBYq2SpmrEa98KU3GW1cusRPzMlwX5xyiv";
    private static final String AUSTIN_KEY = "Ia6EJzc0nymk34LHY8gjldN7sBQqpMKZCof2iPbr9uGvtRxDFAU5WeS1wTVOXh";
    private static final String NATASHA_KEY = "sbzrfcX7x9wPFnELyGqNj8mlo1D3QgZTA0eaVuh5WBIktdpHR6MU42vOCSiYKJ";

    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!
     
  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    Code:
    .........
    private String key; 
    public SecretCode(String theKey) 
    { 
    [COLOR=Red]this.key=theKey;[/COLOR]
    } 
    public String encrypt(String clearText) 
    { 
    [COLOR=Red]String encryptedText="";
    .......
    return encryptedText;[/COLOR]
    } 
    public String decrypt(String cipherText) 
    { 
    [COLOR=Red]String decryptedText="";
    .......
    return decryptedText;[/COLOR]
    } 
    
    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.
     
  3. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    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
     

Share This Page