Question

Java programming problem. I've managed to get through the basic level of encryption, but the advanced...

Java programming problem. I've managed to get through the basic level of encryption, but the advanced and military grade sections are beyond me. If someone can show me what the hell this code is supposed to look like I'd greatly appreciate it. In other words I need to write a code that can decrypt a string message by the following parameters.

Basic: Using Caesar Cipher with a static shift of 1-25. This is easy to decrypt as there are only 25 possibilities.

Advanced: They use two different shift values, one for even index characters, and another value for the odd characters.

Military Grade: They use a variable shift that starts at a certain value and increases by a second variable after encrypting each character. So the first character may be encrypted with a shift of 3, the second with a shift of 5 (3 + 2) and the third with 7 (3 + 2 + 2) and so on. We don’t have any clue of these numbers ahead of time

We also need to be able to receive a message and decrypt it. The Basic, Advanced, and military versions can print all possibilities to the screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, here are the 2 methods you will be needing. I have commented the code so that you can follow the code and the logic.

It would have been great if you could have shared some test cases so that I could have tested it. Hope you find this helpful. Let me know for any help with any other questions.

thanks 

=========================================================================

public class Encryption {

    // method takes in the encrypted text, the starting key and the increment value
    // mehtod returns the decrypted string
    public static String decryptUsingMilitaryRule(String encrypted, int startKey, int increment) {
       
        
        StringBuffer decrypted = new StringBuffer();

        for (int i = 0; i < encrypted.length(); i++) {
            char letter = (char) (encrypted.charAt(i) +startKey); // add startKey to the letter
            startKey+=increment; // add increment to the startKey for the next letter 
            decrypted.append(letter);// we will append the decrypted letter to the string
        }
        return decrypted.toString(); // return the decrypted string back
        
    }
    // method takes in the encrypted text, the odd position key value, the even position key value
    // method returns the decrypted string
    public static String decryptUsingAdvancedRule(String encrypted, int oddKey, int evenKey) {

        StringBuffer decrypted = new StringBuffer();

        for (int i = 0; i < encrypted.length(); i++) {
            char letter = encrypted.charAt(i);
            // when i is even we will add oddKey value to the letter
            // when i is odd we will add evenKey to the letter
            letter += i % 2 == 0 ? oddKey : evenKey;
            decrypted.append(letter); // we will append the decrypted letter to the string
        }
        return decrypted.toString();// return the decrypted string back
    }
}

=========================================================================

Add a comment
Know the answer?
Add Answer to:
Java programming problem. I've managed to get through the basic level of encryption, but the advanced...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I've managed to get through the basic level of encryption, but the advanced and military grade...

    I've managed to get through the basic level of encryption, but the advanced and military grade sections are beyond me. If someone can show me what the hell this code is supposed to look like I'd greatly appreciate it. In other words I need to write a code that can decrypt a string message by the following parameters. Basic: Using Caesar Cipher with a static shift of 1-25. This is easy to decrypt as there are only 25 possibilities. Advanced:...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • 1. Write a C++ program called Password that handles encrypting a password. 2. The program must...

    1. Write a C++ program called Password that handles encrypting a password. 2. The program must perform encryption as follows: a. main method i. Ask the user for a password. ii. Sends the password to a boolean function called isValidPassword to check validity. 1. Returns true if password is at least 8 characters long 2. Returns false if it is not at least 8 characters long iii. If isValidPassword functions returns false 1. Print the following error message “The password...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT