Question
This project will use The Vigenere Cipher to encrypt passwords. Vigenere Cipher Simple letter substitution ciphers are ones in which one letter is substituted for
This project will use The Vigenere Cipher to encrypt passwords.
Vigenere Cipher
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.
Example:
Suppose you have a key word: house
We would encrypt a message as follows:
The first letter would be encrypted using these correspondences:
original letter: 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
substitute letter: h i j k l m n o p q r s t u v w x y z a b c d e f g
The second letter would be encrypted using these correspondences:
original letter: 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
substitute letter: o p q r s t u v w x y z a b c d e f g h i j k l m n
The third letter would be encrypted using these correspondences:
original letter: 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
substitute letter: u v w x y z a b c d e f g h i j k l m n o p q r s t
etc
Once all characters in the key are used, the offset repeats starting over with the Keys first letter.
The cipher for this program is a little more complex as you must include punctuation so the password may be any of the characters in the HYPERLINK "http://www.asciitable.com/" ASCII table from character 33 the exclamation point ! to character 122 the lower case z.
User Class
The class that contains user information including the username, password, encrypted password and key (see UML class diagram below)
User ------------- |
username : String clearPassword : String encryptedPassword : String key : String |
+User() +User(String, String, String) +getUserName() : String +setUserName(String) +getClearPassword(): String +setClearPassword(String) +getEncryptedPassword():String +setEncryptedPassword(String) +getKey(): String +setKey(String) -encrypt() +toString():String |
Constructors
Default constructor sets all fields to the empty String ()
Parameterized constructors
takes in the username, clearPassword and the key
calls the private method encrypt to encrypt the clearPassword using the Vigenere Cypher.
Methods
Accessor and mutator methods as listed in the Class Diagram
encrypt method
Private method only accessible to other methods of the User class.
Uses the Vigenere Cypher to encrypts the clearPassword instance variable using the key
Stores the encrypted password in encryptPassword instance variable.
toString returns a nicely formatted String representing the user to include username, encrypted password, clear password and key such as:
Jsmith ]Umka\f^ password house
Accounts Class
This class contains all the user objects for our company.
The classs instance variable includes company name, company address, and an ArrayList of User Objects (see UML class diagram below)
Accounts |
companyName : String companyAddress : String users : ArrayList NOTFOUND: int = -1 |
+Accounts() +Accounts(String, String) +getCompanyName(): String +setCompanyName(String) +getCompanyAddress(): String +setCompanyAddress(String) +addUser(User) +getUser(String): User +deleteUser(String):boolean -findUser(String):int +toString(): String |
Instance Variables
companyName name of company
companyAddress the address of the company
users an ArrayList containing User Objects
Constructors
Default constructor sets company name and address to the empty String and creates an ArrayList of User objects
Parameterized constructor sets the name and address parameters to the appropriate instance variable and creates the ArrayList of User Objects.
Methods
Accessor and mutator methods as listed in the Class Diagram
addUser
Takes in a User object
Adds that User object to the ArrayList
getUser
Takes in a String with the users username
Calls the private findUser method to locate the index of the User object in the ArrayList.
Returns the User object from the ArrayList that is associated with that username. (assume unique username)
If the username does not exist
print out the error message: does not exist.
Return null
deleteUser
Takes in a String with the users username
Calls the private findUser method to locate the index of the User object in the ArrayList
Returns true if user found and deleted, false if user not found.
findUser
Private method that takes in a String representing a username
Searches the ArrayList looking for this username (again assume usernames are unique)
If found, returns the ArrayList index of the username
If not found returns NOTFOUND constant.
toString
returns a nicely formatted String table representing all the users information in the ArrayList(see example below)
use of the User toString method is advisable.
ABC Company 1234 Holly Lane, Pensacola Florida Username EncryPass ClearPass Key Jsmith ]Umka\f^ password house
mjones GYOX)r*z abcd1234 tide
AccountTester
The purpose of this class is to thoroughly test all the methods and constructors in the Accounts and User classes.
Methods can be tested directly or indirectly
Indirect testing is testing a method by calling another method such as
If the constructors calls the mutator methods when setting instance variables rather than setting them directly.
If the toString method calls accessor method rather than accessing instance variables directly
No user input, just create variables and/or hardcode values
To simplify the program some, No error handling required
All passwords are 8 legal characters (as outlined in the requirements)
All keys are 5 characters
Program Flow (suggestion)
Create several User Objects
Add each to the Accounts class
Call the Accounts toString
Search for username including one that is not found.
Delete a user account.
Call Account toString before exiting.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started