Question: Warm - Up 9 . 1 : Hashing Strings Start Assignment Due Oct 2 7 by 1 1 : 5 9 pm Points 0 Submitting
WarmUp : Hashing Strings
Start Assignment
Due Oct by :pm
Points
Submitting a text entry box or a file upload
File Types c
Available until Dec at :pm
Introduction
For this program you will be generating MD hashes of strings. This program will make use of concepts we have been learning:
Command line arguments
Reading and writing files
Linking to libraries
Multifile compilation
We will be using the MD hashing algorithm which, as discussed in the live session, creates bit hashes. By convention, the hashes are represented as a string of hexadecimal digits.
Specification
The program, called makehash, will accept two command line arguments:
The source file name to read plaintext from
The destination file name to write hashes to
If the user doesn't supply these two filenames, an appropriate error message should be displayed and the program exits with status code
Each line in the source file is read in hashed, and the hash written to the destination file. Each input line should have its newline, if present, trimmed off before hashing.
Using the md function
The md function is contained in the mdc file. A corresponding function prototype is in the mdh header file. To use the md function in your program, #include the mdh header file to make the function prototype available. For most people viewing this page, the contents of the files can be found in the tabs below.
To generate an MD hash, call the md function, passing in two parameters:
The string to be hashed;
The length of the string.
The function returns to the caller a string containing the character hexadecimal hash. The character array is malloc'd by the md function; it is the caller's responsibility to free the memory when it is no longer needed.
Compiling your program
Your program will consist of two source files that need to be compiled together to make an executable. Neither of them, individually, is a complete program. Additionally, the md function internally calls additional functions from the libcrypto library. This will need to be linked in to your program.
To compile your program, use this command line:
clang makehash.c mdc l crypto
Note: the crypto library is included in your Theia environment. In other environments for example, Ubuntu Linux or Mac OS X the libraries you need may be different.
What to Turn In
For this assignment, just submit your makehash.c file. You don't need to submit any of the other files that were needed to compile this program.
Files
Test File
Use this short text file a source for strings to hash.
dinosaur pineapple SpongeBob rockstar Burger King May the Force be with you.
When run through yourprogram the output should appear as below.
aeefaccec deeaefffcacfcfdffbcabc dfebbbbdfddbaebfecceaecbdcdefabaabb
Test File
I ate a clock yesterday, it was very timeconsuming. Did you hear about the monkeys who shared an Amazon account? They were Prime mates. Two guys stole a calendar. They got six months each. What do you call a thieving alligator? A Crookodile.
Here are the resulting hashes:
eeffbbcbe fdeeecddbbe caaffcedd cfebfffbdfddae ceeeaeefaecbf
mdc
#include #include #include #include char mdconst char str int length EVPMDCTX mdctx; unsigned int mddigestlen EVPMDsizeEVPmd; uintt mddigestmddigestlen; char hexdigest char mallocmddigestlen ; MDInit mdctx EVPMDCTXnew; EVPDigestInitexmdctx EVPmd NULL; MDUpdate while length if length EVPDigestUpdatemdctx str; else EVPDigestUpdatemdctx str length; length ; str ; MDFinal EVPDigestFinalexmdctx mddigest, &mddigestlen; EVPMDCTXfreemdctx; for int n ; n mddigestlen; n snprintfhexdigest nx mddigestn; hexdigestmddigestlen ; return hexdigest;
PreviousNext
mdh
Create an MD hex digest from a string. byte string is malloc'd by this function. The caller must free it When compiling, link to: l crypto char mdconst char str int length;
PreviousNext
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
