Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Computer Networks Lab Assignment: Error Detection and Checksum Implementation, Assignments of Network security

Network Security and Data Communication Lab work assignment to find new secure ways to improve data protection.

Typology: Assignments

2021/2022

Available from 03/27/2023

utkarsh-goyal-1
utkarsh-goyal-1 🇺🇸

8 documents

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ITE3001-DCCN
LAB DA2
Name: Utkarsh Goyal
Reg.No 19BIT0402
COMPUTER NETWORKS LAB ASSIGNMENT
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Computer Networks Lab Assignment: Error Detection and Checksum Implementation and more Assignments Network security in PDF only on Docsity!

ITE3001-DCCN

LAB DA

Name: Utkarsh Goyal

Reg.No 19BIT

Q1. Code a C Program to test the following case, Assuming that your error detection method is following even parity, find the parity bit for each of the following data units. Code: #include <stdio.h> int main(){ int n,d,e=0; printf("Enter the binary number: "); scanf("%d",&n); while (n){ d=n%10; if (d==1){ e+=1; } n=n/10; }

  • b.)
  • c.)
  • d.)

scanf("%s",d); if(strlen(a)==strlen(b)&&strlen(b)==strlen(c)&&strlen(c)= =strlen(d)){ length = strlen(a); char carry='0'; for (j=0;j<3;j++) { for(i=length-1;i>=0;i--) { if(a[i]=='0' && b[i]=='0' && carry=='0') { sum[i]='0'; carry='0'; } else if(a[i]=='0' && b[i]=='0' && carry=='1') { sum[i]='1'; carry='0'; }

else if(a[i]=='0' && b[i]=='1' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='1') { sum[i]='0'; carry='1'; } else if(a[i]=='1' && b[i]=='0' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='1' && b[i]=='0' && carry=='1') { sum[i]='0'; carry='1';

a[i]=c[i]; } for (i=0;i<length;i++){ b[i]=d[i]; } } if (j==1){ for (i=0;i<length;i++){ sumcd[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=sumab[i]; } for (i=0;i<length;i++){ b[i]=sumcd[i]; } } if (j==2){

break; } } for(i=0;i<length;i++) { if(sum[i]=='0') complement[i]='1'; else complement[i]='0'; } if(carry=='1') carry='0'; else carry='1'; printf("\nChecksum=%c%s",carry,complement); }else { printf("\nWrong input strings"); } }

char sum[20], sumab[20], sumcd[20], complement[20], sum1[20], complement1[20]; int i,length,j,x,y,w,z; printf("Enter first binary number \n"); scanf("%s",a); printf("Enter second binary number \n"); scanf("%s",b); printf("Enter third binary number \n"); scanf("%s",c); printf("Enter fourth binary number \n"); scanf("%s",d); if(strlen(a)==strlen(b)&&strlen(b)==strlen(c)&&strlen(c)= =strlen(d)){ length = strlen(a); char carry='0'; for (j=0;j<3;j++) { for(i=length-1;i>=0;i--)

if(a[i]=='0' && b[i]=='0' && carry=='0') { sum[i]='0'; carry='0'; } else if(a[i]=='0' && b[i]=='0' && carry=='1') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='0') { sum[i]='1'; carry='0'; } else if(a[i]=='0' && b[i]=='1' && carry=='1') { sum[i]='0';

sum[i]='1'; carry='1'; } else break; } if (j==0){ for (i=0;i<length;i++){ sumab[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=c[i]; } for (i=0;i<length;i++){ b[i]=d[i]; } } if (j==1){ for (i=0;i<length;i++){

sumcd[i]=sum[i]; } for (i=0;i<length;i++){ a[i]=sumab[i]; } for (i=0;i<length;i++){ b[i]=sumcd[i]; } } if (j==2){ break; } } for(i=0;i<length;i++) { if(sum[i]=='0') complement[i]='1'; else

else if(sum[i]=='0' && complement[i]=='1' && carry=='0') { sum1[i]='1'; carry='0'; } else if(sum[i]=='0' && complement[i]=='1' && carry=='1') { sum1[i]='0'; carry='1'; } else if(sum[i]=='1' && complement[i]=='0' && carry=='0') { sum1[i]='1'; carry='0'; } else if(sum[i]=='1' && complement[i]=='0' && carry=='1') { sum1[i]='0'; carry='1';

else if(sum[i]=='1' && complement[i]=='1' && carry=='0') { sum1[i]='0'; carry='1'; } else if(sum[i]=='1' && complement[i]=='1' && carry=='1') { sum1[i]='1'; carry='1'; } else break; } for(i=0;i<length;i++) { if(sum1[i]=='0') complement1[i]='1'; else