COP 4530/CGS5425: Data Structures, Algorithms, and Generic Programming Florida State University, Dept. of Comp. Sci., Fall 2006 Instructor: Breno de Medeiros TA: Ling Toh Assignment 4: HashTables Goals: In this assignment, you will be required to implement a program to simulate a simple password server. The data structure for the password server is a HashTable object. You are required to write the program for both the password server client program, as well as the HashTable class. Requirements for Client Program The following are the requirements for the password server client program named pass.cpp: The client must store username and encrypted password pairs in a HashTable object. The client must allow the user to: 1. Load the password file into the HashTable object. The client reads the username and encrypted password as a pair object from a file and adds the pair entry into the HashTable object. 2. Add a new username and password. The client reads in the username and password as a pair object from the user entry and adds the pair entry into the HashTable object. 3. Remove an existing user. The client reads in the username from the user and removes the corresponding pair entry from the HashTable object. 4. Change an existing user s password. The client reads in the username and password as a pair object, the new password from the user and modifies the pair object s second entry in the HashTable object. 5. Check if a user exists. The client reads in the username and password as a pair object from the user and checks if the pair entry exists in the HashTable object. 6. See the structure and contents of the HashTable to screen. 7. Obtain the size of the HashTable. 8. Save the username and password combination to a file. 9. Exit the client. The client exits the program. The client must re-prompt the user for the next choice from the menu and exit the program only when the user selects the exit x option.
You MUST use the code provided in the attached pass.cpp file as a standardized option menu to develop the implementation for the rest of the client. You may not alter the Menu() method. Requirements for HashTable class A partial interface and implementation of the HashTable class is provided in the attached hashtable.h and hashtable.cpp files. The underlying HashTable data structure is a vector of lists, with each list storing pair objects. Hence, the data structure would be declared as, vector< list < pair < string, string > > > bucketvector; The partially distributed HashTable files contain the following functionality: unsigned int Index (const string & str): Returns the index of the bucketvector where the string str is hashed into. str stores the username. unsigned int hash_function (const string& str): Returns an integer value where the string str is hashed. str stores the username. This method is called by the Index method. unsigned int prime_below(unsigned int n): Returns the highest prime number below n. This method is called by the 1-parameter constructor. void setprimes(vector<unsigned int> &v): Evaluates the index value of a vector object and sets the corresponding element to store the value 1 if the index was a prime number and 0 if the index was not a prime number. This method is called by the prime_below method. Note: The vector object used in this method is used solely for the purpose of obtaining the highest prime number below n and is not the same vector object representing the HashTable. In addition, your full implementation MUST AT LEAST provide the following functionality: HashTable(): no-argument constructor. Initializes the vector to a default capacity of 11. We use a prime number to enhance the quality of the hashing performed later. We shall refer to the resulting capacity as 11 buckets. HashTable(size_t n): 1-parameter constructor. Initializes the vector to a specified capacity. This constructor is called by the client to set the capacity of the underlying vector to the highest prime number below n.
~HashTable():destructor. Iterates through the vector and clears all the lists within each bucket. Method that loads entries from a file: This method should read the username and password entry from a file and add the entries into the HashTable. Each pair entry is separated by a carriage return. A line entry is represented in the format: username:encrypted_password For example, a sample entry file is as follows: hemmi:i5ltky7/qq.yhp1hhzrcy/ marge:qnr/8wr64nvx3qquy.q7u1 hank:djp.joxf9u3vudm8qunmy/ toh:czz4fml29pz0vlpvacr1.0 sean:x.pthyv62/iu9ecwrgkbv0 stuart:sn0akstpbrrfpeppk4qpi/ matthew:cja3fxuld9/nilbzok1pr0 kelly:rixhnhgre6ouzda1o/lvz. Method that adds a user: This method should take the pair object containing the username and encrypted password and add the entry into the HashTable only if the username does not exist in the HashTable. A password MUST be encrypted before storage. For this project, we shall use the GNU C Library s crypt() method to encrypt the password. The algorithm for the crypt() method shall be MD5-based. The salt shall be the character stream $1$########. The resulting encrypted character stream is the $1$######## + $ + 22 characters = 34 characters in total. A user password is the sub string containing the last 22 characters, located after the 3 rd $. Note: A sample program to demonstrate the use of the crypt() method will be provided during Recitation 10. Method that removes a user: This method should find the username from the HashTable and remove the pair entry from the HashTable. Method that changes a username s password: This method should find the pair object containing the username and encrypted password and modify the pair s second entry in the HashTable with the new password. Method that find s a username: This method should inform the user if the username and encrypted password pair entry exists in the HashTable. Method that prints HashTable s contents: This method should print the structure and contents of the HashTable to the screen.
Method that returns the size: This method should return the size of the HashTable. Method that writes entries to a file: This method should write the username and password entries in the HashTable to a file. Each entry is separated by a carriage return. A line entry is represented in the format: username:encrypted_password For example, a sample entry output file is as follows: hemmi:i5ltky7/qq.yhp1hhzrcy/ marge:qnr/8wr64nvx3qquy.q7u1 hank:djp.joxf9u3vudm8qunmy/ toh:czz4fml29pz0vlpvacr1.0 sean:x.pthyv62/iu9ecwrgkbv0 stuart:sn0akstpbrrfpeppk4qpi/ matthew:cja3fxuld9/nilbzok1pr0 kelly:rixhnhgre6ouzda1o/lvz. Extra-credit ( 5 points) You may submit an alternative version to your client named spass.cpp, in which the client hides the user s entries whenever the user keys in a password or new password. Download Instructions To download the partial/sample files, go into the directory where you wish to have the assignment files copied to, and type the command line: cp -r ~cop4530/fall06/partials/proj4/. The following files have been provided for you: 1. hashtable.h : partial implementation 2. hashtable.cpp : partial implementation 3. lpass.x : sample executable for linprog.cs.fsu.edu 4. lspass.x: sample executable with hidden password entries for linprog.cs.fsu.edu 5. ppass.x : sample executable for program.cs.fsu.edu 6. pspass.x: sample executable with hidden password entries for program.cs.fsu.edu 7. test1: sample test case. Deliverables 1. Your implementation must be entirely contained in the following files, which MUST be named,
a. hashtable.h b. hashtable.cpp c. pass.cpp d. spass.cpp (optional: extra-credit) e. makefile 2. Your program must compile on linprog.cs.fsu.edu or program.cs.fsu.edu. If you program does not compile on either machines, the grader cannot test your submission. 3. Your executable(s) must be named pass.x and spass.x (for extra-credit option). 4. The interaction and output (including error messages) of your client s executable(s) must behave in the same manner as the distributed ppass.x and pspass.x (for program.cs.fsu.edu) or lpass.x and lspass.x (for linprog.cs.fsu.edu). e.g. One of the ways to test your program would be to run a diff command between the output file(s) created by your executable(s) and the output file(s) created by the distributed executable(s). Points will be deducted for not complying with these requirements. For instructions on how to submit your project, consult the first assignment, which is posted online. Remember to substitute "4" for "1" in all the command and path names which have the form "projectx" or "projx