Read strings from stdin in a loop (one per line) and print the SHA256 hash of each string in lowercase hexadecimal format
The loop should continue until EOF (end of file)
IMPORTANT
Must compile with the -lcrypto flag to link the OpenSSL library
gcc sha256_loop.c -o sha256_loop -lcrypto
Using SHA256
#include <openssl/sha.h>unsigned char hash[32]; // SHA256 produces 32 bytesSHA256((unsigned char*)my_string, strlen(my_string), hash);// Print as lowercase hex (2 hex digits per byte = 64 characters total)for(int i = 0; i < 32; i++) { printf("%02x", hash[i]);}printf("\n");
Test
$ gcc sha256_loop.c -o sha256_loop -lcrypto$ ./sha256_looppassword5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8hello2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824CSE298c0d6f3f5bcfed5043c0b854560dfcc3f2857a5c2d0d98d0b8f5d64c35b44aef<Press Ctrl-D for end of input>$ ./sha256_loop < small_input.txt5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d82cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98248c0d6f3f5bcfed5043c0b854560dfcc3f2857a5c2d0d98d0b8f5d64c35b44aef$ # The next command is how you should create the output files$ # It will result in a new file with the output from running ./sha256_loop, which$ # the grader will check for$ ./sha256_loop < small_input.txt > small_result.txt$ ./sha256_loop < input.txt > result.txt