Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement SHA-512 and HMAC using C++.... A. Implement SHA-512 using C++ Input: A

ID: 3823367 • Letter: I

Question

Implement SHA-512 and HMAC using C++....

A. Implement SHA-512 using C++ Input: An input file contains a message that will be composed of ASCII characters. You may not assume that the message is a specific length, but you may assume that the length of the input string is a multiple of 1024 bits Output: A 512-bit digest, expressed in hexadecimal. B. Implement HMAC using SHA-512 implemented above as the building block. Input: A key used in HMAC algorithm The input message that is stored in the file with the given name. Output: After computing the HMAC, convert the result into hexadecimal and print it on the screen. Use all upper-case letters for hexadecimal A' through F.

Explanation / Answer

Answer :-

a.

#include <iostream>
#include "sha512.h"

using std::string;
using std::cout;
using std::endl;

int main(int ar, char *av[])
{
string input = "grape";
string output1 = sha512(input);

cout << "sha512('"<< input << "'):" << output1 << endl;
return 0;
}

b .

#include <iostream>
#include "sha512.h"

using namespace std;

const unsigned int size = (1024/8);

int main(int ar, char *av[])
{
if(ar!=3)return 0;
string key = av[1];
string message = av[2];

if(key.length() > size){
key = sha512(key);
}
while(key.length() < size){
key = key + (char)0x00;
}

string o_pad = key;
for(unsigned int i = 0; i < size; i++){
o_pad[i] = key[i] ^ (char)0x5c;
}

string i_pad = key;
for(unsigned int i = 0; i < size; i++){
i_pad[i] = key[i] ^ (char)0x36;
}

string output = sha512(o_pad + sha512(i_pad + message));

cout<<"hmac-sha512: "<<output<<endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote