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

I need to change this to C++, including the last part of the comment meaning the

ID: 3901990 • Letter: I

Question


I need to change this to C++, including the last part of the comment meaning the checksums don't match.

if connand CS is given, conduct a checksum on the recieved file elif data "CS" print "Comparing checksum for recieved file." receive checksum from other end checksum conn.recv(buffer size) #create checksum of file #compare checksums #1f; checksums match, say they match and return 'I' conn.send("1) print Checksums match! #else delete file and say they dont match and return #conn . Send("1") #print Error: Checksums dont match."

Explanation / Answer

else if (data == "CS"){

cout<<"Comparing checksum for received file."<<endl;

checksum = conn.recv(buffer_size);

//create checksum of file

const size_t WORD_SIZE = sizeof(uint32_t);

file.seekg(0, ios::end);

auto sizeInBytes = file.tellg();

file.seekg(0);

uint32_t file_checksum = 0;

if(auto sizeInEntireWords = sizeInBytes / WORD_SIZE)

{

for(int i = 0; i < sizeInEntireWords; i++)

{

uint32_t word;

file.read(reinterpret_cast<char*>(&word), WORD_SIZE);

file_checksum += word;

}

}

if(checksum == file_checksum){

cout<<"checksum matched"<<endl;

return 1;

}

else{

cout<<"Error: Checksum dont match"<<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