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 2 of 2

Thread: Caeser Cipher Decryption with two keys

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Caeser Cipher Decryption with two keys

    You should start by writing the decryption method explained in the lesson that decrypts a message that was encrypted with one key, using statistical letter frequencies of English text. Then you will add code to be able to decrypt a message that was encrypted with two keys, using ideas from the single key decryption method and the encryption with two keys method from the program you wrote in the last lesson.

    Idea for two keys decrypt method. Recall that in using two keys, key1 and key2, key1 was used to encrypt every other character, starting with the first, of the String, and key2 was used to encrypt every other character, starting with the second. In order to decrypt the encrypted String, it may be easier to split the String into two Strings, one String of all the letters encrypted with key1 and one String of all the letters encrypted with key2. Then use the algorithm from the lesson to determine the key for each String, and then use those keys and the two key encryption method to decrypt the original encrypted message.

    For example, if the encrypted message was “Qbkm Zgis”, then you would split this String into two Strings: “Qk gs”, representing the characters in the odd number positions and “bmZi” representing the characters in the even number positions. Then you would get the key for each half String and use the two key encryption method to find the message. Note this example is so small it likely won’t find the keys, but it illustrates how to take the Strings apart.

    A sample file to test your program that is small with lots of e’s is called wordsLotsOfEs.txt and shown here:

    Just a test string with lots of eeeeeeeeeeeeeeeees

    And the same file encrypted using keys 23 and 2 is called wordsLotsOfEsEncrypted.txt and is shown here:

    Gwpv c vbuq pvokki yfve iqqu qc bgbgbgbgbgbgbgbgbu

    Specifically, you should do the following.

    Complete the decryption method shown in the lesson by creating a CaesarBreaker class with the methods countLetters, maxIndex, and decrypt. Recall that the decrypt method creates a CaesarCipher object in order to use the encrypt method you wrote for the last lesson. Make sure that your CaesarCipher class is in the same folder as CaesarBreaker! You may want to use the following code as part of your decrypt method.
    
    Write a testDecrypt method in the CaesarBreaker class that prints the decrypted message, and make sure it works for encrypted messages that were encrypted with one key.
    Write the method halfOfString in the CaesarBreaker class that has two parameters, a String parameter named message and an int parameter named start. This method should return a new String that is every other character from message starting with the start position. For example, the call halfOfString(“Qbkm Zgis”, 0) returns the String “Qk gs” and the call halfOfString(“Qbkm Zgis”, 1) returns the String “bmZi”. Be sure to test this method with a small example.
    Write the method getKey in the CaesarBreaker class that has one parameter, a String s. This method should call countLetters to get an array of the letter frequencies in String s and then use maxIndex to calculate the index of the largest letter frequency, which is the location of the encrypted letter ‘e’, which leads to the key, which is returned.
    Write the method decryptTwoKeys in the CaesarBreaker class that has one parameter, a String parameter named encrypted that represents a String that was encrypted with the two key algorithm discussed in the previous lesson. This method attempts to determine the two keys used to encrypt the message, prints the two keys, and then returns the decrypted String with those two keys. More specifically, this method should:
    - Calculate a String of every other character starting with the first character of the encrypted String by calling halfOfString.

    - Calculate a String of every other character starting with the second character of the encrypted String.

    - Then calculate the key used to encrypt each half String.

    - You should print the two keys found.

    - Calculate and return the decrypted String using the encryptTwoKeys method from your CaesarCipher class, again making sure it is in the same folder as your CaesarBreaker class.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Caeser Cipher Decryption with two keys

    What have you tried?
    Be sure to wrap all posted code in code tags > http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Issue with Caeser Shift, Transpose, and Reverser
    By biwot in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2014, 06:31 AM
  2. Replies: 1
    Last Post: May 22nd, 2013, 07:48 PM
  3. Cipher Client/Server Encryption/Decryption Program - Please Help
    By drwatson in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 15th, 2013, 11:13 AM
  4. Replies: 0
    Last Post: March 28th, 2013, 06:27 AM
  5. Decryption problem
    By hjen in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 20th, 2010, 02:58 AM