Posts

Showing posts from January, 2024

class net id ---------PK

#include<stdio.h> #include<math.h> int main() { char cl;   int b1,b2,b3,b4;   int d1,d2,d3,d4;   int bd1,bd2,bd3,bd4;   int s;   printf("\nEnter 1st byte : ");   scanf("%d",&b1);     printf("\nEnter 2nd byte : ");   scanf("%d",&b2);   printf("\nEnter 3rd byte : ");   scanf("%d",&b3);   printf("\nEnter 4th byte : ");   scanf("%d",&b4);   printf("\nEnter No. of subnets : ");   scanf("%d",&s);   if(b1>255 || b1<0 || b2>255 || b2<0 || b3>255 || b3<0 || b4>255 || b4<0)   {   printf("\nInvalid IP"); }   printf("IP address is : %d.%d.%d.%d",b1,b2,b3,b4);   if(b1>0 && b1<=127)   {   cl='A';   printf("\nClass A"); d1=255; d2=0; d3=0; d4=0; } else if(b1>127 && b1<=191)   {   cl='B';   printf("\nClass B"); d1=255; d2=255; d3=0; d4=0; } else ...

CRC receiver

// Include headers #include<stdio.h> #include<string.h> // length of the generator polynomial #define N strlen(gen_poly) // data to be transmitted and received char data[28]; // CRC value char check_value[28]; // generator polynomial char gen_poly[10]; // variables  int data_length,i,j; // function that performs XOR operation void XOR(){     // if both bits are the same, the output is 0     // if the bits are different the output is 1     for(j = 1;j < N; j++)     check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');      } // Function to check for errors on the receiver side void receiver(){ // get the received data     printf("Enter the received data: ");     scanf("%s", data);     printf("\n-----------------------------\n");     printf("Data received: %s", data); // Cyclic Redundancy Check     crc(); // Check if the remainder is zero to find the error ...

CRC sender

#include<stdio.h>     int arr[8],crc[12],gen[5]={1,0,0,1,1},temp[12];     int i,j,k,l;     void to_binary(int a)     {   for(i=6;i>=0;i--)   {      arr[i]=a%2;      a=a/2;   }   printf("\nThe binary equivalent of given character is :");   for(i=0;i<7;i++)   printf("%d",arr[i]);     }     void to_crc()     {  printf("\n\nFrame after adding 4 zeros at the end for Dataword: ");  for(i=0;i<11;i++)  {      if(i>6)      crc[i]=0;     else   crc[i]=arr[i];  }  for(i=0;i<11;i++)  {      printf("%d",crc[i]);      temp[i]=crc[i];  }    //EX-ORING  printf("\n\nFrame Generated after applying CRC Tech. : ");  k=0;  for(i=0;i<7;i++)  {      if(temp[i]==1)      {   for(j=i;j<...

switch configuration algo

Image

Hamming reciver and sending

#include <stdio.h> int main() {     int d[8],c[4],h[12],i,j,n=0,r[12],c1;     //Sender Side  for(i=0;i<8;i++)  {   printf("\nEnter %d bit of data=",i);   scanf("%d",&d[i]);  }  printf("\nData entered is=\n");  for(i=0;i<8;i++)  printf("%d",d[i]);  c[0]=d[0]^d[1]^d[3]^d[4]^d[6];  c[1]=d[0]^d[2]^d[3]^d[5]^d[6];  c[2]=d[1]^d[2]^d[3]^d[7];  c[3]=d[4]^d[5]^d[6]^d[7];  printf("\n Parity bit are %d %d %d %d",c[0],c[1],c[2],c[3]);  i=0;  for(j=0;j<12;j++)  {   if((pow(2,n)-1)==j)   {    h[j]=c[n];    n++;   }   else   {    h[j]=d[i];    i++;   }  }  printf("\nData transmitted is=");  for(i=0;i<12;i++)  {   printf("%d",h[i]);  }  //Receiver Side  printf("\nEnter received code word bits one by one=");     for(i=0;i<12;i++)  {   printf("\nEnter %d...

class less

#include <stdio.h> int main() {  char data[100],sdata[100],rdata[100],rrdata[100];  int i=0,j=1;  printf ("$ is Flag and @ is Escape Character.\n");  printf ("Enter the Message : ");  scanf ("%s",&data);  sdata[0]='$';  while (data[i]!='\0')  {   if (data[i]=='$'||data[i]=='@')   {    sdata[j]='@';    j++;    sdata[j]=data[i];   }   else   {    sdata[j]=data[i];   }   i++;   j++;  }  sdata[j]='$';  sdata[j+1]='\0';  printf ("Sending data .... %s",sdata);  i=0;  printf ("\n\n");  while (sdata[i]!='\0')  {   rdata[i]=sdata[i];   i++;  }  rdata[i]='\0';  i=0;  for(j=1;rdata[j]!='\0';j++)  {   if (rdata[j]=='@')   {    j++;    rrdata[i]=rdata[j];   }   else if (rdata[j]=='$')   {    rrdata[i]=rdata[j+1];   }   else   { ...

