C++ Program – CheckSum generator



//Downloaded From theonlinetutorials.com
//Source code
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define size 100
unsigned short int checksum(char []);
void valch(unsigned short int check,char message[]);
int main(){
 clrscr();
 cout<<" Enter any thing :";
 char message[size]={0};
 cin>>message;
 unsigned short int check=checksum(message);
 getch();
 valch(check,message);
 getch();
 return 0;
 }
void valch(unsigned short int check,char message[]){
 unsigned short int t[size],ch=0;
 int i,j,n;
 cout<<endl<<endl;
 cout<<"Checking Checksum"<<endl;
 for(i=0,j=0;i<strlen(message);i=i+2,j++){
 t[j]=message[i];
 t[j]=t[j]<<8;
 t[j]=t[j]+message[i+1];
 }
 n=j;
 for(i=0;i<n;i++){
 printf("%X\n",t[i]);
 ch+=t[i];
 }
 printf("%X\n",check);
 ch+=check;
 printf("----\n");
 printf("%X\n",ch);
 printf("   1\n");
 printf("----\n");
 ch++;
 printf("%X\n",ch);
 ch=~ch;
 printf("%4X\n",ch);
 if(ch==0)
 cout<<"Checksum is valid";
 else
 cout<<"Checksum is invalid";
 }
unsigned short int checksum(char message[]){
 unsigned short int t[size];
 unsigned short int check=0;
 int i,j,n;
 cout<<"Generating Checksum"<<endl;
 for(i=0,j=0;i<strlen(message);i=i+2,j++){

 //Divide Message into 16-bit field
 t[j]=message[i];
 t[j]=t[j]<<8;
 t[j]=t[j]+message[i+1];
 }
 n=j;

 for(i=0;i<n;i++){
 printf("%X\n",t[i]);
 check+=t[i];
 }
 printf("0000\n");
 printf("----\n");
 printf("%X\n",check);
 printf("   1\n");
 check+=1;
 printf("----\n");
 printf("%X\n",check);
 check=~check;
 printf("%X\n",check);
 cout<<"Checksum is generated at it is"<<endl;
 printf("%X\n",check);
 return check;
 }



Print Friendly

1 Comment

 Add your comment
  1. check sum c++ generator is good working. thanku lot sir . I faced some coding error in check sum c++ .. and now corrected. tks

Leave a Comment

Your email address will not be published.

Current ye@r *