What is a checksum And how can I creat a C program out of it

What is a checksum? And how can I creat a C program out of it!

Solution

We can use checksums for ensuring the integrity of a file.

Suppose a file has been transmitted from source to destination, this can be across the internet or between two computers on the same network.

If we want to check that the source file and the destination file is completely same then we will use checksum.

Algorithm:

Step 2: Accept two values. (Size and data to send)

Step 4: Find complement of the data and put it on sResult.

Step 5: Find the complement of result and put it on rResult.

Step 6: Compare if the sResult and rResult is 0 then print code generated is correct.

Step 7: Else print code generate is incorrect.

Step 8: Exit program.

Program

#include<stdio.h>
#include<conio.h>
#include<math.h>


int send(int Sdata[10],int l)
{
int check_sum, sum = 0, c;
printf(\"\ SENDER SIDE DATA \ \");
for(c = 0; c < l; c++)
sum += Sdata[c]; //Calculates the sum
printf(\"\ SUM FOR SENDER = %d\", sum);
check_sum = ~sum; //Calculates the complement
printf(\"\ RESULT OF CHECKSUM (SENDER SIDE): %d\",check_sum);
return check_sum;
}

int rec(int Rdata[10],int l,int Scheck)
{
int check_sum, sum = 0,c;
printf(\"\ RECEIVER SIDE DATA \ \");
for(c = 0; c < l; c++)
sum += Rdata[c]; //Calculates the sum
printf(\"\ SUM FOR RECEIVER = %d\", sum);
sum = sum + Scheck; //Calculates the sum
check_sum = ~sum; //Calculates the complement
printf(\"\ RESULT OF CHECKSUM (RECEIVER SIDE): %d\",check_sum);
return check_sum;
}

int main()
{
int ARR[10], c, no, Scheck, Rcheck;
printf(\"\ ENTER NUMBER OF DATA: \");
scanf(\"%d\",&no);

printf(\"\ ENTER THE DATA IN BINAY FORM:\");
for(c = 0; c < no; c++)
scanf(\"%d\",&ARR[c]);
Scheck = send(ARR, no); //Call for sender function
Rcheck = rec(ARR, no, Scheck); //Call for receiver function
if(Rcheck == 0) //Checks for equality
printf(\"\ \ TRANSMISSION ERROR NOT FOUND \ \ \");
else
printf(\"\ \ ERROR DETECTED\");
}

Output

ENTER NUMBER OF DATA: 3

ENTER THE DATA IN BINAY FORM:10110
101010
1011

SENDER SIDE DATA

SUM FOR SENDER = 112131
RESULT OF CHECKSUM (SENDER SIDE): -112132
RECEIVER SIDE DATA

SUM FOR RECEIVER = 112131
RESULT OF CHECKSUM (RECEIVER SIDE): 0

TRANSMISSION ERROR NOT FOUND

What is a checksum? And how can I creat a C program out of it!SolutionWe can use checksums for ensuring the integrity of a file. Suppose a file has been transmi
What is a checksum? And how can I creat a C program out of it!SolutionWe can use checksums for ensuring the integrity of a file. Suppose a file has been transmi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site