0% found this document useful (0 votes)
66 views6 pages

CHECKSUM

The document outlines an experiment to implement a checksum code in C for verifying data integrity during transmission. It explains the checksum algorithm, its limitations, and provides code for both sender and receiver functions to calculate and verify checksums. The experiment highlights applications in network communication, file verification, and storage systems, concluding that while checksums are efficient for error detection, they have limitations and may require more robust methods for critical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

CHECKSUM

The document outlines an experiment to implement a checksum code in C for verifying data integrity during transmission. It explains the checksum algorithm, its limitations, and provides code for both sender and receiver functions to calculate and verify checksums. The experiment highlights applications in network communication, file verification, and storage systems, concluding that while checksums are efficient for error detection, they have limitations and may require more robust methods for critical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ADITYA KUMAR JHA

22BEC1074

EXPERIMENT -8
CHECKSUM CODE USING C

AIM:
To implement a checksum code using the C programming language to
verify data integrity. The checksum algorithm will be used to generate a
checksum value for a given set of data, and the receiver can use the checksum to
verify whether the data has been transmitted correctly or not.

TOOLS REQUIRED:
C Compiler, to compile and run the C program

THEORY:
A checksum is a value used to verify data integrity during transmission. It is
calculated by performing arithmetic operations on the data, such as summing the
values, and then applying a 1's complement to the result. The sender computes the
checksum and sends it along with the data. The receiver performs the same
operation on the received data and adds the received checksum. If the result is 0, it
indicates that the data has been transmitted correctly; otherwise, an error is
detected.
Checksums are simple to implement and computationally efficient, making them
useful for error detection in applications like network communication and file
verification. However, checksums cannot correct errors and may not detect all
types of errors. They are typically used for basic error detection, while more
complex techniques like Cyclic Redundancy Checks (CRC) may be employed for
more robust error handling.
ADITYA KUMAR JHA
22BEC1074

 Limited Error Detection: Checksum may not catch all types of errors,
especially when multiple errors occur that cancel each other out, leading to
undetected corruption.
 No Error Correction: A checksum can only detect errors; it cannot correct
or recover corrupted data, requiring retransmission if errors are found.
 Vulnerable to Collisions: In some cases, different data inputs can
generate the same checksum value, which could lead to false positives
(checksum passes, but data is corrupted).

CODE:
#include<stdio.h>

#include<math.h>

int sender(int arr[10],int n)

int checksum,sum=0,i;

printf("\n****SENDER

SIDE****\n"); for(i=0;i<n;i++)

sum+=arr[i];

printf("SUM IS: %d",sum);

checksum=~sum; //1's complement of sum

printf("\nCHECKSUM IS:%d",checksum);

return checksum;

void receiver(int arr[10],int n,int sch)

int checksum,sum=0,i;
ADITYA KUMAR JHA
22BEC1074

printf("\n\n****RECEIVER SIDE****\n");

for(i=0;i<n;i++)

sum+=arr[i];

printf("SUM IS:%d",sum);

sum=sum+sch;

checksum=~sum; //1's complement of sum

printf("\nCHECKSUM IS:%d",checksum);

void main()

int n,sch,rch;

printf("\nENTER SIZE OF THE STRING:");

scanf("%d",&n);

int arr[n];

printf("ENTER THE ELEMENTS OF THE ARRAY TO CALCULATE


CHECKSUM:\n");
for(int i=0;i<n;i++)

scanf("%d",&arr[i]);

sch=sender(arr,n);

receiver(arr,n,sch);

}
ADITYA KUMAR JHA
22BEC1074

EXPLANATION:

Prompt the user to enter the size of the string, n.


Initialize an array of size n, arr[n].
Ask the user to input n elements into the array to compute the
checksum.
To calculate the checksum on the sender side, pass the array and the
number of elements to a function sender(), and store the returned value in a
variable sch.
Inside the sender() function, loop from i = 0 to n, and in each iteration,
calculate the sum as sum = sum + arr[i]. This will accumulate the sum of
all elements in the array.
Next, compute the checksum as the 1’s complement of the sum and
display both the sum and checksum for the sender side.
Return the checksum value and store it in the variable sch.
To calculate the checksum on the receiver side, pass the array, the
number of elements, and the sch value to a function receiver().
Inside the receiver() function, loop from i = 0 to n, and in each iteration,
calculate the sum as sum = sum + arr[i]. This will accumulate the sum of
all elements in the array.
Add the value of sum with sch and store the result in the variable sum.
This step decodes the checksum generated by the sender.
Finally, compute the checksum as the 1’s complement of the sum, and
display both the sum and checksum for the receiver side.

INFERENCES AND APPLICATIONS:


Network Communication Protocols: Checksum is widely used in networking
protocols like TCP/IP, where data packets are verified for integrity during
transmission to ensure no corruption or loss.
File Integrity Verification: Many download services provide checksum values (e.g.,
MD5, SHA) to ensure files have not been corrupted or tampered with during the
transfer.
ADITYA KUMAR JHA
22BEC1074

Storage Systems: Hard drives and other storage devices use checksums to verify
the integrity of data written to disk, protecting against corruption during
read/write operations.

OUTPUT:
ADITYA KUMAR JHA
22BEC1074

CONCLUSIONS:
In conclusion, checksum is a simple and efficient method for detecting
errors in data transmission, ensuring data integrity. While it is computationally light
and widely used in networking and file verification, it has limitations in detecting
complex errors and cannot correct them. More robust methods like CRC may be
necessary for critical applications.

You might also like