Question

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 SecurityApp. The second class will contain your static security methods. Name this class Securtiy. SecurityApp class This is the starting point for the application which is the only class to contain a main method. This driver class will be used to control the user interactions. The class should include the following: Follow the sample interaction on what to display for prompts, labels, messages and the flow for screen input and outputs. Uses the static methods in the Security class Five methods: A static method, main, that will: Initiate the program, manage the flow of execution. A static method, mainMenu, that will: Display a welcome message and a list of the available tools Prompt the user to select a tool A static method, passwordSelected: It will prompt the user to enter a phrase that is at least 8 characters long. If the user enters a phrase less than 8 characters long, it will ask them to try again. (It will keep asking them to enter the phrase until they enter a phrase that is at least 8 characters). Once we get that phrase, we will generate the strong password (using the Security class) and print it back to the user. A static method, encryptionSelected: It will prompt the user to select the encryption type(Caesar or vigener) It will ask the user to enter the phrase we need to encrypt. If the encryption needs a key, we will prompt the user to enter a key. It will encrypt the phrase (using the security class) and print it out. A static method, decryptionSelected: It will prompt the user to select the decryption type(Caesar or vigener). It will ask the user to enter the phrase we need to decrypt. If the decryption needs a key, we will prompt the user to enter a key. It will decrypt the phrase (using the security class) and print it out. Security class This class is the class that will contain all our security tools (methods). This class should include the following Methods: generatePassword: static method This method will take a phrase and will convert it into a strong password. It will make the first character an uppercase It will convert any S (upper or lower case) character in the phrase into $ It will convert any A (upper or lower case) character in the phrase into @ It will convert any O (upper or lower case) character in the phrase into 0 It will convert any E (upper or lower case) character in the phrase into 3 It will convert any space character in the phrase into an underscore If the previous character in the generated password was an upper case it will make the current character a lower case. If the previous character was a lower case it will make the current character an upper case. (alternate the case of the alphabetical characters) If the generated password doesn’t have any special characters (@,#,$,%,^,&,*,!) , we will add an ! at the end of the phrase. At the end of the phrase it will add the number of characters in the original phrase. caesarEncrypt: static method It will take a phrase and an offset and will encrypt the phrase using Caesar cipher. For simplicity we will convert the phrase into all uppercase regardless of how it was passed to the method. Also, we are assuming that the phrase is only made out of alphabetical characters The Caesar cipher encrypts a message by shifting each letter a certain number of characters (Shifts according to their position in the alphabet). For example, if the shift is 3, then “A” would become “D”, “B” would become “E” and so on. HINT: you can use casting to convert between integer numbers that represent Unicode values and characters. HINT: The Unicode Value of A is 65. This line prints out 65: System.out.println((int)'A'); The Caesar cipher “wraps around”, “Y” with a shift of 3 would become “B”, “Z” with a shift a 3 would become “C”. HINT: use mod to wrap around E(x)=(x+n)mod 26.gNuyhNFhX9ACwAAAABJRU5ErkJggg== x represents the Unicode value of the character and n represents the shift value. The message “ATTACKATDAWN”, with a shift a 5 is encrypted as “FYYFHPFYIFBS”. See more details here: https://en.wikipedia.org/wiki/Caesar_cipher vigenerEncrypt: static method It will take a phrase and a key and will encrypt the phrase using Vigenère cipher For simplicity we will convert the phrase into all uppercase regardless of how it was passed to the method. Also, we are assuming that the phrase is only made from alphabetical characters. The key should not contain more characters than the phrase and must check for this in your code The Vigenère cipher encrypts based on a keyword; to encrypt each letter of the message, shift each letter, as in the Caesar cipher, but by a different amount, depending on the current letter of the key. In the keyword, a letter “A” represents no shift at all, “B” a shift of one, and so on. Since the keyword is very likely shorter than the length of the entire message, the keyword is repeated as many times as necessary to encrypt the entire message. For example: Plaintext: ATTACKATDAWN Key: LEMON Repeated key: LEMONLEMONLE Ciphertext: LXFOPVEFRNHR As you can see, we are shifting each character in the phrase based on the character that is at the same position in the key In this example A (the first character in the phrase) was shifted L times (the first character in the key) which resulted in the cyphered result to be L, T was shifted E times which resulted in the cyphered result to be X You can think of it as adding the phrase and the key to get the result. A+L= L (0+11=11 L is the 12th character in the alphabet, but since we started with A at 0, we subtract 1) T+E=X (19+4=23 X is the 24th character in the alphabet, but since we started with A at 0, we subtract 1) HINT: EK(Mi) = (Mi+Ki) mod 2669fIQrDMfwHG0gx0uf1zv4AAAAASUVORK5CYII= Mi: the character of the phrase at location i Ki : the character of the key at location i For more details see: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher caesarDecrypt Static method It will take a phrase and a key and returns the decrypted phrase using the Caesar cipher. Use the same algorithm to decrypt as you did to encrypt, except that you will subtract where we previously added and add where we previously subtracted. vigenerDecrypt Static method It will take a phrase and a key and returns the decrypted phrase using the Vigenère cipher. Use the same algorithm to decrypt as you did to encrypt, except that you will subtract where we previously added and add where we previously subtracted.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Program

Security.java

/**
* Program to create different security generation functions impleentation
* @author deept
*
*/
public class Security {
   //Function to generate strong password
   public static String generatePassword(String phrase) {
       boolean isUpper=true,check=false;
       String pswd="";
       //First letter uppercase
       pswd+=Character.toUpperCase(phrase.charAt(0));
       //Loop through phrase
       for(int i=1;i<phrase.length();i++) {
           //Check each charcter match for particular charcters and replace
           if(Character.toUpperCase(phrase.charAt(i))=='S') {
               pswd+='$';
           }
           else if(Character.toUpperCase(phrase.charAt(i))=='A') {
               pswd+='@';
           }
           else if(Character.toUpperCase(phrase.charAt(i))=='O') {
               pswd+='0';
           }
           else if(Character.toUpperCase(phrase.charAt(i))=='E') {
               pswd+='3';
           }
           else if(phrase.charAt(i)==' ') {
               pswd+='_';
           }
           //Otherwise alternate upper,lower case
           else {
               if(isUpper) {
                   pswd+=Character.toLowerCase(phrase.charAt(i));
                   isUpper=false;
               }
               else {
                   pswd+=Character.toUpperCase(phrase.charAt(i));
                   isUpper=true;
               }
           }
       }
       //Check for special charcter
       for(int i=1;i<pswd.length();i++) {
           if(pswd.charAt(i)!='@'|| pswd.charAt(i)!='#' || pswd.charAt(i)!='$' || pswd.charAt(i)!='%'
           && pswd.charAt(i)!='^' || pswd.charAt(i)!='&' || pswd.charAt(i)!='*' || pswd.charAt(i)!='!') {
               check=true;
               break;
           }
       }
       if(!check) {
           pswd+='!';
       }
       //Add length
       pswd+=phrase.length();
       //Return strong password
       return pswd;
   }
   //Generate caesar encryption
   //By shifting letters by given shift key
   //Change phrase to uppercase
   public static String caesarEncrypt(String phrase,int key) {
       phrase=phrase.toUpperCase();
       String encrypt="";
       for(int i=0;i<phrase.length();i++) {
               encrypt+=(char)(((int)phrase.charAt(i) + key - 65) % 26 + 65);
          
       }
       return encrypt;
   }
   //Vigener encryption
   public static String vigenerEncrypt(String phrase,String key) {
       //Genrate equal length key
       int len = phrase.length();
        for (int i = 0; ; i++)
        {
            if (len == i)
                i = 0;
            if (key.length() == phrase.length())
                break;
            key+=(key.charAt(i));
        }
        key=key.toUpperCase();
        //Convert phrase to uppercase
       phrase=phrase.toUpperCase();
       String encrypt="";
       for(int i=0;i<phrase.length();i++) {
           encrypt+=(char)((char)('A'+(phrase.charAt(i) + key.charAt(i)) %26));
          
       }
       return encrypt;
   }
   //Generate caesar decryption
   //By shifting letters by given shift key
   //Change phrase to uppercase
   public static String caesarDecrypt(String phrase,int key) {
       phrase=phrase.toUpperCase();
       String encrypt="";
       for(int i=0;i<phrase.length();i++) {
               encrypt+=(char)(((int)phrase.charAt(i) - key + 65) % 26 + 65);
          
       }
       return encrypt;
   }
   //Vigener decryption
   public static String vigenerDecrypt(String phrase,String key) {
       int len = phrase.length();
        for (int i = 0; ; i++)
        {
            if (len == i)
                i = 0;
            if (key.length() == phrase.length())
                break;
            key+=(key.charAt(i));
        }
        key=key.toUpperCase();
       phrase=phrase.toUpperCase();
       String decrypt="";
       for(int i=0;i<phrase.length();i++) {
               decrypt+=(char)('A'+((phrase.charAt(i) - key.charAt(i) + 26) %26));
          
       }
       return decrypt;
   }
}

SecuritApp.java

import java.util.Scanner;
/**
* Program to create a security over data of a company
* This test class welcome user and provode different tools for security
* Give options of tools and call appropriate method to implemnt functionality
* @author deept
*
*/

public class SecurityApp {
//Main method initiate test
   public static void main(String[] args) {
       mainMenu();

   }
   //Method to display welcome message and available security tools to user
   public static void mainMenu() {
       Scanner sc=new Scanner(System.in);
       int opt;
       //Welcome message
       System.out.println("WELCOME TO SECURITY APP");
       //Display tools available
       do {
           System.out.println("\nTools Available:-");
           System.out.println("1. Strong password generation\n2. Encryption\n3. Decryption\n4. Exit");
           //Prompt for choice
           System.out.print("Enter your option(1-4): ");
           opt=sc.nextInt();
           //Error check
           while(opt<1 || opt>4) {
               System.out.print("Enter your option(1-4): ");
               opt=sc.nextInt();
           }
           //If password strength select
           if(opt==1) {
               passwordSelected();
           }
           //If encryption select
           else if(opt==2) {
               encryptionSelected();
           }
           //If decryption select
           else if(opt==3) {
               decryptionSelected();
           }
           System.out.println();
           //Loop repetiton check
       }while(opt!=4);
       //End
       System.out.println("\nEnding.....");
   }
   /**
   * If user select fo password strength
   * Prompt for phrase
   * Check minimum 8 charcter length
   * Otherwise repeatedly ask for phrase
   * Then call Strong pass word generator function and disply password
   */
   public static void passwordSelected() {
       Scanner sc=new Scanner(System.in);
       System.out.println("\nEnter password atleast 8 character length: ");
       String pswd=sc.nextLine();
       while(pswd.length()<8) {
           System.out.println("\nEnter password atleast 8 character length: ");
           pswd=sc.nextLine();
       }
       System.out.println("Strong Password = "+Security.generatePassword(pswd));
   }
   /**
   * Method for encryption
   * Give user 2 option for encryption
   * If caesar type the get phrase and shift key and call appropriate method to encrypt
   * If vigener type the get phrase and key and call appropriate method to encrypt
   */
   public static void encryptionSelected() {
       Scanner sc=new Scanner(System.in);
       System.out.println("\nSelect which encription you prefer:-\n1. Caesar\n2. vigener");
       System.out.print("Enter you selection(1-2): ");
       int opt=sc.nextInt();
       while(opt!=1 && opt!=2) {
           System.out.print("Enter you selection(1-2): ");
           opt=sc.nextInt();
       }
       sc.nextLine();
       if(opt==1) {
           System.out.print("Enter a phrase to encrypt using caesar method: ");
           String phrase= sc.nextLine();
           System.out.print("Enter shift key: ");
           int key=sc.nextInt();
           sc.nextLine();
           System.out.println("Encrypted phrase = "+Security.caesarEncrypt(phrase, key));
       }
       else if(opt==2) {
           System.out.print("Enter a phrase to encrypt using vigener method: ");
           String phrase= sc.nextLine();
           System.out.print("Enter key: ");
           String key=sc.nextLine();
           while(key.length()>phrase.length()) {
               System.out.print("Enter key: ");
               key=sc.nextLine();
           }
           System.out.println("Encrypted phrase = "+Security.vigenerEncrypt(phrase, key));
       }
   }
   /**
   * Method for decryption
   * Give user 2 option for decryption
   * If caesar type the get phrase and shift key and call appropriate method to decrypt
   * If vigener type the get phrase and key and call appropriate method to decrypt
   */
   public static void decryptionSelected() {
       Scanner sc=new Scanner(System.in);
       System.out.println("\nSelect which decryption you prefer:-\n1. Caesar\n2. vigener");
       System.out.print("Enter you selection(1-2): ");
       int opt=sc.nextInt();
       while(opt!=1 && opt!=2) {
           System.out.print("Enter you selection(1-2): ");
           opt=sc.nextInt();
       }
       sc.nextLine();
       if(opt==1) {
           System.out.print("Enter a phrase to encrypt using caesar method: ");
           String phrase= sc.nextLine();
           System.out.print("Enter shift key: ");
           int key=sc.nextInt();
           sc.nextLine();
           System.out.println("Encrypted phrase = "+Security.caesarDecrypt(phrase, key));
       }
       else if(opt==2) {
           System.out.print("Enter a phrase to encrypt using vigener method: ");
           String phrase= sc.nextLine();
           System.out.print("Enter key: ");
           String key=sc.nextLine();
           while(key.length()>phrase.length()) {
               System.out.print("Enter key: ");
               key=sc.nextLine();
           }
           System.out.println("Encrypted phrase = "+Security.vigenerDecrypt(phrase, key));
       }
   }
}

--------------------------------------------

Output

WELCOME TO SECURITY APP

Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit
Enter your option(1-4): 1

Enter password atleast 8 character length:
adolf hitler
Strong Password = Ad0Lf_HiTl3R12


Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit
Enter your option(1-4): 2

Select which encription you prefer:-
1. Caesar
2. vigener
Enter you selection(1-2): 1
Enter a phrase to encrypt using caesar method: wraparound
Enter shift key: 3
Encrypted phrase = ZUDSDURXQG


Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit
Enter your option(1-4): 2

Select which encription you prefer:-
1. Caesar
2. vigener
Enter you selection(1-2): 2
Enter a phrase to encrypt using vigener method: attackatdawn
Enter key: lemon
Encrypted phrase = LXFOPVEFRNHR


Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit
Enter your option(1-4): 3

Select which decryption you prefer:-
1. Caesar
2. vigener
Enter you selection(1-2): 1
Enter a phrase to encrypt using caesar method: hello
Enter shift key: 3
Encrypted phrase = EBIIL


Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit


Tools Available:-
1. Strong password generation
2. Encryption
3. Decryption
4. Exit
Enter your option(1-4): 4


Ending.....

Add a comment
Know the answer?
Add Answer to:
JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...
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
  • JAVA public static String generatePassword(String gp)        {            String password="";       ...

    JAVA public static String generatePassword(String gp)        {            String password="";            boolean b= false;            for (int i =0;i            {                char ch = gp.charAt(i);                if (i == 0)                {                    password += Character.toUpperCase(ch);                }                if (ch == 'S' || ch == 's')           ...

  • 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...

  • Security is an important feature of information systems. Often, text is encrypted before being sent, and...

    Security is an important feature of information systems. Often, text is encrypted before being sent, and then decrypted upon receipt. We want to build a class (or several classes) encapsulating the concept of encryption. You will need to test that class with a client program where the main method is located. For this project, encrypting consists of translating each character into another character. For instance, if we consider the English alphabet, including characters a through z, each character is randomly...

  • [Java] Create a class called FileExercises that contains the following method Method encrypt that does not...

    [Java] Create a class called FileExercises that contains the following method Method encrypt that does not return anything and takes a shift, input filename and output filename as arguments. It should read the input file as a text file and encrypt the content using a Caesar cypher with the shift provided. The resulting text should be placed in the output file specified. (If the output file already exists, replace the existing file with a new file that contains the required...

  • 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...

  • 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...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • 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...

  • Write the programming C please, not C++. The main function should be to find the offset...

    Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...

  • Computer Security Question about the Caesar Cipher: I also don't know this part of the problem...

    Computer Security Question about the Caesar Cipher: I also don't know this part of the problem Hello I am not sure how to figure this out Hello so for question 3, I think its +23 "the password is qqzzqqz" choose the correct multiple choice Question1 2 pts The following cipher text was produced by the Caesar Cipher: The Caesar cipher cryptanalysis technique from lecture calculates the most likely keys. When the technique is applied in this case, which of the...

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