CHECKSUM
CHECKSUM
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 checksum,sum=0,i;
printf("\n****SENDER
SIDE****\n"); for(i=0;i<n;i++)
sum+=arr[i];
printf("\nCHECKSUM IS:%d",checksum);
return checksum;
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;
printf("\nCHECKSUM IS:%d",checksum);
void main()
int n,sch,rch;
scanf("%d",&n);
int arr[n];
scanf("%d",&arr[i]);
sch=sender(arr,n);
receiver(arr,n,sch);
}
ADITYA KUMAR JHA
22BEC1074
EXPLANATION:
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.