Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: need help on this pls

  1. #1
    d3sm0nd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default need help on this pls

    SUBSTITUTION ENCRYPTION
    This type of encryption works by substituting the first few characters for the key typed in by user. For example, if the key is WREAKHAVOC, the substitution table would look like:
    KEY: WREAKHAVOC
    Java Code:
    A	B	C	D	E	F	G	H	I	J
    W	R	E	A	K	H	V	O	C	A
    K	L	M	N	O	P	Q	R	S	T
    B	D	F	G	I	J	L	M	N	P
    U	V	W	X	Y	Z				
    Q	S	T	U	X	Z

    Notes:
    • In the key, WREAKHAVOC, the letter A appears twice, but only one substitution will be used, in this case D
    • Encryption:
    o Plain Text: ATTACK AT DAWN
    o Cipher Text: WPPWEK WP AWTG
    • Decryption:
    o Cipher Text: HDKK WP IGEK
    o Plain Text: FLEE AT ONCE
    Last edited by d3sm0nd; 06-21-2012 at 07:58 AM.

  2. #2
    d3sm0nd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: need help on this pls

    do u guys understand what it is about?

  3. #3
    Ruben is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: need help on this pls

    I had a class on encrytping and decrypting messages and yes, i know what this is about.

    But what is the problem ?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: need help on this pls

    Is this the same as at javaprogrammingforms?

    @OP: It might sound harsh but if you are totally baffled you should think about approaching your teacher. You can get plenty of help here, but it's going to be on the basis of what *you* understand and explain the problem to be.

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: need help on this pls

    I think I understand what the requirement is but if I do then the example code above is incorrect. With letter sustitution all letters of the alphabet have a one to one mapping with another letter. After substition 'A' is mapped to both 'D' and 'J' whilst 'Y' maps to nothing. I'm assuming this is the case but I would like confirmation before going any further.

    Regards.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: need help on this pls

    With letter sustitution all letters of the alphabet have a one to one mapping with another letter. After substition 'A' is mapped to both 'D' and 'J' whilst 'Y' maps to nothing.
    Yes there seems to be a problem. Every letter must appear exactly once in rows 1/3/5 and exactly once in rows 2/4/6. Personally I think they screwed up with the last 'A' in line 2 because 'A' has already been used. I would have made it 'B' and adjusted the other letters on lines 4 and 6.

    (I also find it confusing to talk about 'A' mapping or being substituted for 'D', but that's how the example is worded. Notice that's for the decryption).

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: need help on this pls

    It'd be easier to read if there were only two rows. You'd quickly see one row was the letters A to Z and the second row was the key with duplicates removed followed by the remaining letters in the alphabet that were not in the key.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: need help on this pls

    Please go through the Forum Rules -- particularly the third paragraph.

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

  9. #9
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default Re: need help on this pls

    Quote Originally Posted by pbrockway2 View Post
    (I also find it confusing to talk about 'A' mapping or being substituted for 'D', but that's how the example is worded. Notice that's for the decryption).
    Cheers for the input. I got a little carried away with the response and didn't explain it quite as well as I could have.

    Regards.

  10. #10
    d3sm0nd is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: need help on this pls

    alright this is the code my member send it to me...do u guys have any idea how can we make it more Object oriented,the lecturer will not like if we only used one class

    Java Code:
    package substitutionencryption;
    
    import java.util.Scanner;
    
    public class SubstitutionDemo
    {
    public static void main(String[] args)
    {
    
    Scanner bb = new Scanner(System.in);
    System.out.println("Please enter the key.");
    String key = bb.nextLine();
    System.out.println("If you would like to encrypt, type [E]."
    + " If you would like to decrypt, type [D]");
    String answer = bb.nextLine();
    char choice = answer.charAt(0);
    
    if (choice == 'e' || choice == 'E'){
    System.out.println("Please enter the plain text.");
    String plaintext = bb.nextLine();
    encryption(key, plaintext);
    }
    else
    System.out.println("Please enter the cipher text.");
    String ciphertext = bb.nextLine();
    decryption(key, ciphertext);
    }
    
    public static void encryption(String ps, String pl){
    
    char [] letters = {'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'};
    String password = ps;
    String plaintext = pl;
    password = password + "abcdefghijklmnopqrstuvwxyz";
    int kk = password.length();
    char [] userEntered = password.toCharArray();
    char [] userFixed = new char [kk];
    char [] plainx = plaintext.toCharArray();
    
    int l = 0;
    
    for(int i = 0; i < userEntered.length; i++){
    char x = userEntered[i];
    if (Character.isLetter(x)) {
    boolean Insert = true;
    for(int j = 0; j < userEntered.length; j++){
    if (userFixed[j] == x)
    Insert=false;
    }
    if (Insert) {
    userFixed[l] = x;
    l++;
    }
    }
    }
    
    for(int i = 0; i < plainx.length; i++){
    for(int x = 0; x < letters.length; x++){
    if (plainx[i] == letters[x])
    System.out.print(userFixed[x]);
    }
    }
    }
    
    public static void decryption(String la, String pn) {
    char [] letters = {'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'};
    String password = la;
    String cipher = pn;
    password = password + "abcdefghijklmnopqrstuvwxyz";
    int kk = password.length();
    char [] userEntered = password.toCharArray();
    char [] userFixed = new char [kk];
    char [] cipherx = cipher.toCharArray();
    
    int l = 0;
    for(int i = 0; i < userEntered.length; i++){
    char x = userEntered[i];
    if (Character.isLetter(x)) {
    boolean Insert = true;
    for(int j = 0; j < userEntered.length; j++){
    if (userFixed[j] == x)
    Insert=false;
    }
    if (Insert) {
    userFixed[l] = x;
    l++;
    }
    }
    }
    
    for(int i = 0; i < cipherx.length; i++){
    for(int x = 0; x < userFixed.length; x++){
    if (cipherx[i] == userFixed[x])
    System.out.print(letters[x]);
    }
    }
    }
    }

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: need help on this pls

    Edit and format the code.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,864
    Rep Power
    8

    Default Re: need help on this pls

    I received a private message from the OP asking that I "do this question" for him.

    That is absolutely not how this works. Don't contact members asking that they "do this question for you".

    I recommend you read the link in my signature on asking questions the smart way before you post again.
    Fubarable likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Posting Permissions

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