Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: anyone can help me to solve this?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb anyone can help me to solve this?

    import java.util.Scanner;
    public class Substitution
    {
    public static void main(String[] args){

    Scanner bb = new Scanner (System.in);
    String [] 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"};

    char [] user = new char[27];

    System.out.println("Please enter the plain text.");
    String text = bb.nextLine();




    for (int i = 0; i < text.length(); i++)
    {
    user[i] = text.charAt(i);
    for (int x = 0; user[i] != user[x]; x++)
    user[i] = text.charAt(i);
    }
    }
    }


  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    the two loops at the end....Im trying to figure out how to check the array for repeated letters. For example: If the use enters bilal. Only "bila" is supposed to go in the array I made. You can't have repeated letters there.Any idea how to solve it?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    Only "bila" is supposed to go in the array
    Can you describer how the program is supposed to work? List the steps the code should do to solve the problem.
    What is the name of the array you are working with? How are the values put in the array?
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    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
    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; June 16th, 2012 at 08:52 AM.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    Quote Originally Posted by Norm View Post
    Can you describer how the program is supposed to work? List the steps the code should do to solve the problem.
    What is the name of the array you are working with? How are the values put in the array?
    just posted the question...do you understand it?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    These look like two different problems. Which one are you working on?

    Is this a question about creating an algorithm
    or about how to code an algorithm in java?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    Quote Originally Posted by Norm View Post
    These look like two different problems. Which one are you working on?

    Is this a question about creating an algorithm
    or about how to code an algorithm in java?
    seriously?that means what I'm doing right now nt related to the question at all?sorry me just beginner in java still gt alot need to learn...u gt any idea on the question i posted?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    Can you be more specific? Post #1 is about removing duplicates. Post#2 is about encoding.

    Are you looking for algorithms to solve these problems
    or do you have the algorithm and need help writing a java program for the algorithm?

    If you have code you are having problems with, post the code (please wrap it in code tags) and ask any questions.
    Wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting
    Last edited by Norm; June 16th, 2012 at 11:01 AM.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    I need help writing a java program for the algorithm based on the question i posted #4...totally out of clue

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    post #4 is not an algorithm for solving the problem. It is a partial statement of the problem with an example.
    An algorithm is a list of steps that will solve the problem. You have not provided that yet.

    In post#4 there is a table with some lines of letters:
    A	B	C	D	E	F	G	H	I	J
    W	R	E	A	K	H	V	O	C	A   <<< From key
    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	                            <<<????
    The second line looks like it was created from the key. What are the rules for creating this line from the key?
    What are the rules for creating the fourth and sixth lines?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    This version of Rail Fence Encryption depends on the number of rails, where the plain text/cipher text will be used to populate the rails in fixed direction (either top-down or bottom-up). The text that is used for encryption/decryption should be a multiple of ‘rails’. Padding may be used to achieve that. The encrypted text can be read off the table in a similar direction (either top-down or bottom-up), left to right
    Example:
    Method: TOP DOWN with 4 Rails
    o Encryption:
    o Plain Text: ATTACK AT DAWN (Populated top-down, left-right)
    o Cipher Text: ACTWTK*NT*D*AAA* (Read left-right, top-down)
    A	C	T	W
    T	K	*	N
    T	*	D	*
    A	A	A	*


    o Decryption:
    o Cipher Text: F*O*ALANPSETCLEE*EE* (Populated left-right, top-down)
    o Plain Text: FLEE AT ONCE PLEASE! (Read top-down, left-right)
    F	*	O	*	A
     L	A	N	P	S
    E	T	C	L	E
    E	*	E	E	*

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    Have you created a design in pseudo code for the problem? A list of the steps the program needs to do to solve it.



    Also posted at http://www.java-forums.org/new-java/...-help-pls.html
    Last edited by Norm; June 21st, 2012 at 02:50 PM. Reason: Added link
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: anyone can help me to solve this?

    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..and how to encrypt things with space. For example "the world". Right now the program can only encrypt 1 word.

    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]);
    }
    }
    }
    }
    Last edited by d3sm0nd; June 27th, 2012 at 03:46 AM.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: anyone can help me to solve this?

    Please edit the code and add indentations to show the nesting level. This unformatted, (all statements in starting in column one) is hard to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help to solve this problem
    By ahanf in forum Object Oriented Programming
    Replies: 1
    Last Post: June 3rd, 2012, 05:00 AM
  2. Please can anyone help solve this ?
    By jennyb in forum Java Theory & Questions
    Replies: 1
    Last Post: January 6th, 2012, 09:45 PM
  3. using while to solve this question !
    By deathpain in forum Java Theory & Questions
    Replies: 2
    Last Post: November 19th, 2011, 04:46 PM
  4. Solve Them Please
    By omath in forum Java Theory & Questions
    Replies: 1
    Last Post: December 25th, 2010, 04:26 PM
  5. solve it plz
    By tillu in forum Java Theory & Questions
    Replies: 4
    Last Post: December 17th, 2010, 01:45 PM