byte stuffing send and receive

#include <stdio.h> int main() {  char data[100],sdata[100],rdata[100],rrdata[100];  int i=0,j=1;  printf ("$ is Flag and @ is Escape Character.\n");  printf ("Enter the Message : ");  scanf ("%s",&data);  sdata[0]='$';  while (data[i]!='\0')  {   if (data[i]=='$'||data[i]=='@')   {    sdata[j]='@';    j++;    sdata[j]=data[i];   }   else   {    sdata[j]=data[i];   }   i++;   j++;  }  sdata[j]='$';  sdata[j+1]='\0';  printf ("Sending data .... %s",sdata);  i=0;  printf ("\n\n");  while (sdata[i]!='\0')  {   rdata[i]=sdata[i];   i++;  }  rdata[i]='\0';  i=0;  for(j=1;rdata[j]!='\0';j++)  {   if (rdata[j]=='@')   {    j++;    rrdata[i]=rdata[j];   }   else if (rdata[j]=='$')   {    rrdata[i]=rdata[j+1];   }   else   { ...

B ip to D ip and D ip to B ip

#include<stdio.h> #include<string.h> int binary(int n) { int c=0,b,mf=1; while(n>0) { b=n%2; n=n/2; c=b*mf+c; mf=mf*10; } return c; } int decimal(int n) { int dv=0,base=1,rem; while(n>0) { rem=n%10;  dv=dv+rem*base;  n=n/10;  base=base*2;  } return dv; } int  main() { char data[16]; int a,i,n1,n2,n3,n4; printf("Enter 1 :- For converting data from decimal  IP adress to binary IP adress \nEnter 0 :- For converting data from binary IP adress to decimal IP adress \n "); scanf("%d",&a); getchar(); if(a==1) { { printf("Enter the IP adress :- "); scanf("%s",data); sscanf(data,"%d.%d.%d.%d",&n1,&n2,&n3,&n4); } for(i=0;data[i]!='\0';i++) { if(!(data[i]=='1' || data[i]=='0' || data[i]=='2' || data[i]=='3' || data[i]=='4' || data[i]=='5' || data[i]=='6' || data[i]=='7' || data[i]==...

bit stuffing sending and receiving

#include<stdio.h> int sender(char str[],char ptr[],char dest[]) { int i,j=0,k=0,c=0,count=0; for(k=0;k<8;k++) {  if(k==0||k==7)   dest[k]='0';  else   dest[k]='1'; } for(i=0;str[i]!='\0';i++) {  count++; if(str[i]==ptr[j]) { dest[k]=str[i]; c++; k++; if(c==5) {  dest[k]='0';  k++;  j=0;  c=0; } } else {  dest[k]=str[i];  k++;  j=0;  c=0; if(str[i]=ptr[j]) {  c++;  j++; } } } j=0; while(ptr[j]!='\0') {  dest[k]=ptr[j];  k++;  j++; } dest[k]='1'; dest[k+1]='0'; dest[k+2]='\0'; printf("\nString send from sender side \n%s",dest); return count; } /*int receiver(char result[],char dest[]) {  int i=0,j=0,k=0,count;  for(k=8;dest[k]<a+8;k++)  {   result[i]==dest[k];   i++;  } printf("strring receive from receiver is %s",result); }*/ void main() {  char ptr[10]={'0','1','1','1','1','1','\0'}; char dest[100]; char str[100]; char result[100]; char...

send and receiver side parity detection

#include <stdio.h> #include <stdlib.h> int checking(char *data) {     int i=0,num;     while (data[i]!='\0')     {         num=data[i]-48;         if (num=='0'||num=='1')         {             i++;         }         else         {             return 0;         }     }     return 1; } int main() {  char data[40],rdata[40];  int i=0,count=0,check;  printf("Enter the data : \t");  scanf ("%s",data);   check=checking(&data[0]);   printf ("%d is num",check);  if (check==0)     {         printf ("Error.....\nEntered Data is Wrong");         return 0;     }     else if (check==1)     {         printf...

class net id

#include<stdio.h> int checking(char *ip) { int i=0,c=0; while (ip[i]!='\0') { if (ip[i]=='.') { c++; } i++; } if (c==3) { return 1; } return -1; } int find_class(int a,char *ip) { if (a>=0&&a<=127) { printf ("%s is Belongs to Class A",ip); return 'A'; } else if (a>=128&&a<=191) { printf ("%s is Belongs to Class B",ip); return 'B'; } else if (a>=192&&a<=223) { printf ("%s is Belongs to Class C",ip); return 'C'; } else if (a>=224&&a<=239) { printf ("%s is Belongs to Class D",ip); return 'D'; } else if (a>=240&&a<=255) { printf ("%s is Belongs to Class E",ip); return 'E'; } } int validity(int a,int b,int c,int d) { if (a<=255&&b<=255&&c<=255&&d<=255) { return 1; } else { printf ("Check the Ip Address first...