Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By berderder

Thread: Help creating an encryption/decryption program?

  1. #1
    berderder is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default Help creating an encryption/decryption program?

    Hi everyone,

    I am new to Java and am taking a class on it in school for my Computer Science degree. Compared to other courses, this class seems like it's been pretty intensive and I am struggling to keep up.

    For this week's assignment, I am supposed to create a java program that encrypt's a user's sentence, outputs the encrypted message, then decrypts the message, outputting the user's original message.

    This is what I have so far. It doesn't compile the last few lines since that is not correct Java syntax. I almost feel like I have to teach myself how to do this, because it is an online school, and I pretty much have to learn from the book, which has been pretty difficult. Ok. Enough complaining from me:


    Java Code:
    import java.util.Scanner;
    import java.io.*;
    
    public class Decrypter {
    
        public static void main(String[] args) {
            
            String sentence;
    
            final char REAL_ALPHA[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
                    + 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 
                    + 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            
            final char CODE_ALPHA[] = { 'z', 'y', 'x', 'w', 'v', 'u', 't', 's',
                    + 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 
                    + 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a' };
            
            Scanner scan = new Scanner(System.in);
            
            System.out.println("Please enter a sentence to be encrypted");
            sentence = scan.nextLine();
            System.out.println(sentence.replace( 'char REAL_ALPHA[]', 'codeAlpha[]'));

    So you can see I have "realAlpha" which are regular letters of the alphabet, and "codeAlpha" which are the letters I want to encrypt with. I want 'a' equal to 'z,' 'b' equal to 'y', 'c' equal to 'x' and so forth in that sort of reverse order, you know? So the word "apple" would encrypt into "zkkov."

    I am stuck as to how to replace the letters in this way. You can see I tried fumbling with sentence.replace to switch the letters out between the two arrays. Also, I only barely understand arrays.

    Anyhow, any guidance would be really great! Thank you.
    Last edited by berderder; 02-25-2015 at 04:28 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: Help creating an encryption/decryption program?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    berderder is offline Member
    Join Date
    Feb 2015
    Posts
    2
    Rep Power
    0

    Default Re: Help creating an encryption/decryption program?

    Quote Originally Posted by DarrylBurke View Post
    Fixed my post, sorry.
    Last edited by berderder; 02-25-2015 at 04:28 AM.
    DarrylBurke likes this.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Help creating an encryption/decryption program?

    Quote Originally Posted by berderder View Post
    Also, I only barely understand arrays.
    Well you'll need to work on that. You can't cut corners, if you need to do an assignment that heavily revolves around using arrays you'll need to properly understand them. Unfortunately we don't have a Matrix machine to upload the understanding to your brain, you'll need to sit down and work on it yourself. I hope you have a quality source of information called a "book" available to you.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Need some help with encryption decryption
    By JP34 in forum New To Java
    Replies: 1
    Last Post: 11-06-2012, 04:29 AM
  2. Encryption & Decryption
    By raj.mscking@gmail.com in forum New To Java
    Replies: 1
    Last Post: 02-01-2012, 02:21 PM
  3. Encryption and Decryption
    By jatinkansagara in forum Advanced Java
    Replies: 7
    Last Post: 06-27-2011, 03:08 PM
  4. Encryption/Decryption
    By Echilon in forum New To Java
    Replies: 2
    Last Post: 03-24-2009, 11:58 AM
  5. Encryption/Decryption Through AOP
    By SirRawlins in forum Advanced Java
    Replies: 0
    Last Post: 12-19-2007, 03:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •