Question

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 representing the password key

                                             ii.     encryptedPassword – String representing the encrypted password.

b.     Constructors

                                               i.     Default (no parameter) Constructor – sets all instance variables to a default value

                                             ii.     Parameterized Constructor

1.     Takes in a key and the clear text password as parameters

2.     Set the instance variable key from the associated parameter

3.     Call the encrypt method to encrypt the clear text password.

c.     Methods

                                               i.     encrypt

1.     Takes in a clear text password as a parameter

2.     Uses the instance variable key to encrypt the password.

3.     Stores the encrypted password in the encryptedPassword instance variable

                                             ii.     isValidPassword

1.     Take in a clear text password as a parameter

2.     Compares the clear text password with the stored encryptedPassword (Hint you must first encrypt the clear text password parameter)

3.     Returns true if the passwords match, false if they don’t.

                                           iii.     getEncryptedPassword – returns the encrypted password.

                                            iv.     setPassword – takes in a new clear text password and a new key and generates a new encrypted password by calling the encrypt method.

                                             v.     getKey – returns the instance variable: key

                                            vi.     toString – returns a nicely formatted String in the form below use the getKey and getEncryptedPassword method to retrieve those values, do not use the instance variable directly.

   The encrypted password is UeiY3$2Spw. The used to generate this password is 3.

Encryption

- key : int

- encryptedPassword : String

+ Encryption()

+ Encryption (int, String)

+ encrypt(String)

+ isValidPassword(String) : boolean

+ getEncryptedPassword() : String

+ setPassword(int, String)

+ getKey() : int

+ toString(): String

EncrytionTester Class

a.     This class is very similar to Project 3 however there is some additional error handling and the use of the Encryption class.

b.     Ask the user for a password

c.     Check to ensure the password is a least 8 characters long. If it is not, then print the following error message and ask the user to enter a password that is at least 8 characters, continue asking until they enter a valid password:

The password must be at least 8 characters long, your password is only X characters long. (X is the length of the current password)

d.     Ask the user a number between 1 and 10 (Inclusive) that will be used as the encryption key. If it is not between 1 and 10, then print the following error message and ask the user to enter a key that is between 1 and 10 continue asking until they enter a valid password.

The key must be between 1 and 10, you entered is X. (X is the number entered)

e.     Create two objects of the Encryption class:

                                               i.     Create the first Encryption class object using the default constructor

                                             ii.     Create the second Encryption class object using the parameterized constructor (pass the password and key entered by the user as its parameters)(Remember the parametrized constructor calls the encryption method within the Encryption class)

f.      Call the second object’s toString and display the results.

g.     Test the encrypt method

                                               i.     Prompt the user to enter their password

                                             ii.     Call the isValidPassword method using this clear text password as its parameter

                                           iii.     Display a message indicating the results of password validation.

h.     Test all other methods of the Encryption class that haven’t already been tested, such as setKey.

Prompt the user if they would like to run the program and if so restart the program.

5.     Encryption Algorithm

Implement a simple shift cipher.

A shift cipher is a form 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 shift of 3, A would be replaced by D, B would become E, and so on.

The shift for this program will be the key entered by the user.

The password may be any of the characters in the ASCII table from character 33 the exclamation point ‘!’ to character 122 the lower case ‘z’.

If the shift cause the character to be greater than 122, the shift will continue starting with character 33.

Example:

If the user entered 8 as the key and a letter in the password is lower case ‘x’ (char 120) a shift of 8 would result in the character ‘&’ (char 38).  

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

Encryption.j ava


public class Encryption {
  
   private String encryptedPassword;
   private int key;
  
   public Encryption() {
       this.key = 0;
       this.encryptedPassword = "";
   }
  
   public Encryption(int key, String clearTextPassword) {
       this.key = key;
       encrypt(clearTextPassword);
   }

   public String getEncryptedPassword() {
       return encryptedPassword;
   }

   public void encrypt(String clearTextPassword) {
       this.encryptedPassword = "";
       for(int i = 0; i < clearTextPassword.length(); ++i){
           this.encryptedPassword += (char)(clearTextPassword.charAt(i) + key);
       }
   }

   public int getKey() {
       return key;
   }

   public void setKey(int key) {
       this.key = key;
   }
  
   public boolean isValidPassword(String clearTextPassword){
       String temp = "";
       for(int i = 0; i < clearTextPassword.length(); ++i){
           temp += (char)(clearTextPassword.charAt(i) + key);
       }
       return temp.equals(this.encryptedPassword);
   }
  
   public String toString(){
       return "Encrypted Password is " + encryptedPassword + " and the key is " + key;
   }
  
}

\color{blue}\underline{Password.java:}

import java.util.Scanner;

public class Password {

   public static void main(String[] args){
       Scanner in = new Scanner(System.in);
       String pass;
       int key;
       while(true){
           System.out.print("Enter a passowrd: ");
           pass = in.next();
           if(pass.length() < 8){
               System.out.println("Error. Length of the password should be atleast 8. Try again!!");
           }
           else{
               break;
           }
       }
       while(true){
           System.out.print("Enter encryption key(1 - 10): ");
           key = in.nextInt();
           if(key < 1 || key > 10){
               System.out.println("Error. Key is not in range(1 - 10). Try again!!");
           }
           else{
               break;
           }
       }
       Encryption e1 = new Encryption(key, pass);
       Encryption e2 = new Encryption();
       e2.setKey(key);
       e2.encrypt(pass);
       System.out.println(e2.toString());
       System.out.print("Enter your password: ");
       pass = in.next();
       if(e2.isValidPassword(pass)){
           System.out.println("Passwords match");
       }
       else{
           System.out.println("Passwords do not match");
       }
   }
  
}

Output:

Enter a passowrd: ronaldo
Error. Length of the password should be atleast 8. Try again!!
Enter a passowrd: kad
Error. Length of the password should be atleast 8. Try again!!
Enter a passowrd: ronaldo77
Enter encryption key(1 - 10): -5
Error. Key is not in range(1 - 10). Try again!!
Enter encryption key(1 - 10): 15
Error. Key is not in range(1 - 10). Try again!!
Enter encryption key(1 - 10): 7
Encrypted Password is yvuhskv>> and the key is 7
Enter your password: ronaldo7
Passwords do not match

Add a comment
Know the answer?
Add Answer to:
1.     This project will extend Project 3 and move the encryption of a password to a...
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
  • 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 Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones...

    This project will use The Vigenere Cipher to encrypt passwords. Simple letter substitution ciphers are ones in which one letter is substituted for another. Although their output looks impossible to read, they are easy to break because the relative frequencies of English letters are known. The Vigenere cipher improves upon this. They require a key word and the plain text to be encrypted. Create a Java application that uses: decision constructs looping constructs basic operations on an ArrayList of objects...

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

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

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

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

  • This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = '...

    This is Crypto Manager blank public class CryptoManager { private static final char LOWER_BOUND = ' '; private static final char UPPER_BOUND = '_'; private static final int RANGE = UPPER_BOUND - LOWER_BOUND + 1; /** * This method determines if a string is within the allowable bounds of ASCII codes * according to the LOWER_BOUND and UPPER_BOUND characters * @param plainText a string to be encrypted, if it is within the allowable bounds * @return true if all characters...

  • Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank...

    Java: Please help with my Tester. I'm having a hard time figuring out my error. Thank you. What the tester requires: The AccountTester This class should consists of a main method that tests all the methods in each class, either directly by calling the method from the Tester or indirectly by having another method call a method. User and Bot information will be read from a file. A sample file is provided. Use this file format to aid in grading....

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

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