SlideShare a Scribd company logo
1 of 86
-1- VERTICAL REDUNDANCY CHECK

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void receiver();
void sender();
int i,j,data[20];
void main()
{
         int ans;
         clrscr();
         printf("nn*********************** VERTICAL REDUNDANCY
         CHECK ***********************nn");
         while(1)
         {
                 printf("n--------------------------------------------------------------------------n
                 ");
                 printf("ttttMAIN MENU");
                 printf("n--------------------------------------------------------------------------n
                 n");
                 printf("Choice No. Choice Name.nn");
                 printf(" 1.       Sender's Sidenn 2.           Receiver's Sidenn 3.
                 ExitnnnEnter Your Choice : ");
                 scanf("%d",&ans);
                 switch(ans)
                 {
                        case 1:
                                 printf("n-----------------------------------------------------------
                                 -------------n");
                                 printf("ttt      Sender's Side");
                                 printf("n-----------------------------------------------------------
                                 --------------n");
                                 sender();
                                 break;
                        case 2:
                                 printf("n-----------------------------------------------------------
                                 --------------n");
                                 printf("ttt Receiver's Side");
                                 printf("n-----------------------------------------------------------
                                 --------------n");
                                 receiver();
                                 break;
                        case 3:
                                 exit(1);
                        default:


                                                  1
printf("nnINVALID ENTRY!!!");
                }
        }
}

void receiver()
{
       int sum=0;
       printf("nEnter the number of bits you want (Max 20) : ");
       scanf("%d",&j);
       printf("nnEnter %d bits : ",j);
       for(i=0;i<j;i++)
       {
              printf("nn %d bit: ",i+1);
              scanf("%d",&data[i]);
              if((data[i]!=0) && (data[i]!=1))
              {
                       printf("nInvalid Bit......Enter only (1's and 0's) ");
                       i--;
              }
       }
       for(i=0;i<j;i++)
       {
              sum=sum+data[i];
       }
       printf("n-------------------------------------------------------------------------n");
       printf("ttttOutput");
       printf("n-------------------------------------------------------------------------");
       printf("nnThe Number of 1's in the message is: %d",sum);
       if(sum%2==0)
       {
              printf("nnThere is no ERROR in the message.");
       }
       else
       {
              printf("nnThere is ERROR in the message.");
       }
}

void sender()
{
       int sum=0;
       printf("nEnter the number of bits you want (Max 20) : ");
       scanf("%d",&j);
       printf("nEnter %d bits : ",j);
       for(i=0;i<j;i++)



                                                  2
{
            printf("nn %d bit: ",i+1);
            scanf("%d",&data[i]);
            if((data[i]!=0) && (data[i]!=1))
            {
                    printf("nInvalid bit......Enter only (1's and 0's) ");
                    i--;
            }
    }
    for(i=0;i<j;i++)
    {
           sum=sum+data[i];
    }
    printf("n-------------------------------------------------------------------------n");
    printf("ttttOutput");
    printf("n-------------------------------------------------------------------------");
    printf("nnThe Message sent was : ");
    for(i=0;i<j;i++)
    {
           printf("%d",data[i]);
    }
    if(sum%2!=0)
    {
           printf("nnParity Bit is : 1");
           data[j]=1;
           printf("nnThe Message after appending parity bit was : ");
           for(i=0;i<=j;i++)
           {
                    printf("%d",data[i]);
           }
    }
    else
    {
           printf("nnParity Bit is : 0");
           data[j]=0;
           printf("nnThe Message after appending parity bit was : ");
           for(i=0;i<=j;i++)
           {
                    printf("%d",data[i]);
           }
    }
}




                                              3
OUTPUT:-

****************** VERTICAL REDUNDANCY CHECK *******************

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Side

  2.            Receiver's Side

  3.            Exit

Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                              Sender's Side
-----------------------------------------------------------------------------------------------------------
-

Enter the number of bits you want (Max 20) : 5

Enter 5 bits :

1 bit: 1


2 bit: 0


3 bit: 1


4 bit: 0


5 bit: 1

-----------------------------------------------------------------------------------------------------------
-


                                                     4
Output
-----------------------------------------------------------------------------------------------------------
-

The Message sent was : 10101

Parity Bit is : 1

The Message after appending parity bit was : 101011
-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Side

  2.            Receiver's Side

  3.            Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Side
-----------------------------------------------------------------------------------------------------------
-

Enter the number of bits you want (Max 20) : 4


Enter 4 bits :

1 bit: 1


2 bit: 0


3 bit: 2

Invalid Bit......Enter only (1's and 0's)




                                                     5
3 bit: 0


4 bit: 1

-----------------------------------------------------------------------------------------------------------
-
                                                Output
-----------------------------------------------------------------------------------------------------------
-

The Number of 1's in the message is: 2
There is no ERROR in the message.
-----------------------------------------------------------------------------------------------------------
-
                                              MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Side

  2.            Receiver's Side

  3.            Exit

Enter Your Choice : 3




                                                     6
-2- LONGITUDINAL REDUNDANCY CHECK


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int a[10][10];
int count,j,i,n,m;
void sender();
void receiver();
void main()
{
        int ans;
        clrscr();
        printf("nn*********************** LONGITUDINAL REDUNDANCY
        CHECK ***********************nn");
        while(1)
        {
                printf("n--------------------------------------------------------------------------n
                ");
                printf("ttttMAIN MENU");
                printf("n--------------------------------------------------------------------------n
                n");
                printf("Choice No. Choice Name.nn");
                printf(" 1.       Sender's Sitenn 2.           Receiver's Sitenn 3.
                ExitnnnEnter Your Choice : ");
                scanf("%d",&ans);
                switch(ans)
                {
                       case 1:
                                printf("n-----------------------------------------------------------
                                --------------n");


                                                  7
printf("ttt      Sender's Site");
                                printf("n-----------------------------------------------------------
                                --------------n");
                                sender();
                                break;
                      case 2:
                                printf("n-----------------------------------------------------------
                                --------------n");
                                printf("ttt Receiver's Site");
                                printf("n-----------------------------------------------------------
                                --------------n");
                                receiver();
                                break;

                      case 3:
                                exit(1);
                                default:
                                printf("nnINVALID ENTRY!!!");
              }
       }
}

void sender()
{
       printf("Enter the number of rows and columns max(5) : ");
       scanf("%d%d",&m,&n);
       printf("nEnter %d rows and %d columns : n",m,n);
       for(i=1;i<=m;i++)
       {
              printf("nEnter %d row %d bits : ",i,n);
              for(j=1;j<=n;j++)
              {
                     scanf("%d",&a[i][j]);
                     if((a[i][j]!=0)&&(a[i][j]!=1))
                     {
                              printf("nnInvalid Bit......Enter another bit(Only 1's
                              and 0's)!!!");
                              j--;
                     }
              }
       }
       for(i=1;i<=n;i++)
       {
              for(j=1;j<=m;j++)
              {
                     if(a[j][i]==1)



                                                8
{
                              count++;
                      }
              }
              if(count%2==0)
              {
                     a[j][i]=0;
                     count=0;
              }
              else
              {
                     a[j][i]=1;
                     count=0;
              }
      }
      printf("n--------------------------------------------- Output
      -----------------------------------n");
      printf("nThe parity row is : n");
      i=m+1;
      for(j=1;j<=n;j++)
      {
               printf("%dt",a[i][j]);
      }
      printf("nnThe Message after appending : n");
      for(i=1;i<=m+1;i++)
      {
               for(j=1;j<=n;j++)
               {
                        printf("%dt",a[i][j]);
               }
               printf("nn");
      }
}

void receiver()
{
       int count1=0;
       printf("Enter the number of rows and columns max(5) : ");
       scanf("%d%d",&m,&n);
       printf("nEnter %d rows and %d columns : ",m,n);
       for(i=1;i<=m;i++)
       {
              printf("nnEnter %d row %d bits : ",i,n);
              for(j=1;j<=n;j++)
              {
                     scanf("%d",&a[i][j]);



                                              9
if((a[i][j]!=0)&&(a[i][j]!=1))
                    {
                             printf("nnInvalid Bit......Enter another bit(Only 1's
                             and 0's)!!!");
                             j--;
                    }
             }
    }
    printf("n-------------------------------------------- Output
    ----------------------------------------n");
    for(i=1;i<=n;i++)
    {
             for(j=1;j<=m;j++)
             {
                      if(a[j][i]==1)
                      {
                               count++;
                      }
             }
             if(count%2==0)
             {
                      count1++;
                      count=0;

            }
            else
            {
                    count=0;
           }
    }
    if(count1==n)
           printf("nData is correctly received...n");
    else
           printf("nData is not correctly received...n");


}




                                           10
OUTPUT:-

***************** LONGITUDINAL REDUNDANCY CHECK ***************

-----------------------------------------------------------------------------------------------------------
-
                                            MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                             Sender's Site
-----------------------------------------------------------------------------------------------------------
-
Enter the number of rows and columns max(5) : 2 3

Enter 2 rows and 3 columns :

Enter 1 row 3 bits : 1 0 0

Enter 2 row 3 bits : 1 0 1


                                                    11
----------------------------------------------- Output --------------------------------------------------

The parity row is :
0    0    1

The Message after appending :
1   0    0

1        0   1

0        0   1




-----------------------------------------------------------------------------------------------------------
-
                                            MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

    1.           Sender's Site

    2.           Receiver's Site

    3.           Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the number of rows and columns max(5) : 2 3

Enter 2 rows and 3 columns :

Enter 1 row 3 bits : 1 1 0




                                                    12
Enter 2 row 3 bits : 1 0 1

------------------------------------------------ Output -------------------------------------------------

Data is not correctly received...




-----------------------------------------------------------------------------------------------------------
-
                                            MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 3




                                                    13
-3- CYCLIC REDUNDANCY CHECK



#include<stdlib.h>
#include<conio.h>
#include<stdio.h>

void receiver();
void sender();

int i,j,n,g,a1,a[20]={0},d[20]={0},b[20],p[20],s,cnt;

void main()
{
      int choice;
      clrscr();
      printf("*********************** CYCLIC REDUNCDANCY CHECK
      **********************n");
      while(1)
      {
              printf("nn--------------------------------------------------------------------------
              n");


                                                 14
printf("ttttMAIN MENU");
              printf("n--------------------------------------------------------------------------n
              n");
              printf("Choice No. Choice Name.nn");
              printf(" 1.      Sender's Sitenn 2.            Receiver's Sitenn 3.
              ExitnnnEnter Your Choice : ");
              scanf("%d",&choice);

              switch(choice)
              {
                     case 1:
                             printf("n--------------------------- Sender's Site
                             ----------------------------");
                             sender();
                             break;

                      case 2:
                                printf("n------------------------- Receiver's Site
                                ---------------");
                                receiver();
                                break;


                       case 3:
                              exit(1);
              }
       }
}

void sender()
{
       printf("nnEnter total number of data bits : ");
       scanf("%d",&n);
       printf("nEnter %d data bits : nn",n);
       for(i=0;i<n;i++)
       {
              printf("nEnter bit %d: ",i+1);
              scanf("%d",&a[i]);
              if((a[i]!=1)&& (a[i]!=0))
              {
                       printf("nInvalid Entry...Enter only 1's & 0's!!!n");
                       i--;
              }
       }
       printf("nEnter size of Key (! >databits) : ");
       scanf("%d",&g);



                                               15
if(g>n)
{
          printf("nInvalid Entry...Enter value less than databit!!!n");
          printf("nEnter size of Key (! >databits): ");
          scanf("%d",&g);
}
do
{
       printf("nEnter Key values : nn");
       for(j=0;j<g;j++)
       {
               printf("nEnter key bit %d : ",j+1);
               scanf("%d",&d[j]);
               if((d[j]!=1)&& (d[j]!=0))
               {
                        printf("nInvalid Entry...Enter only 1's & 0's!!!n");
                        j--;
               }
       }
}while(d[0]!=1);
printf("n------------------------------------------------------------------n");
printf("ttOutput ");
printf("n------------------------------------------------------------------n");
a1=n+(g-1);
printf("nnThe Message : t");
for(i=0;i<a1;++i)
{
       if(i<a1)
       {
               p[i]=a[i];
       }
       else
       {
               p[i]=0;
       }
}
for(i=0;i<a1;++i)
{
       printf("%d",p[i]);
}
printf("nnThe Divisor : t");
for(j=0;j<g;j++)
{
       printf("%d",d[j]);
}
printf("nnIntermediate CRC : ");



                                     16
for(i=0;i<n;++i)
       {
              if(a[i]==0)
              {
                      printf(" ");
                      for(j=i;j<g+i;++j)
                      {
                              a[j] = a[j]^0;
                              printf("%d",a[j]);
                      }
              }
              else
              {
                      printf(" ");
                      a[i] = a[i]^d[0];
                      a[i+1]=a[i+1]^d[1];
                      a[i+2]=a[i+2]^d[2];
                      a[i+3]=a[i+3]^d[3];
                      printf("%d%d%d",a[i],a[i+1],a[i+2]);
                      printf(" ");
              }
       }
       printf("nnThe Final CRC Bit is : t");
       for(i=n;i<a1;++i)
       {
              printf("%d",a[i]);
       }
       s=n+a1;
       for(i=n;i<s;i++)
       {
              p[i]=a[i];
       }
       printf("n");
       printf("nThe Message transmitted is : ");
       for(i=0;i<a1;i++)
       {
              printf("%d",p[i]);
       }
}
void receiver()
{
       printf("nnEnter total number of data bits: ");
       scanf("%d",&n);
       printf("nEnter %d data bits : nn",n);
       for(i=0;i<n;i++)
       {



                                         17
printf("nEnter bit %d : ",i+1);
        scanf("%d",&a[i]);
        if((a[i]!=1)&& (a[i]!=0))
        {
                 printf("nInvalid Entry...Enter only 1's & 0's!!!n");
                 i--;
        }
}
printf("nEnter size of Key (! >databits): ");
scanf("%d",&g);
if(g>n)
{
        printf("nInvalid Entry...Enter value less than databit!!!n");
        printf("nEnter size of Key (! >databits): ");
        scanf("%d",&g);
}
do
{
        printf("nEnter Key values : nn");
        for(j=0;j<g;j++)
        {
               printf("nEnter key bit %d : ",j+1);
               scanf("%d",&d[j]);
               if((d[j]!=1)&& (d[j]!=0))
               {
                        printf("nInvalid Entry...Enter only 1's & 0's!!!n");
                        j--;
               }
        }
}while(d[0]!=1);
printf("n-------------------------------------------------------------------------------n");
printf("ttOutput");
printf("n--------------------------------------------------------------------------------n");
printf("nnThe Message : t");
for(i=0;i<n;++i)
{
        p[i]=a[i];
}
for(i=0;i<n;i++)
{
        printf("%d",p[i]);
}
printf("nnThe Divisor : t");
for(j=0;j<g;j++)
{
        printf("%d",d[j]);



                                         18
}
a1=n+(g-1);
printf("nnCRC's : ");
for(i=0;i<n;i++)
{
       if(a[i]==0)
       {
               printf(" ");
               for(j=i;j<g+i;j++)
               {
                       a[j] = a[j]^0;
                       printf("%d",a[j]);
               }
       }
       else
       {
               printf(" ");
               a[i] = a[i]^d[0];
               a[i+1]=a[i+1]^d[1];
               a[i+2]=a[i+2]^d[2];
               a[i+3]=a[i+3]^d[3];
               printf("%d%d%d",a[i],a[i+1],a[i+2]);
               printf(" ");
       }
}
printf("nnThe Final CRC is : ");
for(i=n;i<a1;++i)
{
       printf("%d",a[i]);
}
s=n+a1;
cnt=0;
for(i=n;i<s;i++)
{
       p[i]=a[i];
       if(p[i]==1)
       {
               cnt++;
       }
}
printf("n");
if(cnt==0)
{
       printf("nnThe Message is received correctly");
}
else



                                 19
{
                  printf("nnThe Message is not received correctly");
         }
}




Output:-

********************** CYCLIC REDUNCDANCY CHECK ****************

-----------------------------------------------------------------------------------------------------------
-
                                               MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

    1.         Sender's Site

    2.         Receiver's Site

    3.         Exit

Enter Your Choice : 1

----------------------------------------------- Sender's Site
-------------------------------------------


                                                    20
Enter total number of data bits : 5

Enter 5 data bits :


Enter bit 1: 1

Enter bit 2: 0

Enter bit 3: 1

Enter bit 4: 1

Enter bit 5: 0

Enter size of Key (! >databits) : 3

Enter Key values :


Enter key bit 1 : 1

Enter key bit 2 : 1

Enter key bit 3 : 0

-----------------------------------------------------------------------------------------------------------
-
                                                  Output
-----------------------------------------------------------------------------------------------------------
-


The Message : 1011000

The Divisor : 110

Intermediate CRC : 011 001 010 010 010

The Final CRC Bit is : 10

The Message transmitted is : 1011010

-----------------------------------------------------------------------------------------------------------
-



                                                    21
MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 2

---------------------------------------------- Receiver's Site -----------------------------------------

Enter total number of data bits: 5

Enter 5 data bits :


Enter bit 1 : 1

Enter bit 2 : 1

Enter bit 3 : 0

Enter bit 4 : 1

Enter bit 5 : 1

Enter size of Key (! >databits): 3

Enter Key values :

Enter key bit 1 : 1

Enter key bit 2 : 0

Enter key bit 3 : 1

-----------------------------------------------------------------------------------------------------------
-
                                                  Output
-----------------------------------------------------------------------------------------------------------
-



                                                    22
The Message : 11011

The Divisor : 101

CRC's : 011 010 000 000 000

The Final CRC is : 00

The Message is received correctly

-----------------------------------------------------------------------------------------------------------
-
                                               MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 3




                                           -4- CHECKSUM


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int sum(int,int);
int sum1(int,int,int);
void sender();
void receiver();
int a[8],b[8],r[8],c[8],r1[8];


                                                    23
static int carry=0;
int n,i,count=0;
void main()
{
int choice;
clrscr();
printf("n*********************************** CHECKSUM
*********************************n");
while(1)
         {
               printf("nn--------------------------------------------------------------------------
               n");
               printf("ttttMAIN MENU");
               printf("n--------------------------------------------------------------------------n
               n");
               printf("Choice No. Choice Name.nn");
               printf(" 1.       Sender's Sitenn 2.           Receiver's Sitenn 3.
               ExitnnnEnter Your Choice : ");
               scanf("%d",&choice);
               switch(choice)
               {
                      case 1:
                               printf("-------------------------------------------------------------
                               -----------n");
                               printf("ntt Sender's Site ");
                               printf("n-----------------------------------------------------------
                               -------------n");
                               sender();
                               break;

                         case 2:
                                   printf("-------------------------------------------------------------
                                   -----------n");
                                   printf("nttReceiver's Site ");
                                   printf("n-----------------------------------------------------------
                                   -------------n");
                                   receiver();
                                   break;

                         case 3:
                                   exit(1);

                         default:
                                printf("nnINVALID ENTRY");
                }
        }



                                                  24
}

void sender()
{
       printf("nEnter the total number of bits : ");
       scanf("%d",&n);
       printf("nEnter %d bits of Data 1 : nn",n);
       for(i=0;i<n;i++)
       {
              printf("nEnter bit %d: ",i+1);
              scanf("%d",&a[i]);
              if(a[i]!=0 && a[i]!=1)
              {
                      printf("nnInvalid Bit......Enter another value(only 1's and
                      0's)!!!!!");
                      i--;
              }
       }
       printf("n------------------------------------------------------------------n");
       printf("nEnter %d bits of Data 2 : nn",n);
       for(i=0;i<n;i++)
       {
              printf("nEnter bit %d: ",i+1);
              scanf("%d",&b[i]);
              if(b[i]!=0 && b[i]!=1)
              {
                      printf("nnInvalid Bit......Enter another value(only 1's and
                      0's)!!!!!");
                      i--;
              }
       }
       printf("n-----------------------------------------------------------------------------n");
       printf("nttOutput");
       printf("n-----------------------------------------------------------------------------n");
       printf("nnData 1:ttt ");
       for(i=0;i<n;i++)
       {
              printf("%d",a[i]);
       }
       printf("nnData 2:ttt ");
       for(i=0;i<n;i++)
       {
              printf("%d",b[i]);
       }
       for(i=n;i>=0;i--)
       {



                                                 25
r[i]=sum(a[i],b[i]);
      }
      printf("nnResult :tt ");
      for(i=0;i<n;i++)
      {
             printf("%d",r[i]);
      }
      for(i=0;i<n;i++)
      {
             if (r[i]==0)
             {
                      r[i]=1;
             }
             else
             {
                      r[i]=0;
             }
      }
      printf("nn1's Compliment of Result :");
      for(i=0;i<n;i++)
      {
             printf("%d",r[i]);
      }
}

int sum(int x,int y)
{
       if(x==0 && y==0 && carry==0)
       {
                carry=0;
                return 0;
       }
       else if(x==0 && y==0 && carry==1)
       {
                carry=0;
                return 1;
       }
       else if(x==0 && y==1 && carry==0)
       {
                carry=0;
                return 1;
       }
       else if(x==0 && y==1 && carry==1)
       {
                carry=1;
                return 0;



                                       26
}
       else if(x==1 && y==0 && carry==0)
       {
                carry=0;
                return 1;
       }
       else if(x==1 && y==0 && carry==1)
       {
                carry=1;
                return 0;
       }
       else if(x==1 && y==1 && carry==0)
       {
                carry=1;
                return 0;
       }
       else if(x==1 && y==1 && carry==1)
       {
                carry=1;
                return 1;
       }
       else
       return(1);
}

void receiver()
{
       printf("nEnter the total number of bits : ");
       scanf("%d",&n);
       printf("nEnter %d bits of Data 1 : nn",n);
       for(i=0;i<n;i++)
       {
              printf("nEnter bit %d: ",i+1);
              scanf("%d",&a[i]);
              if(a[i]!=0 && a[i]!=1)
              {
                      printf("nnInvalid Bit......Enter another value(only 1's and
                      0's)!!!!!");
                      i--;
              }
       }
       printf("n------------------------------------------------------------------n");
       printf("nEnter %d bits of Data 2 : nn",n);
       for(i=0;i<n;i++)
       {
              printf("nEnter bit %d: ",i+1);



                                             27
scanf("%d",&b[i]);
        if(b[i]!=0 && b[i]!=1)
        {
                printf("nnInvalid Bit......Enter another value(only 1's and
                0's)!!!!!");
                i--;
        }
}
printf("n------------------------------------------------------------------n");
printf("nEnter %d bits of Checksum : nn",n);
for(i=0;i<n;i++)
{
       printf("nEnter bit %d: ",i+1);
       scanf("%d",&c[i]);
       if(c[i]!=0 && c[i]!=1)
       {
                printf("nnInvalid Bit......Enter another value(only 1's and
                0's)!!!!!");
                i--;
       }
}
printf("n----------------------------------------------------------------------------------");
printf("nttOutput");
printf("n----------------------------------------------------------------------------------");
printf("nnData 1:ttt ");
for(i=0;i<n;i++)
{
       printf("%d",a[i]);
}
printf("nnData 2:ttt ");
for(i=0;i<n;i++)
{
       printf("%d",b[i]);
}
printf("nnChecksum:tt ");
for(i=0;i<n;i++)
{
       printf("%d",c[i]);
}
for(i=n;i>=0;i--)
{
       r1[i]=sum1(a[i],b[i],c[i]);
}
printf("nnResult :tt ");
for(i=0;i<n;i++)
{



                                          28
printf("%d",r1[i]);
      }
      for(i=0;i<n;i++)
      {
             if (r1[i]==0)
             {
                      r1[i]=1;
             }
             else
             {
                      r1[i]=0;
             }
      }
      printf("nn1's Compliment of Result :");
      for(i=0;i<n;i++)
      {
             printf("%d",r1[i]);
      }
      for(i=0;i<n;i++)
      {
             if(r1[i]==0)
             {
                      count=count+1;
             }
      }
      if(count==n)
      {
             printf("nnData is ERROR free, hence ACCEPTED... ");
      }
      else
      {
             printf("nnData is NOT ERROR free, hence NOT ACCEPTED...");
      }
}

int sum1(int x,int y,int z)
{
       if(x==0 && y==0 && z==0 && carry==0)
       {
                carry=0;
                return(0);
       }
       else if(x==1 && y==0 && z==0 && carry==0)
       {
                carry=0;
                return(1);



                                    29
}
else if(x==0 && y==1 && z==0 && carry==0)
{
         carry=0;
         return(1);
}
else if(x==1 && y==1 && z==0 && carry==0)
{
         carry=1;
         return(0);
}
else if(x==0 && y==0 && z==1 && carry==0)
{
         carry=0;
         return(1);
}
else if(x==1 && y==0 && z==1 && carry==0)
{
         carry=1;
         return(0);
}
else if(x==0 && y==1 && z==1 && carry==0)
{
         carry=1;
         return(0);
}
else if(x==1 && y==1 && z==1 && c==0)
{
         carry=1;
         return(1);
}
else if(x==0 && y==0 && z==0 && carry==1)
{
         carry=0;
         return(1);
}
else if(x==1 && y==0 && z==0 && carry==1)
{
         carry=1;
         return(0);
}
else if(x==0 && y==1 && z==0 && carry==1)
{
         carry=1;
         return(0);
}



                             30
else if(x==1 && y==1 && z==0 && carry==1)
         {
                  carry=1;
                  return(1);
         }
         else if(x==0 && y==0 && z==1 && carry==1)
         {
                  carry=1;
                  return(0);
         }
         else if(x==1 && y==0 && z==1 && carry==1)
         {
                  carry=1;
                  return(1);
         }
         else if(x==0 && y==1 && z==1 && carry==1)
         {
                  carry=1;
                  return(1);
         }
         else
                  return(1);
}




Output:-

****************************** CHECKSUM *****************************

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.



                                                    31
1.            Sender's Site

  2.            Receiver's Site

  3.            Exit

Enter Your Choice : 1
-----------------------------------------------------------------------------------------------------------
-
                                             Sender's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the total number of bits : 5

Enter 5 bits of Data 1 :


Enter bit 1: 1

Enter bit 2: 0

Enter bit 3: 1

Enter bit 4: 1

Enter bit 5: 0

-----------------------------------------------------------------------------------------------------------
-

Enter 5 bits of Data 2 :


Enter bit 1: 0

Enter bit 2: 1

Enter bit 3: 0
Enter bit 4: 0

Enter bit 5: 1

-----------------------------------------------------------------------------------------------------------
-



                                                    32
Output
-----------------------------------------------------------------------------------------------------------
-

Data 1:                10110

Data 2:                01001

Result :               11111

1's Compliment of Result :00000

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Site

  2.            Receiver's Site

  3.            Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the total number of bits : 5

Enter 5 bits of Data 1 :


Enter bit 1: 0

Enter bit 2: 0

Enter bit 3: 0

Enter bit 4: 0



                                                    33
Enter bit 5: 1
-----------------------------------------------------------------------------------------------------------
-

Enter 5 bits of Data 2 :


Enter bit 1: 1

Enter bit 2: 2

Invalid Bit......Enter another value(only 1's and 0's)!!!!!

Enter bit 2: 1

Enter bit 3: 1

Enter bit 4: 1

Enter bit 5: 0

-----------------------------------------------------------------------------------------------------------
-

Enter 5 bits of Checksum :


Enter bit 1: 0

Enter bit 2: 0

Enter bit 3: 0

Enter bit 4: 0

Enter bit 5: 0

-----------------------------------------------------------------------------------------------------------
-
                                               Output
-----------------------------------------------------------------------------------------------------------
-

Data 1:                          00001




                                                    34
Data 2:                          11110

Checksum:                        00000

Result :                         11111

1's Compliment of Result :00000

Data is ERROR free, hence ACCEPTED...

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Site

  2.            Receiver's Site

  3.            Exit

Enter Your Choice : 3




                                                    35
-5- HAMMING CODE


#include<stdio.h>
#include<conio.h>
#include<math.h>
void sender();
void receiver();
int a,m,r,i,count=0,n,count1=0;
void main()
{
       int ans;
       clrscr();
       printf("nn*********************** HAMMING CODE
       ***********************nn");
       while(1)
       {
               printf("n--------------------------------------------------------------------------n
               ");
               printf("ttttnMAIN MENU");
               printf("n--------------------------------------------------------------------------n
               n");
               printf("Choice No. Choice Name.nn");
               printf(" 1.        Sender's Sitenn 2.          Receiver's Sitenn 3.
               ExitnnnEnter Your Choice : ");
               scanf("%d",&ans);
               switch(ans)
               {
                      case 1:
                                printf("n-----------------------------------------------------------
                                --------------n");
                                printf("ttt      Sender's Site");
                                printf("n-----------------------------------------------------------
                                --------------n");
                                sender();
                                break;
                      case 2:
                                printf("n-----------------------------------------------------------
                                --------------n");
                                printf("ttt Receiver's Site");


                                                 36
printf("n-----------------------------------------------------------
                                --------------n");
                                receiver();
                                break;
                      case 3:
                             exit(1);
                      default:
                             printf("nnINVALID ENTRY!!!");
              }
       }
}

void sender()
{
       int data[20];
       printf("Enter the number of data bits (MAX 11) : ");
       scanf("%d",&m);
       for(i=0;i<20;i++)
              data[i]=0;
       while(pow(2,r)-r<m+1)
              r++;
       printf("nThe Parity Bits are : %d n",r);
       for(i=1;i<9;i++)
       {
              if(i==1||i==2||i==4||i==8)
              {
                      data[i]=4;
              }
       }
       printf("nEnter %d data bits : ",m);
       for(i=1;i<=m+r;i++)
       {
              if(i==3||i==5||i==6||i==7||i==9||i==10||i==11||i==12||i==13||i==14||i==15||
i==16)
              {
                      scanf("%d",&data[i]);
                      if (data[i]!=0&&data[i]!=1)
                      {
                              printf("Invalid Entry!!! Enter only 0's and 1's");
                              i--;
                      }
              }
       }
       printf("nData Is : ");
       for(i=1;i<=m+r;i++)
       {



                                               37
printf("%d ",data[i]);
}
for(i=1;i<=m+r;i++)
{
       if(data[i]==4)
       {
               a=i;
       }
       if(a==1)
       {
               count=data[3]+data[5]+data[7]+data[9]+data[11];
               if(count%2==0)
                        data[a]=0;
               else
                        data[a]=1;
       }
       if(a==2)
       {
               count=data[3]+data[6]+data[7]+data[10]+data[11];
               if(count%2==0)
                        data[a]=0;
               else
                        data[a]=1;
       }
       if(a==4)
       {
               count=data[5]+data[6]+data[7];
               if(count%2==0)
                        data[a]=0;
               else
                        data[a]=1;
       }
       if(a==8)
       {
               count=data[9]+data[10]+data[11];
               if(count%2==0)
                        data[a]=0;
               else
                        data[a]=1;
       }
}
printf("nn-----------------------------------------------------------------------------n");
printf("tttOutput");
printf("n--------------------------------------------------------------------------------n");
printf("nnNew Data To Be Sent Is : ");
for(i=1;i<=m+r;i++)



                                         38
printf("%d ",data[i]);
}




void receiver()
{
       int data[20],temp;
       printf("nEnter the number of data bits : ");
       scanf("%d",&m);
       for(i=0;i<20;i++)
              data[i]=0;
       printf("nEnter %d data bits : ",m);
       for(i=1;i<=m;i++)
       {
              scanf("%d",&data[i]);
              if (data[i]!=0&&data[i]!=1)
              {
                      printf("Invalid Entry!!! Enter only 0's and 1's");
                      i--;
              }
       }
       for(i=1;i<=m;i++)
       {
              if(i==1)
              {
                      count=data[1]+data[3]+data[5]+data[7]+data[9]+data[11];
                      if(count%2==0)
                      {
                             data[i]=data[i];
                      }
                      else
                      {
                             count1=count1+i;
                      }
              }
              if(i==2)
              {
                      count=data[2]+data[3]+data[6]+data[7]+data[10]+data[11];
                      if(count%2==0)
                      {
                             data[i]=data[i];
                      }
                      else
                      {



                                       39
count1=count1+i;
               }
        }
        if(i==4)
        {
               count=data[4]+data[5]+data[6]+data[7];
               if(count%2==0)
               {
                      data[i]=data[i];
               }
               else
               {
                      count1=count1+i;
               }
        }
        if(i==8)
        {
               count=data[8]+data[9]+data[10]+data[11];
               if(count%2==0)
               {
                      data[i]=data[i];
               }
               else
               {
                      count1=count1+i;
               }
        }
}
printf("nn-----------------------------------------------------------------------------n");
printf("ttOutputn");
printf("n--------------------------------------------------------------------------------n");
if(count1>0)
{
       if(count1>m)
       {
               printf("nError Is At Position %d",count1);
               printf("nnOOPS!!! Position is not availablen");
       }
       else
       {
               printf("nError Is At Position %d",count1);
               if(data[count1]==0)
                        data[count1]=1;
               else
                        data[count1]=0;
               printf("nCorrect Code Word : ");



                                         40
for(i=1;i<=m;i++)
                 {
                        printf("%d ",data[i]);
                 }
           }
    }
    else
    {
           printf("nReceived Data Is ERROR FREE... n");
           printf("nCorrect Code Word : ");
           for(i=1;i<=m;i++)
           {
                  printf("%d ",data[i]);
           }
    }
}




                                    41
Output:-

***************************** HAMMING CODE *************************

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Site

  2.            Receiver's Site

  3.            Exit

Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                              Sender's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the number of data bits (MAX 11) : 7

The Parity Bits are : 4

Enter 7 data bits : 1 0 0 1 0 1 1

Data Is : 4 4 1 4 0 0 1 4 0 1 1

-----------------------------------------------------------------------------------------------------------
-
                                                 Output
-----------------------------------------------------------------------------------------------------------
-



                                                    42
New Data To Be Sent Is : 1 0 1 1 0 0 1 0 0 1 1

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.            Sender's Site

  2.            Receiver's Site

  3.            Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the number of data bits : 11

Enter 11 data bits : 1 0 1 1 0 0 1 0 1 1 1

-----------------------------------------------------------------------------------------------------------
-
                                                 Output
-----------------------------------------------------------------------------------------------------------
-

Error Is At Position 9

Correct Code Word : 1 0 1 1 0 0 1 0 0 1 1

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.




                                                    43
1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 3




                                       -6- BIT STUFFING


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void sender();
void receiver();
int data[20],i,j,n,count=0;
void main()
{
       int choice;
       clrscr();
       printf("********************************** BIT STUFFING
       ********************************");
       while(1)
       {
                printf("nn--------------------------------------------------------------------------
                n");
                printf("ttttMAIN MENU");
                printf("n--------------------------------------------------------------------------n
                n");
                printf("Choice No. Choice Name.nn");
                printf(" 1.      Sender's Sitenn 2.            Receiver's Sitenn 3.
                ExitnnnEnter Your Choice : ");
                scanf("%d",&choice);


                                                  44
switch(choice)
              {
                     case 1:
                             printf("n-----------------------------------------------------------
                             --------------n");
                             printf("ttt      Sender's Site");
                             printf("n-----------------------------------------------------------
                             --------------n");
                             sender();
                             break;
                     case 2:
                             printf("n-----------------------------------------------------------
                             --------------n");
                             printf("ttt Receiver's Site");
                             printf("n-----------------------------------------------------------
                             --------------n");
                             receiver();
                             break;
                     case 3:
                               exit(1);
                     default:
                               printf("nInvalid Choice!!!");
              }
       }
}

void sender()
{
       printf("nEnter the length of your code : ");
       scanf("%d",&n);
       for(i=0;i<n;i++)
       {
              printf("nEnter %d bit : ",i+1);
              scanf("%d",&data[i]);
       }
       printf("nnThe Original Data entered : ");
       for(i=0;i<n;i++)
       {
              printf("%d ",data[i]);
       }
       i=0;
       while(i<n)
       {
              if(data[i]==1)
              {
                      i++;



                                              45
count++;
                        if(count==5)
                        {
                               for(j=n+1;j>i;j--)
                               {
                                      data[j]=data[j-1];
                               }
                               data[i]=0;
                        }
               }
               else
               {
                        i++;
                        count=0;
              }
       }
       printf("nn--------------------------------------------------------------------------n");
       printf("ttt Outputn");
       printf("-------------------------------------------------------------------------------n");
       printf("nnData After Stuffing : ");
       for(i=0;i<n+1;i++)
       {
              printf("%d ",data[i]);
       }
}

void receiver()
{
       printf("nEnter the length of your code : ");
       scanf("%d",&n);
       for(i=0;i<n;i++)
       {
              printf("nEnter %d bit : ",i+1);
              scanf("%d",&data[i]);
       }
       printf("nnThe Original Data entered : ");
       for(i=0;i<n;i++)
       {
              printf("%d ",data[i]);
       }
       i=0;
       while(i<n)
       {
              if(data[i]==1)
              {
                      i++;



                                                 46
count++;
                     if(count==5)
                     {
                            for(j=i;j<n+1;j++)
                            {
                                    data[j]=data[j+1];

                             }
                             n--;
                     }
            }
            else
            {
                     i++;
                     count=0;
            }
    }
    printf("nn--------------------------------------------------------------------------------");
    printf("nttt Output");
    printf("n--------------------------------------------------------------------------------n");
    printf("nData After De-Stuff : ");
    for(i=0;i<n;i++)
    {
           printf("%d ",data[i]);
    }
}




                                             47
Output:-

****************************** BIT STUFFING **************************

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                              Sender's Site
-----------------------------------------------------------------------------------------------------------
-



                                                    48
Enter the length of your code : 11

Enter 1 bit : 0

Enter 2 bit : 1

Enter 3 bit : 1

Enter 4 bit : 1

Enter 5 bit : 1

Enter 6 bit : 1

Enter 7 bit : 1

Enter 8 bit : 0

Enter 9 bit : 1

Enter 10 bit : 1

Enter 11 bit : 0

The Original Data entered : 0 1 1 1 1 1 1 0 1 1 0

-----------------------------------------------------------------------------------------------------------
-
                                                 Output
-----------------------------------------------------------------------------------------------------------
-

Data After Stuffing : 0 1 1 1 1 1 0 1 0 1 1 0

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site




                                                    49
3.           Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the length of your code : 11

Enter 1 bit : 0

Enter 2 bit : 1

Enter 3 bit : 1

Enter 4 bit : 1

Enter 5 bit : 1

Enter 6 bit : 1

Enter 7 bit : 0

Enter 8 bit : 0

Enter 9 bit : 1

Enter 10 bit : 0

Enter 11 bit : 1

The Original Data entered : 0 1 1 1 1 1 0 0 1 0 1

-----------------------------------------------------------------------------------------------------------
-
                                                 Output
-----------------------------------------------------------------------------------------------------------
-

Data After De-Stuff : 0 1 1 1 1 1 0 1 0 1

-----------------------------------------------------------------------------------------------------------
-



                                                    50
MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit

Enter Your Choice : 3




                                        -7- WALSH MATRIX


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void stn1();
void stn2();
void stn4();
int n,i,j;
void main()
{


                                                    51
clrscr();
printf("n***************** CHIPPING SEQUENCE USING WALSH
MATRIX *********************nn");
while(1)
{
        printf("n--------------------------------------------------------------------------n
        ");
        printf("ttttMAIN MENU");
        printf("n--------------------------------------------------------------------------n
        n");
        printf("Choice No. Station No.nn");
        printf(" 1.       Station 1nn 2.         Station 2nn 3.           Station 4nn
        4.    ExitnnEnter Your Choice : ");
        scanf("%d",&n);
        switch(n)
        {
               case 1:
                        printf("n-----------------------------------------------------------
                        --------------n");
                        printf("ttt      Station 1");
                        printf("n-----------------------------------------------------------
                        --------------n");
                        stn1();
                        break;
               case 2:
                        printf("n-----------------------------------------------------------
                        --------------n");
                        printf("ttt      Station 2");
                        printf("n-----------------------------------------------------------
                        --------------n");
                        stn2();
                        break;
               case 3:
                        printf("n-----------------------------------------------------------
                        --------------n");
                        printf("ttt      Station 4");
                        printf("n-----------------------------------------------------------
                        --------------n");
                        stn4();
                        break;
               case 4:
                        exit(1);
               default:
                        printf("nnInvalid Entry!!!");
        }
}



                                         52
}

void stn1()
{
       int w1;
       printf("nYour Code For Station 1 : 1n");
}

void stn2()
{
       int w2[2][2];
       for(i=0;i<2;i++)
       {
              for(j=0;j<2;j++)
              {
                     if ((i==1) && (j==1))
                     {
                             w2[i][j]=-1;
                     }
                     else
                     {
                             w2[i][j]=1;
                     }
              }
       }
       printf("nYour Code For Station 2 : nn");
       for(i=0;i<2;i++)
       {
              for(j=0;j<2;j++)
              {
                     printf("%d ",w2[i][j]);
              }
              printf("n");
       }
}

void stn4()
{
       int w4[4][4];
       for(i=0;i<4;i++)
       {
              for(j=0;j<4;j++)
              {
                     if(i==0)
                     {
                            w4[i][j]=1;



                                          53
}
                 else if(j==0)
                 {
                          w4[i][j]=1;
                 }
                 else if((i==1)&&(j==1))
                 {
                          w4[i][j]=-1;
                 }
                 else if((i==1)&&(j==3))
                 {
                          w4[i][j]=-1;
                 }
                 else if((i==2)&&(j==2))
                 {
                          w4[i][j]=-1;
                 }
                 else if((i==2)&&(j==3))
                 {
                          w4[i][j]=-1;
                 }
                 else if((i==3)&&(j==1))
                 {
                          w4[i][j]=-1;
                 }
                 else if((i==3)&&(j==2))
                 {
                          w4[i][j]=-1;
                 }
                 else
                 {
                          w4[i][j]=1;
                 }
          }
    }
    printf("nYour Code For Station 4 : nn");
    for(i=0;i<4;i++)
    {
           for(j=0;j<4;j++)
           {
                  printf("%dt",w4[i][j]);
           }
           printf("n");
    }
}




                                     54
Output:-

************** CHIPPING SEQUENCE USING WALSH MATRIX ***********

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Station No.

  1.             Station 1


                                                    55
2.             Station 2

  3.             Station 4

  4.             Exit

Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                                Station 1
-----------------------------------------------------------------------------------------------------------
-

Your Code For Station 1 : 1

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Station No.

  1.             Station 1

  2.             Station 2

  3.             Station 4

  4.             Exit

Enter Your Choice : 5

Invalid Entry!!!



-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Station No.



                                                    56
1.             Station 1

  2.             Station 2

  3.             Station 4

  4.             Exit

Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                                Station 2
-----------------------------------------------------------------------------------------------------------
-

Your Code For Station 2 :

1 1
1 -1

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Station No.

  1.             Station 1

  2.             Station 2

  3.             Station 4

  4.             Exit

Enter Your Choice : 3




                                                    57
-----------------------------------------------------------------------------------------------------------
-
                                                Station 4
-----------------------------------------------------------------------------------------------------------
-

Your Code For Station 4 :

1         1    1       1
1        -1    1      -1
1         1   -1      -1
1        -1   -1       1

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Station No.

    1.             Station 1

    2.             Station 2

    3.             Station 4

    4.             Exit

Enter Your Choice : 4




                                                    58
-8- BIT COMPRESSION


#include<stdio.h>
#include<conio.h>
void main()
{
       int i,j,a[20],cnt1,cnt2,n;
       clrscr();
       printf("n************************** BIT COMPRESSION
       ************************************n");
       printf("nnEnter the length of Data ( <= 20 ) : ");
       scanf("%d",&n);
       printf("nnEnter %d Bits : n",n);
       for(i=1;i<=n;i++)
       {
                printf("nnEnter Bit %d:",i);
                scanf("%d",&a[i]);
       }
       printf("nnOriginal Data : ");
       for(i=1;i<=n;i++)
       {
                printf("%d ",a[i]);
       }
       cnt1=0;
       cnt2=0;
       printf("nn-----------------------------------------------------------------------------n");
       printf("ttt      Output");
       printf("n-------------------------------------------------------------------------------n");
       printf("nThe Data Contains : n");
       for(i=1;i<=n;i++)
       {
                if(a[i]==1)
                {
                        if(cnt2!=0)
                        {
                                printf("nn 0's : %d",cnt2);
                                cnt2=0;
                        }
                        cnt1++;

                }


                                                 59
if(a[i]==0)
           {
                   if(cnt1!=0)
                   {
                           printf("nn 1's : %d",cnt1);
                           cnt1=0;
                   }
                   cnt2++;
           }
    }
    if(cnt1==0)
           printf("nn 0's : %d",cnt2);
    if(cnt2==0)
           printf("nn 1's : %d",cnt1);
    getch();
}




                                       60
Output:-

************************** BIT COMPRESSION **************************

Enter the length of Data : 11

Enter 11 Bits :

Enter Bit 1 : 1

Enter Bit 2 : 1

Enter Bit 3 : 0

Enter Bit 4 : 0

Enter Bit 5 : 0

Enter Bit 6 : 0

Enter Bit 7 : 1

Enter Bit 8 : 1

Enter Bit 9 : 0

Enter Bit 10 : 1

Enter Bit 11 :1

Original Data : 1 1 0 0 0 0 1 1 0 1 1

-----------------------------------------------------------------------------------------------------------
-
                                                 Output
-----------------------------------------------------------------------------------------------------------
-
The Data Contains :

1's : 2

0's : 4


                                                    61
1's : 2

0's : 1

1's : 2
                          -9- MONOALPHABETIC ENCRYPTION


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>

void sender();
void receiver();
void main()
{
       int choice;
       clrscr();
       printf("n************************** MONOALPHABETIC
       ENCRYPTION ***********************n");
       while(1)
       {
               printf("nn--------------------------------------------------------------------------
               n");
               printf("ttttMAIN MENU");
               printf("n--------------------------------------------------------------------------n
               n");
               printf("Choice No. Choice Name.nn");
               printf(" 1.       Sender's Sitenn 2.           Receiver's Sitenn 3.
               ExitnnnEnter Your Choice : ");
               scanf("%d",&choice);
               switch(choice)
               {
                      case 1:
                               printf("n-----------------------------------------------------------
                               --------------n");
                               printf("ttt      Sender's Site");
                               printf("n-----------------------------------------------------------
                               --------------n");
                               sender();
                               break;
                      case 2:
                               printf("n-----------------------------------------------------------
                               --------------n");


                                                 62
printf("ttt        Receiver's Site");

                                   printf("n-----------------------------------------------------------
                                   --------------n");
                                   receiver();
                                   break;

                         case 3:
                                exit(1);
                         default:
                                printf("nnInvalid Entry");
                }
        }
}

void sender()
{
       int i,n;
       char *ptr,*str,*str1;
       printf("nEnter the Plain Text : ");
       scanf("%s",str);
       printf("nEnter the Charter difference : ");
       scanf("%d",&n);
       printf("n-----------------------------------------------------------------------nn");
       printf("nPlain Text : ");
       printf("%s",str);
       printf("nnCipher Text After Encryption : ");
       for(i=0;str[i]!='0';i++)
       {
                if((str[i]>=65 && str[i]<=90-n) || (str[i]>=97 && str[i]<=122-n))
                {
                         ptr[i]=str[i]+n;
                }
                else if((str[i]>90-n && str[i]<=90)||(str[i]>122-n && str[i]<=122))
                {
                         ptr[i]=str[i]-26+n;
                }
                else
                {
                         ptr[i]=str[i];
                }
       }
       ptr[i]='0';
       printf("%s",ptr);
}




                                                    63
void receiver()
{
       int i,n;
       char *ptr,*str,*str1;
       printf("nEnter the Cipher text : ");
       scanf("%s",ptr);
       printf("nEnter the Charter difference : ");
       scanf("%d",&n);
       printf("n-----------------------------------------------------------------------nn");
       printf("nCipher Text : ");
       printf("%s",ptr);
       printf("nnPlain text After Decryption : ");
       for(i=0;ptr[i]!='0';i++)
       {
                if((ptr[i]>=65+n && ptr[i]<=90) || (ptr[i]>=97+n && ptr[i]<=122))
                {
                         str1[i]=ptr[i]-n;
                }
                else if((ptr[i]>=65 && ptr[i]<=65+n)||(ptr[i]>=97 && ptr[i]<=97+n))
                {
                         str1[i]=ptr[i]+26-n;
                }
                else
                {
                         str1[i]=ptr[i];
                }
       }
       str1[i]='0';
       printf("%s",str1);
}




                                               64
Output:-

********************* MONOALPHABETIC ENCRYPTION ****************

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit


Enter Your Choice : 1

-----------------------------------------------------------------------------------------------------------
-
                                              Sender's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the Plain Text : TARANNUM

Enter the Charter difference : 5

-----------------------------------------------------------------------------------------------------------
-

Plain Text : TARANNUM

Cipher Text After Encryption : YFWFSSZR




                                                    65
-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site

  3.           Exit


Enter Your Choice : 2

-----------------------------------------------------------------------------------------------------------
-
                                             Receiver's Site
-----------------------------------------------------------------------------------------------------------
-

Enter the Cipher text : yfwfsszr

Enter the Charter difference : 5

-----------------------------------------------------------------------------------------------------------
-

Cipher Text : yfwfsszr

Plain text After Decryption : tarannum

-----------------------------------------------------------------------------------------------------------
-
                                             MAIN MENU
-----------------------------------------------------------------------------------------------------------
-

Choice No. Choice Name.

  1.           Sender's Site

  2.           Receiver's Site




                                                    66
3.          Exit


Enter Your Choice : 3




                          -10- POLYALPHABETIC ENCRYPTION


#include <stdio.h>
#include <string.h>

void main()
{
      unsigned int i,j=1,k;
      char input[257],key[33],l[257];
      clrscr();
      k=65;
      printf("n************************** POLYALPHABETIC
      ENCRYPTION ***************************n");
      printf("ntttt VIGENERE TABLE nn");
      printf("------------------------------------------------------------------------------nn");
      while (j <= 26)
      {
              for (i=j; i<j+26; i++)
              {
                      if (k >90)
                               k = k - 26;
                      printf("%c ",k );
                      k++;
              }
              printf("n");


                                                 67
j++;
            k++;
    }
    printf("n----------------------------------------------------------------------------nn");
    printf("nEnter Plain Text : ");
    gets(input);
    printf("nEnter Encryption Key : ");
    gets(key);
    printf("n----------------------------------------------------------------------------n");
    printf("nKEY : t       ");
    for(i=0,j=0;i<strlen(input);i++,j++)
    {

            if(j>=strlen(key))
            {
             j=0;
            }
            l[i]=key[j];
    }
    for(i=0;i<strlen(input);i++)
    {
           printf("%c",l[i]);
    }
    printf("nnPlain Text : ");
    printf("%s",input);
    printf("nnCipher Text : ");
    for(i=0,j=0;i<strlen(input);i++,j++)
    {
             if(j>=strlen(key))
             {
                   j=0;
             }
              printf("%c",65+(((toupper(input[i])-65)+(toupper(key[j])-65))
              %26));
    }
    getch();
}




                                             68
Output:-

********************* POLYALPHABETIC ENCRYPTION *****************


                                        VIGENERE TABLE

-----------------------------------------------------------------------------------------------------------
-

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
P Q R S T U V W X Y Z A B C D E F G H I J K L M N O


                                                    69
Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
Z A B C D E F G H I J K L M N O P Q R S T U V W X Y

-----------------------------------------------------------------------------------------------------------
-

Enter Plain Text : HIWORLD

Enter Encryption Key : ME

-----------------------------------------------------------------------------------------------------------
-



KEY :           MEMEMEM

Plain Text : HIWORLD

Cipher Text : TMISDPP




                                                    70
-11- RSA ALGORITHM


#include<stdio.h>
#include<conio.h>
#include<math.h>

int phi,m,n,e,d,c,flg;
void check()
{
        int i;
        for(i=3;e%i==0 && phi%i==0;i+2)
        {
                flg = 1;
                return;
        }
        flg = 0;
        }

void encrypt()
{
       int i;
       c = 1;


                                     71
for(i=0;i<e;i++)
               c=c*m%n;
               c=c%n;
        printf("nEncrypted Plain Text : %d",c);
        printf("nn----------------------------------------------------------------------n");
}

void decrypt()
{
       int i;
       m = 1;
       for(i=0;i< d;i++)
              m=m*c%n;
              m = m%n;
       printf("nDecrypted Cipher Text : %d",m);
}

void main()
{
      int p,q,s;
      clrscr();
      printf("n************************* RSA ALGORITHM
      *****************************nn");
      printf("nEnter Two Relative Prime Numbers : ");
      scanf("%d%d",&p,&q);
      n = p*q;
      phi=(p-1)*(q-1);
      printf("nF(n)t = %d",phi);
      do
      {
              printf("nnEnter value for e : ");
              scanf("%d",&e);
              check();
      }while(flg==1);
      d = 1;
      do
      {
              s = (d*e)%phi;
              d++;
      }while(s!=1);
      d = d-1;
      printf("n-----------------------------------------------------------------------------nn");
      printf("nPublic Keyt: {%d,%d}",e,n);
      printf("nnPrivate Keyt: {%d,%d}",d,phi);
      printf("nn---------------------------------------------------------------------------nn");
      printf("nEnter The Plain Text : ");



                                                 72
scanf("%d",&m);
         encrypt();
         printf("nnEnter the Cipher text : ");
         scanf("%d",&c);
         decrypt();
         getch();
}




Output:-

**************************** RSA ALGORITHM *************************

Enter Two Relative Prime Numbers : 7 11

F(n)     = 60

Enter value for e : 13

-----------------------------------------------------------------------------------------------------------
-

Public Key        : {13,77}

Private Key        : {37,60}

-----------------------------------------------------------------------------------------------------------
-

Enter The Plain Text : 7

Encrypted Plain Text : 35


                                                    73
-----------------------------------------------------------------------------------------------------------
-

Enter the Cipher text : 35

Decrypted Cipher Text : 7




                              -12-DIJKSTRA’S SHORTEST PATH

#include<stdio.h>
#include<conio.h>

#define MAX 10
#define TEMP 0
#define PERM 1
#define infinity 9999

struct node
{
       int predecessor;
       int dist;
       int status;
};

int adj[MAX][MAX];
int n;
void main()


                                                    74
{
       int i,j;
       int source,dest;
       int path[MAX];
       int shortdist,count;
       clrscr();
       printf("************************ DIJKSTRA'S SHORTEST PATH
       **********************");
       create_graph();
       printf("The adjacency matrix is :n");
       display();
       while(1)
       {
                printf("nEnter source node(0 to quit) : ");
                scanf("%d",&source);
                printf("nEnter destination node(0 to quit) : ");
                scanf("%d",&dest);

              if(source==0 || dest==0)
                     exit(1);

              count = findpath(source,dest,path,&shortdist);
              if(shortdist!=0)
              {
                      printf("nShortest distance is : %dn", shortdist);
                      printf("nShortest Path is : ");
                      for(i=count;i>1;i--)
                             printf("%d->",path[i]);
                      printf("%d",path[i]);
                      printf("n");
              }
              else
                      printf("nThere is no path from source to destination
noden");
      }
      getch();
}

create_graph()
{
       int i,max_edges,origin,destin,wt;

       printf("Enter number of vertices : ");
       scanf("%d",&n);
       max_edges=n*(n-1);




                                           75
for(i=1;i<=max_edges;i++)
       {
              printf("nEnter edge %d(0 0 to quit) : ",i);
              scanf("%d %d",&origin,&destin);
              if((origin==0) && (destin==0))
                      break;
              printf("nEnter weight for this edge : ");
              scanf("%d",&wt);
              if( origin > n || destin > n || origin<=0 || destin<=0)
              {
                      printf("nInvalid edge!n");
                      i--;
              }
              else
                      adj[origin][destin]=wt;
       }
}

display()
{
       int i,j;
       for(i=1;i<=n;i++)
       {
                for(j=1;j<=n;j++)
                       printf("%3d",adj[i][j]);
                printf("n");
       }

}

int findpath(int s,int d,int path[MAX],int *sdist)
{
        struct node state[MAX];
        int i,min,count=0,current,newdist,u,v;
        *sdist=0;
        for(i=1;i<=n;i++)
        {
                state[i].predecessor=0;
                state[i].dist = infinity;
                state[i].status = TEMP;
        }
        state[s].predecessor=0;
        state[s].dist = 0;
        state[s].status = PERM;
        current=s;
        while(current!=d)



                                            76
{
          for(i=1;i<=n;i++)
          {
                 if ( adj[current][i] > 0 && state[i].status == TEMP )
                 {
                          newdist=state[current].dist + adj[current][i];
                          if( newdist < state[i].dist )
                          {
                                  state[i].predecessor = current;
                                  state[i].dist = newdist;
                          }
                 }
          }
          min=infinity;
          current=0;
          for(i=1;i<=n;i++)
          {
                 if(state[i].status == TEMP && state[i].dist < min)
                 {
                          min = state[i].dist;
                          current=i;
                 }
          }

          if(current==0)
                 return 0;
          state[current].status=PERM;
    }
    while( current!=0 )
    {
           count++;
           path[count]=current;
           current=state[current].predecessor;
    }
    for(i=count;i>1;i--)
    {
           u=path[i];
           v=path[i-1];
           *sdist+= adj[u][v];
    }
    return (count);
}




                                      77
Output:-

********************** DIJKSTRA'S SHORTEST PATH *******************

Enter number of vertices : 6

Enter edge 1(0 0 to quit) : 1 2

Enter weight for this edge : 6

Enter edge 2(0 0 to quit) : 2 5

Enter weight for this edge : 3

Enter edge 3(0 0 to quit) : 2 6

Enter weight for this edge : 2

Enter edge 4(0 0 to quit) : 3 4


                                  78
Enter weight for this edge : 2

Enter edge 5(0 0 to quit) : 3 6

Enter weight for this edge : 3

Enter edge 6(0 0 to quit) : 4 6

Enter weight for this edge : 1

Enter edge 7(0 0 to quit) : 5 4

Enter weight for this edge : 4

Enter edge 8(0 0 to quit) : 6 5

Enter weight for this edge : 3

Enter edge 9(0 0 to quit) : 0 0




The adjacency matrix is :
 0 6 0 0 0 0
 0 0 0 0 3 2
 0 0 0 2 0 3
 0 0 0 0 0 1
 0 0 0 4 0 0
 0 0 0 0 3 0

Enter source node(0 to quit) : 1

Enter destination node(0 to quit) : 6

Shortest distance is : 8

Shortest Path is : 1->2->6

Enter source node(0 to quit) : 2

Enter destination node(0 to quit) :4



                                        79
Shortest distance is : 7

Shortest Path is : 2->5->4

Enter source node(0 to quit) : 0

Enter destination node(0 to quit) : 0




                               -13-PRIM’S ALGORITHM


#include<stdio.h>
#include<conio.h>

#define MAX 10
#define TEMP 0
#define PERM 1
#define FALSE 0
#define TRUE 1
#define infinity 9999

struct node
{
       int predecessor;
       int dist;
       int status;
};


                                        80
struct edge
{
        int u;
        int v;
};

int adj[MAX][MAX];
int n;

main()
{
         int i,j;
         int path[MAX];
         int wt_tree,count;
         struct edge tree[MAX];
         clrscr();
         printf("********* MINIMUM SPANNING TREE FROM PRIM'S
         ALGORITHM ********n");
         create_graph();
         printf("nAdjacency matrix is : nn");
         display();

         count = maketree(tree,&wt_tree);

         printf("nWeight of spanning tree is : %dn", wt_tree);
         printf("nEdges to be included in spanning tree are : nn");
         for(i=1;i<=count;i++)
         {
                printf("%d->",tree[i].u);
                printf("%dn",tree[i].v);
         }
         getch();
}

create_graph()
{
       int i,max_edges,origin,destin,wt;

         printf("nEnter number of vertices : ");
         scanf("%d",&n);
         max_edges=n*(n-1)/2;

         for(i=1;i<=max_edges;i++)
         {
                printf("nEnter edge %d(0 0 to quit) : ",i);



                                            81
scanf("%d %d",&origin,&destin);
              if((origin==0) && (destin==0))
                      break;
              printf("nEnter weight for this edge : ");
              scanf("%d",&wt);
              if( origin > n || destin > n || origin<=0 || destin<=0)
              {
                      printf("nInvalid edge!n");
                      i--;
              }
              else
              {
                      adj[origin][destin]=wt;
                      adj[destin][origin]=wt;
              }
       }
       if(i<n-1)
       {
               printf("nSpanning tree is not possiblen");
               exit(1);
       }
}

display()
{
       int i,j;
       for(i=1;i<=n;i++)
       {
                for(j=1;j<=n;j++)
                       printf("%3d",adj[i][j]);
                printf("n");
       }
}

int maketree(struct edge tree[MAX],int *weight)
{
      struct node state[MAX];
      int i,k,min,count,current,newdist;
      int m;
      int u1,v1;
      *weight=0;
      for(i=1;i<=n;i++)
      {
              state[i].predecessor=0;
              state[i].dist = infinity;
              state[i].status = TEMP;



                                           82
}
       state[1].predecessor=0;
       state[1].dist = 0;
       state[1].status = PERM;

       current=1;
       count=0;
       while( all_perm(state) != TRUE )
       {
              for(i=1;i<=n;i++)
              {
                     if ( adj[current][i] > 0 && state[i].status == TEMP )
                     {
                              if( adj[current][i] < state[i].dist )
                              {
                                      state[i].predecessor = current;
                                      state[i].dist = adj[current][i];
                              }
                     }
              }

              min=infinity;
              for(i=1;i<=n;i++)
              {
                     if(state[i].status == TEMP && state[i].dist < min)
                     {
                             min = state[i].dist;
                             current=i;
                     }
              }

              state[current].status=PERM;
              u1=state[current].predecessor;
              v1=current;
              count++;
              tree[count].u=u1;
              tree[count].v=v1;
              *weight=*weight+adj[u1][v1];
       }
       return (count);
}
int all_perm(struct node state[MAX] )
{
        int i;
        for(i=1;i<=n;i++)
          if( state[i].status == TEMP )



                                          83
return FALSE;
       return TRUE;
}




Output:-

******** MINIMUM SPANNING TREE FROM PRIM'S ALGORITHM ********

Enter number of vertices : 7

Enter edge 1(0 0 to quit) : 1 2

Enter weight for this edge : 3

Enter edge 2(0 0 to quit) : 1 3

Enter weight for this edge : 10

Enter edge 3(0 0 to quit) : 1 4

Enter weight for this edge : 2

Enter edge 4(0 0 to quit) : 1 5


                                  84
Enter weight for this edge : 4

Enter edge 5(0 0 to quit) : 2 5

Enter weight for this edge : 7

Enter edge 6(0 0 to quit) : 3 4

Enter weight for this edge : 12

Enter edge 7(0 0 to quit) : 3 6

Enter weight for this edge : 15

Enter edge 8(0 0 to quit) : 4 5

Enter weight for this edge : 6

Enter edge 9(0 0 to quit) : 4 6

Enter weight for this edge : 4

Enter edge 10(0 0 to quit) : 5 6

Enter weight for this edge : 5

Enter edge 11(0 0 to quit) : 5 7

Enter weight for this edge : 2

Enter edge 12(0 0 to quit) : 6 7

Enter weight for this edge : 3

Enter edge 13(0 0 to quit) : 0 0

Adjacency matrix is :

 0   3 10 2   4 0 0
 3   0 0 0    7 0 0
10   0 0 12   0 15 0
 2   0 12 0   6 4 0
 4   7 0 6    0 5 2
 0   0 15 4   5 0 3
 0   0 0 0    2 3 0



                                   85
Weight of spanning tree is : 24

Edges to be included in spanning tree are :

1->4
1->2
1->5
5->7
7->6
1->3




                                         86

More Related Content

Viewers also liked

Essential qualities found in intrapreneurs
Essential qualities found in intrapreneursEssential qualities found in intrapreneurs
Essential qualities found in intrapreneurseTailing India
 
Deepening of flaws in startup india’s laws
Deepening of flaws in startup india’s lawsDeepening of flaws in startup india’s laws
Deepening of flaws in startup india’s lawseTailing India
 
Startups- know 4 types of ip protection for businesses
Startups- know 4 types of ip protection for businessesStartups- know 4 types of ip protection for businesses
Startups- know 4 types of ip protection for businesseseTailing India
 
Customer Experience - Changing Shopping Experiences In India – End to End Bra...
Customer Experience - Changing Shopping Experiences In India – End to End Bra...Customer Experience - Changing Shopping Experiences In India – End to End Bra...
Customer Experience - Changing Shopping Experiences In India – End to End Bra...eTailing India
 
Re-energeize your career by being an intrapreneur
 Re-energeize your career by being an intrapreneur Re-energeize your career by being an intrapreneur
Re-energeize your career by being an intrapreneureTailing India
 
FDI To Aid Ecommerce Firms Expand Food And FMCG Sectors
FDI To Aid Ecommerce Firms Expand Food And FMCG SectorsFDI To Aid Ecommerce Firms Expand Food And FMCG Sectors
FDI To Aid Ecommerce Firms Expand Food And FMCG SectorseTailing India
 

Viewers also liked (6)

Essential qualities found in intrapreneurs
Essential qualities found in intrapreneursEssential qualities found in intrapreneurs
Essential qualities found in intrapreneurs
 
Deepening of flaws in startup india’s laws
Deepening of flaws in startup india’s lawsDeepening of flaws in startup india’s laws
Deepening of flaws in startup india’s laws
 
Startups- know 4 types of ip protection for businesses
Startups- know 4 types of ip protection for businessesStartups- know 4 types of ip protection for businesses
Startups- know 4 types of ip protection for businesses
 
Customer Experience - Changing Shopping Experiences In India – End to End Bra...
Customer Experience - Changing Shopping Experiences In India – End to End Bra...Customer Experience - Changing Shopping Experiences In India – End to End Bra...
Customer Experience - Changing Shopping Experiences In India – End to End Bra...
 
Re-energeize your career by being an intrapreneur
 Re-energeize your career by being an intrapreneur Re-energeize your career by being an intrapreneur
Re-energeize your career by being an intrapreneur
 
FDI To Aid Ecommerce Firms Expand Food And FMCG Sectors
FDI To Aid Ecommerce Firms Expand Food And FMCG SectorsFDI To Aid Ecommerce Firms Expand Food And FMCG Sectors
FDI To Aid Ecommerce Firms Expand Food And FMCG Sectors
 

Similar to Dcn code and output

Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingvrgokila
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003ncct
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in CAmbili Baby
 
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);Joel Porquet
 
Problem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdfProblem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdffeelinggift
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhdsachindb9
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...DR B.Surendiran .
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfVishwasChoclaty1
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所Hiroshi Sekiguchi
 
I just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdfI just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdfallurafashions98
 

Similar to Dcn code and output (20)

Unit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programmingUnit 1 ocs752 introduction to c programming
Unit 1 ocs752 introduction to c programming
 
Ramco C Question Paper 2003
Ramco  C  Question  Paper 2003Ramco  C  Question  Paper 2003
Ramco C Question Paper 2003
 
Numerical Methods in C
Numerical Methods in CNumerical Methods in C
Numerical Methods in C
 
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
printf("%s from %c to Z, in %d minutes!\n", "printf", 'A', 45);
 
Gps c
Gps cGps c
Gps c
 
C programs
C programsC programs
C programs
 
Problem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdfProblem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdf
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Loopback.vhd
Loopback.vhdLoopback.vhd
Loopback.vhd
 
week-3x
week-3xweek-3x
week-3x
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdf
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所SQLチューニング総合診療Oracle CloudWorld出張所
SQLチューニング総合診療Oracle CloudWorld出張所
 
week-2x
week-2xweek-2x
week-2x
 
I just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdfI just need code for processQueue function using iterators from the .pdf
I just need code for processQueue function using iterators from the .pdf
 

Dcn code and output

  • 1. -1- VERTICAL REDUNDANCY CHECK #include<stdio.h> #include<conio.h> #include<stdlib.h> void receiver(); void sender(); int i,j,data[20]; void main() { int ans; clrscr(); printf("nn*********************** VERTICAL REDUNDANCY CHECK ***********************nn"); while(1) { printf("n--------------------------------------------------------------------------n "); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sidenn 2. Receiver's Sidenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&ans); switch(ans) { case 1: printf("n----------------------------------------------------------- -------------n"); printf("ttt Sender's Side"); printf("n----------------------------------------------------------- --------------n"); sender(); break; case 2: printf("n----------------------------------------------------------- --------------n"); printf("ttt Receiver's Side"); printf("n----------------------------------------------------------- --------------n"); receiver(); break; case 3: exit(1); default: 1
  • 2. printf("nnINVALID ENTRY!!!"); } } } void receiver() { int sum=0; printf("nEnter the number of bits you want (Max 20) : "); scanf("%d",&j); printf("nnEnter %d bits : ",j); for(i=0;i<j;i++) { printf("nn %d bit: ",i+1); scanf("%d",&data[i]); if((data[i]!=0) && (data[i]!=1)) { printf("nInvalid Bit......Enter only (1's and 0's) "); i--; } } for(i=0;i<j;i++) { sum=sum+data[i]; } printf("n-------------------------------------------------------------------------n"); printf("ttttOutput"); printf("n-------------------------------------------------------------------------"); printf("nnThe Number of 1's in the message is: %d",sum); if(sum%2==0) { printf("nnThere is no ERROR in the message."); } else { printf("nnThere is ERROR in the message."); } } void sender() { int sum=0; printf("nEnter the number of bits you want (Max 20) : "); scanf("%d",&j); printf("nEnter %d bits : ",j); for(i=0;i<j;i++) 2
  • 3. { printf("nn %d bit: ",i+1); scanf("%d",&data[i]); if((data[i]!=0) && (data[i]!=1)) { printf("nInvalid bit......Enter only (1's and 0's) "); i--; } } for(i=0;i<j;i++) { sum=sum+data[i]; } printf("n-------------------------------------------------------------------------n"); printf("ttttOutput"); printf("n-------------------------------------------------------------------------"); printf("nnThe Message sent was : "); for(i=0;i<j;i++) { printf("%d",data[i]); } if(sum%2!=0) { printf("nnParity Bit is : 1"); data[j]=1; printf("nnThe Message after appending parity bit was : "); for(i=0;i<=j;i++) { printf("%d",data[i]); } } else { printf("nnParity Bit is : 0"); data[j]=0; printf("nnThe Message after appending parity bit was : "); for(i=0;i<=j;i++) { printf("%d",data[i]); } } } 3
  • 4. OUTPUT:- ****************** VERTICAL REDUNDANCY CHECK ******************* ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Side 2. Receiver's Side 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Side ----------------------------------------------------------------------------------------------------------- - Enter the number of bits you want (Max 20) : 5 Enter 5 bits : 1 bit: 1 2 bit: 0 3 bit: 1 4 bit: 0 5 bit: 1 ----------------------------------------------------------------------------------------------------------- - 4
  • 5. Output ----------------------------------------------------------------------------------------------------------- - The Message sent was : 10101 Parity Bit is : 1 The Message after appending parity bit was : 101011 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Side 2. Receiver's Side 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Side ----------------------------------------------------------------------------------------------------------- - Enter the number of bits you want (Max 20) : 4 Enter 4 bits : 1 bit: 1 2 bit: 0 3 bit: 2 Invalid Bit......Enter only (1's and 0's) 5
  • 6. 3 bit: 0 4 bit: 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - The Number of 1's in the message is: 2 There is no ERROR in the message. ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Side 2. Receiver's Side 3. Exit Enter Your Choice : 3 6
  • 7. -2- LONGITUDINAL REDUNDANCY CHECK #include<stdio.h> #include<stdlib.h> #include<conio.h> int a[10][10]; int count,j,i,n,m; void sender(); void receiver(); void main() { int ans; clrscr(); printf("nn*********************** LONGITUDINAL REDUNDANCY CHECK ***********************nn"); while(1) { printf("n--------------------------------------------------------------------------n "); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&ans); switch(ans) { case 1: printf("n----------------------------------------------------------- --------------n"); 7
  • 8. printf("ttt Sender's Site"); printf("n----------------------------------------------------------- --------------n"); sender(); break; case 2: printf("n----------------------------------------------------------- --------------n"); printf("ttt Receiver's Site"); printf("n----------------------------------------------------------- --------------n"); receiver(); break; case 3: exit(1); default: printf("nnINVALID ENTRY!!!"); } } } void sender() { printf("Enter the number of rows and columns max(5) : "); scanf("%d%d",&m,&n); printf("nEnter %d rows and %d columns : n",m,n); for(i=1;i<=m;i++) { printf("nEnter %d row %d bits : ",i,n); for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); if((a[i][j]!=0)&&(a[i][j]!=1)) { printf("nnInvalid Bit......Enter another bit(Only 1's and 0's)!!!"); j--; } } } for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(a[j][i]==1) 8
  • 9. { count++; } } if(count%2==0) { a[j][i]=0; count=0; } else { a[j][i]=1; count=0; } } printf("n--------------------------------------------- Output -----------------------------------n"); printf("nThe parity row is : n"); i=m+1; for(j=1;j<=n;j++) { printf("%dt",a[i][j]); } printf("nnThe Message after appending : n"); for(i=1;i<=m+1;i++) { for(j=1;j<=n;j++) { printf("%dt",a[i][j]); } printf("nn"); } } void receiver() { int count1=0; printf("Enter the number of rows and columns max(5) : "); scanf("%d%d",&m,&n); printf("nEnter %d rows and %d columns : ",m,n); for(i=1;i<=m;i++) { printf("nnEnter %d row %d bits : ",i,n); for(j=1;j<=n;j++) { scanf("%d",&a[i][j]); 9
  • 10. if((a[i][j]!=0)&&(a[i][j]!=1)) { printf("nnInvalid Bit......Enter another bit(Only 1's and 0's)!!!"); j--; } } } printf("n-------------------------------------------- Output ----------------------------------------n"); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(a[j][i]==1) { count++; } } if(count%2==0) { count1++; count=0; } else { count=0; } } if(count1==n) printf("nData is correctly received...n"); else printf("nData is not correctly received...n"); } 10
  • 11. OUTPUT:- ***************** LONGITUDINAL REDUNDANCY CHECK *************** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Site ----------------------------------------------------------------------------------------------------------- - Enter the number of rows and columns max(5) : 2 3 Enter 2 rows and 3 columns : Enter 1 row 3 bits : 1 0 0 Enter 2 row 3 bits : 1 0 1 11
  • 12. ----------------------------------------------- Output -------------------------------------------------- The parity row is : 0 0 1 The Message after appending : 1 0 0 1 0 1 0 0 1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Site ----------------------------------------------------------------------------------------------------------- - Enter the number of rows and columns max(5) : 2 3 Enter 2 rows and 3 columns : Enter 1 row 3 bits : 1 1 0 12
  • 13. Enter 2 row 3 bits : 1 0 1 ------------------------------------------------ Output ------------------------------------------------- Data is not correctly received... ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 3 13
  • 14. -3- CYCLIC REDUNDANCY CHECK #include<stdlib.h> #include<conio.h> #include<stdio.h> void receiver(); void sender(); int i,j,n,g,a1,a[20]={0},d[20]={0},b[20],p[20],s,cnt; void main() { int choice; clrscr(); printf("*********************** CYCLIC REDUNCDANCY CHECK **********************n"); while(1) { printf("nn-------------------------------------------------------------------------- n"); 14
  • 15. printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("n--------------------------- Sender's Site ----------------------------"); sender(); break; case 2: printf("n------------------------- Receiver's Site ---------------"); receiver(); break; case 3: exit(1); } } } void sender() { printf("nnEnter total number of data bits : "); scanf("%d",&n); printf("nEnter %d data bits : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); scanf("%d",&a[i]); if((a[i]!=1)&& (a[i]!=0)) { printf("nInvalid Entry...Enter only 1's & 0's!!!n"); i--; } } printf("nEnter size of Key (! >databits) : "); scanf("%d",&g); 15
  • 16. if(g>n) { printf("nInvalid Entry...Enter value less than databit!!!n"); printf("nEnter size of Key (! >databits): "); scanf("%d",&g); } do { printf("nEnter Key values : nn"); for(j=0;j<g;j++) { printf("nEnter key bit %d : ",j+1); scanf("%d",&d[j]); if((d[j]!=1)&& (d[j]!=0)) { printf("nInvalid Entry...Enter only 1's & 0's!!!n"); j--; } } }while(d[0]!=1); printf("n------------------------------------------------------------------n"); printf("ttOutput "); printf("n------------------------------------------------------------------n"); a1=n+(g-1); printf("nnThe Message : t"); for(i=0;i<a1;++i) { if(i<a1) { p[i]=a[i]; } else { p[i]=0; } } for(i=0;i<a1;++i) { printf("%d",p[i]); } printf("nnThe Divisor : t"); for(j=0;j<g;j++) { printf("%d",d[j]); } printf("nnIntermediate CRC : "); 16
  • 17. for(i=0;i<n;++i) { if(a[i]==0) { printf(" "); for(j=i;j<g+i;++j) { a[j] = a[j]^0; printf("%d",a[j]); } } else { printf(" "); a[i] = a[i]^d[0]; a[i+1]=a[i+1]^d[1]; a[i+2]=a[i+2]^d[2]; a[i+3]=a[i+3]^d[3]; printf("%d%d%d",a[i],a[i+1],a[i+2]); printf(" "); } } printf("nnThe Final CRC Bit is : t"); for(i=n;i<a1;++i) { printf("%d",a[i]); } s=n+a1; for(i=n;i<s;i++) { p[i]=a[i]; } printf("n"); printf("nThe Message transmitted is : "); for(i=0;i<a1;i++) { printf("%d",p[i]); } } void receiver() { printf("nnEnter total number of data bits: "); scanf("%d",&n); printf("nEnter %d data bits : nn",n); for(i=0;i<n;i++) { 17
  • 18. printf("nEnter bit %d : ",i+1); scanf("%d",&a[i]); if((a[i]!=1)&& (a[i]!=0)) { printf("nInvalid Entry...Enter only 1's & 0's!!!n"); i--; } } printf("nEnter size of Key (! >databits): "); scanf("%d",&g); if(g>n) { printf("nInvalid Entry...Enter value less than databit!!!n"); printf("nEnter size of Key (! >databits): "); scanf("%d",&g); } do { printf("nEnter Key values : nn"); for(j=0;j<g;j++) { printf("nEnter key bit %d : ",j+1); scanf("%d",&d[j]); if((d[j]!=1)&& (d[j]!=0)) { printf("nInvalid Entry...Enter only 1's & 0's!!!n"); j--; } } }while(d[0]!=1); printf("n-------------------------------------------------------------------------------n"); printf("ttOutput"); printf("n--------------------------------------------------------------------------------n"); printf("nnThe Message : t"); for(i=0;i<n;++i) { p[i]=a[i]; } for(i=0;i<n;i++) { printf("%d",p[i]); } printf("nnThe Divisor : t"); for(j=0;j<g;j++) { printf("%d",d[j]); 18
  • 19. } a1=n+(g-1); printf("nnCRC's : "); for(i=0;i<n;i++) { if(a[i]==0) { printf(" "); for(j=i;j<g+i;j++) { a[j] = a[j]^0; printf("%d",a[j]); } } else { printf(" "); a[i] = a[i]^d[0]; a[i+1]=a[i+1]^d[1]; a[i+2]=a[i+2]^d[2]; a[i+3]=a[i+3]^d[3]; printf("%d%d%d",a[i],a[i+1],a[i+2]); printf(" "); } } printf("nnThe Final CRC is : "); for(i=n;i<a1;++i) { printf("%d",a[i]); } s=n+a1; cnt=0; for(i=n;i<s;i++) { p[i]=a[i]; if(p[i]==1) { cnt++; } } printf("n"); if(cnt==0) { printf("nnThe Message is received correctly"); } else 19
  • 20. { printf("nnThe Message is not received correctly"); } } Output:- ********************** CYCLIC REDUNCDANCY CHECK **************** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------- Sender's Site ------------------------------------------- 20
  • 21. Enter total number of data bits : 5 Enter 5 data bits : Enter bit 1: 1 Enter bit 2: 0 Enter bit 3: 1 Enter bit 4: 1 Enter bit 5: 0 Enter size of Key (! >databits) : 3 Enter Key values : Enter key bit 1 : 1 Enter key bit 2 : 1 Enter key bit 3 : 0 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - The Message : 1011000 The Divisor : 110 Intermediate CRC : 011 001 010 010 010 The Final CRC Bit is : 10 The Message transmitted is : 1011010 ----------------------------------------------------------------------------------------------------------- - 21
  • 22. MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 2 ---------------------------------------------- Receiver's Site ----------------------------------------- Enter total number of data bits: 5 Enter 5 data bits : Enter bit 1 : 1 Enter bit 2 : 1 Enter bit 3 : 0 Enter bit 4 : 1 Enter bit 5 : 1 Enter size of Key (! >databits): 3 Enter Key values : Enter key bit 1 : 1 Enter key bit 2 : 0 Enter key bit 3 : 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - 22
  • 23. The Message : 11011 The Divisor : 101 CRC's : 011 010 000 000 000 The Final CRC is : 00 The Message is received correctly ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 3 -4- CHECKSUM #include<stdio.h> #include<conio.h> #include<stdlib.h> int sum(int,int); int sum1(int,int,int); void sender(); void receiver(); int a[8],b[8],r[8],c[8],r1[8]; 23
  • 24. static int carry=0; int n,i,count=0; void main() { int choice; clrscr(); printf("n*********************************** CHECKSUM *********************************n"); while(1) { printf("nn-------------------------------------------------------------------------- n"); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("------------------------------------------------------------- -----------n"); printf("ntt Sender's Site "); printf("n----------------------------------------------------------- -------------n"); sender(); break; case 2: printf("------------------------------------------------------------- -----------n"); printf("nttReceiver's Site "); printf("n----------------------------------------------------------- -------------n"); receiver(); break; case 3: exit(1); default: printf("nnINVALID ENTRY"); } } 24
  • 25. } void sender() { printf("nEnter the total number of bits : "); scanf("%d",&n); printf("nEnter %d bits of Data 1 : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); scanf("%d",&a[i]); if(a[i]!=0 && a[i]!=1) { printf("nnInvalid Bit......Enter another value(only 1's and 0's)!!!!!"); i--; } } printf("n------------------------------------------------------------------n"); printf("nEnter %d bits of Data 2 : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); scanf("%d",&b[i]); if(b[i]!=0 && b[i]!=1) { printf("nnInvalid Bit......Enter another value(only 1's and 0's)!!!!!"); i--; } } printf("n-----------------------------------------------------------------------------n"); printf("nttOutput"); printf("n-----------------------------------------------------------------------------n"); printf("nnData 1:ttt "); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("nnData 2:ttt "); for(i=0;i<n;i++) { printf("%d",b[i]); } for(i=n;i>=0;i--) { 25
  • 26. r[i]=sum(a[i],b[i]); } printf("nnResult :tt "); for(i=0;i<n;i++) { printf("%d",r[i]); } for(i=0;i<n;i++) { if (r[i]==0) { r[i]=1; } else { r[i]=0; } } printf("nn1's Compliment of Result :"); for(i=0;i<n;i++) { printf("%d",r[i]); } } int sum(int x,int y) { if(x==0 && y==0 && carry==0) { carry=0; return 0; } else if(x==0 && y==0 && carry==1) { carry=0; return 1; } else if(x==0 && y==1 && carry==0) { carry=0; return 1; } else if(x==0 && y==1 && carry==1) { carry=1; return 0; 26
  • 27. } else if(x==1 && y==0 && carry==0) { carry=0; return 1; } else if(x==1 && y==0 && carry==1) { carry=1; return 0; } else if(x==1 && y==1 && carry==0) { carry=1; return 0; } else if(x==1 && y==1 && carry==1) { carry=1; return 1; } else return(1); } void receiver() { printf("nEnter the total number of bits : "); scanf("%d",&n); printf("nEnter %d bits of Data 1 : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); scanf("%d",&a[i]); if(a[i]!=0 && a[i]!=1) { printf("nnInvalid Bit......Enter another value(only 1's and 0's)!!!!!"); i--; } } printf("n------------------------------------------------------------------n"); printf("nEnter %d bits of Data 2 : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); 27
  • 28. scanf("%d",&b[i]); if(b[i]!=0 && b[i]!=1) { printf("nnInvalid Bit......Enter another value(only 1's and 0's)!!!!!"); i--; } } printf("n------------------------------------------------------------------n"); printf("nEnter %d bits of Checksum : nn",n); for(i=0;i<n;i++) { printf("nEnter bit %d: ",i+1); scanf("%d",&c[i]); if(c[i]!=0 && c[i]!=1) { printf("nnInvalid Bit......Enter another value(only 1's and 0's)!!!!!"); i--; } } printf("n----------------------------------------------------------------------------------"); printf("nttOutput"); printf("n----------------------------------------------------------------------------------"); printf("nnData 1:ttt "); for(i=0;i<n;i++) { printf("%d",a[i]); } printf("nnData 2:ttt "); for(i=0;i<n;i++) { printf("%d",b[i]); } printf("nnChecksum:tt "); for(i=0;i<n;i++) { printf("%d",c[i]); } for(i=n;i>=0;i--) { r1[i]=sum1(a[i],b[i],c[i]); } printf("nnResult :tt "); for(i=0;i<n;i++) { 28
  • 29. printf("%d",r1[i]); } for(i=0;i<n;i++) { if (r1[i]==0) { r1[i]=1; } else { r1[i]=0; } } printf("nn1's Compliment of Result :"); for(i=0;i<n;i++) { printf("%d",r1[i]); } for(i=0;i<n;i++) { if(r1[i]==0) { count=count+1; } } if(count==n) { printf("nnData is ERROR free, hence ACCEPTED... "); } else { printf("nnData is NOT ERROR free, hence NOT ACCEPTED..."); } } int sum1(int x,int y,int z) { if(x==0 && y==0 && z==0 && carry==0) { carry=0; return(0); } else if(x==1 && y==0 && z==0 && carry==0) { carry=0; return(1); 29
  • 30. } else if(x==0 && y==1 && z==0 && carry==0) { carry=0; return(1); } else if(x==1 && y==1 && z==0 && carry==0) { carry=1; return(0); } else if(x==0 && y==0 && z==1 && carry==0) { carry=0; return(1); } else if(x==1 && y==0 && z==1 && carry==0) { carry=1; return(0); } else if(x==0 && y==1 && z==1 && carry==0) { carry=1; return(0); } else if(x==1 && y==1 && z==1 && c==0) { carry=1; return(1); } else if(x==0 && y==0 && z==0 && carry==1) { carry=0; return(1); } else if(x==1 && y==0 && z==0 && carry==1) { carry=1; return(0); } else if(x==0 && y==1 && z==0 && carry==1) { carry=1; return(0); } 30
  • 31. else if(x==1 && y==1 && z==0 && carry==1) { carry=1; return(1); } else if(x==0 && y==0 && z==1 && carry==1) { carry=1; return(0); } else if(x==1 && y==0 && z==1 && carry==1) { carry=1; return(1); } else if(x==0 && y==1 && z==1 && carry==1) { carry=1; return(1); } else return(1); } Output:- ****************************** CHECKSUM ***************************** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 31
  • 32. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Site ----------------------------------------------------------------------------------------------------------- - Enter the total number of bits : 5 Enter 5 bits of Data 1 : Enter bit 1: 1 Enter bit 2: 0 Enter bit 3: 1 Enter bit 4: 1 Enter bit 5: 0 ----------------------------------------------------------------------------------------------------------- - Enter 5 bits of Data 2 : Enter bit 1: 0 Enter bit 2: 1 Enter bit 3: 0 Enter bit 4: 0 Enter bit 5: 1 ----------------------------------------------------------------------------------------------------------- - 32
  • 33. Output ----------------------------------------------------------------------------------------------------------- - Data 1: 10110 Data 2: 01001 Result : 11111 1's Compliment of Result :00000 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Site ----------------------------------------------------------------------------------------------------------- - Enter the total number of bits : 5 Enter 5 bits of Data 1 : Enter bit 1: 0 Enter bit 2: 0 Enter bit 3: 0 Enter bit 4: 0 33
  • 34. Enter bit 5: 1 ----------------------------------------------------------------------------------------------------------- - Enter 5 bits of Data 2 : Enter bit 1: 1 Enter bit 2: 2 Invalid Bit......Enter another value(only 1's and 0's)!!!!! Enter bit 2: 1 Enter bit 3: 1 Enter bit 4: 1 Enter bit 5: 0 ----------------------------------------------------------------------------------------------------------- - Enter 5 bits of Checksum : Enter bit 1: 0 Enter bit 2: 0 Enter bit 3: 0 Enter bit 4: 0 Enter bit 5: 0 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - Data 1: 00001 34
  • 35. Data 2: 11110 Checksum: 00000 Result : 11111 1's Compliment of Result :00000 Data is ERROR free, hence ACCEPTED... ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 3 35
  • 36. -5- HAMMING CODE #include<stdio.h> #include<conio.h> #include<math.h> void sender(); void receiver(); int a,m,r,i,count=0,n,count1=0; void main() { int ans; clrscr(); printf("nn*********************** HAMMING CODE ***********************nn"); while(1) { printf("n--------------------------------------------------------------------------n "); printf("ttttnMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&ans); switch(ans) { case 1: printf("n----------------------------------------------------------- --------------n"); printf("ttt Sender's Site"); printf("n----------------------------------------------------------- --------------n"); sender(); break; case 2: printf("n----------------------------------------------------------- --------------n"); printf("ttt Receiver's Site"); 36
  • 37. printf("n----------------------------------------------------------- --------------n"); receiver(); break; case 3: exit(1); default: printf("nnINVALID ENTRY!!!"); } } } void sender() { int data[20]; printf("Enter the number of data bits (MAX 11) : "); scanf("%d",&m); for(i=0;i<20;i++) data[i]=0; while(pow(2,r)-r<m+1) r++; printf("nThe Parity Bits are : %d n",r); for(i=1;i<9;i++) { if(i==1||i==2||i==4||i==8) { data[i]=4; } } printf("nEnter %d data bits : ",m); for(i=1;i<=m+r;i++) { if(i==3||i==5||i==6||i==7||i==9||i==10||i==11||i==12||i==13||i==14||i==15|| i==16) { scanf("%d",&data[i]); if (data[i]!=0&&data[i]!=1) { printf("Invalid Entry!!! Enter only 0's and 1's"); i--; } } } printf("nData Is : "); for(i=1;i<=m+r;i++) { 37
  • 38. printf("%d ",data[i]); } for(i=1;i<=m+r;i++) { if(data[i]==4) { a=i; } if(a==1) { count=data[3]+data[5]+data[7]+data[9]+data[11]; if(count%2==0) data[a]=0; else data[a]=1; } if(a==2) { count=data[3]+data[6]+data[7]+data[10]+data[11]; if(count%2==0) data[a]=0; else data[a]=1; } if(a==4) { count=data[5]+data[6]+data[7]; if(count%2==0) data[a]=0; else data[a]=1; } if(a==8) { count=data[9]+data[10]+data[11]; if(count%2==0) data[a]=0; else data[a]=1; } } printf("nn-----------------------------------------------------------------------------n"); printf("tttOutput"); printf("n--------------------------------------------------------------------------------n"); printf("nnNew Data To Be Sent Is : "); for(i=1;i<=m+r;i++) 38
  • 39. printf("%d ",data[i]); } void receiver() { int data[20],temp; printf("nEnter the number of data bits : "); scanf("%d",&m); for(i=0;i<20;i++) data[i]=0; printf("nEnter %d data bits : ",m); for(i=1;i<=m;i++) { scanf("%d",&data[i]); if (data[i]!=0&&data[i]!=1) { printf("Invalid Entry!!! Enter only 0's and 1's"); i--; } } for(i=1;i<=m;i++) { if(i==1) { count=data[1]+data[3]+data[5]+data[7]+data[9]+data[11]; if(count%2==0) { data[i]=data[i]; } else { count1=count1+i; } } if(i==2) { count=data[2]+data[3]+data[6]+data[7]+data[10]+data[11]; if(count%2==0) { data[i]=data[i]; } else { 39
  • 40. count1=count1+i; } } if(i==4) { count=data[4]+data[5]+data[6]+data[7]; if(count%2==0) { data[i]=data[i]; } else { count1=count1+i; } } if(i==8) { count=data[8]+data[9]+data[10]+data[11]; if(count%2==0) { data[i]=data[i]; } else { count1=count1+i; } } } printf("nn-----------------------------------------------------------------------------n"); printf("ttOutputn"); printf("n--------------------------------------------------------------------------------n"); if(count1>0) { if(count1>m) { printf("nError Is At Position %d",count1); printf("nnOOPS!!! Position is not availablen"); } else { printf("nError Is At Position %d",count1); if(data[count1]==0) data[count1]=1; else data[count1]=0; printf("nCorrect Code Word : "); 40
  • 41. for(i=1;i<=m;i++) { printf("%d ",data[i]); } } } else { printf("nReceived Data Is ERROR FREE... n"); printf("nCorrect Code Word : "); for(i=1;i<=m;i++) { printf("%d ",data[i]); } } } 41
  • 42. Output:- ***************************** HAMMING CODE ************************* ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Site ----------------------------------------------------------------------------------------------------------- - Enter the number of data bits (MAX 11) : 7 The Parity Bits are : 4 Enter 7 data bits : 1 0 0 1 0 1 1 Data Is : 4 4 1 4 0 0 1 4 0 1 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - 42
  • 43. New Data To Be Sent Is : 1 0 1 1 0 0 1 0 0 1 1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Site ----------------------------------------------------------------------------------------------------------- - Enter the number of data bits : 11 Enter 11 data bits : 1 0 1 1 0 0 1 0 1 1 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - Error Is At Position 9 Correct Code Word : 1 0 1 1 0 0 1 0 0 1 1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 43
  • 44. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 3 -6- BIT STUFFING #include<stdio.h> #include<conio.h> #include<stdlib.h> void sender(); void receiver(); int data[20],i,j,n,count=0; void main() { int choice; clrscr(); printf("********************************** BIT STUFFING ********************************"); while(1) { printf("nn-------------------------------------------------------------------------- n"); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&choice); 44
  • 45. switch(choice) { case 1: printf("n----------------------------------------------------------- --------------n"); printf("ttt Sender's Site"); printf("n----------------------------------------------------------- --------------n"); sender(); break; case 2: printf("n----------------------------------------------------------- --------------n"); printf("ttt Receiver's Site"); printf("n----------------------------------------------------------- --------------n"); receiver(); break; case 3: exit(1); default: printf("nInvalid Choice!!!"); } } } void sender() { printf("nEnter the length of your code : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("nEnter %d bit : ",i+1); scanf("%d",&data[i]); } printf("nnThe Original Data entered : "); for(i=0;i<n;i++) { printf("%d ",data[i]); } i=0; while(i<n) { if(data[i]==1) { i++; 45
  • 46. count++; if(count==5) { for(j=n+1;j>i;j--) { data[j]=data[j-1]; } data[i]=0; } } else { i++; count=0; } } printf("nn--------------------------------------------------------------------------n"); printf("ttt Outputn"); printf("-------------------------------------------------------------------------------n"); printf("nnData After Stuffing : "); for(i=0;i<n+1;i++) { printf("%d ",data[i]); } } void receiver() { printf("nEnter the length of your code : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("nEnter %d bit : ",i+1); scanf("%d",&data[i]); } printf("nnThe Original Data entered : "); for(i=0;i<n;i++) { printf("%d ",data[i]); } i=0; while(i<n) { if(data[i]==1) { i++; 46
  • 47. count++; if(count==5) { for(j=i;j<n+1;j++) { data[j]=data[j+1]; } n--; } } else { i++; count=0; } } printf("nn--------------------------------------------------------------------------------"); printf("nttt Output"); printf("n--------------------------------------------------------------------------------n"); printf("nData After De-Stuff : "); for(i=0;i<n;i++) { printf("%d ",data[i]); } } 47
  • 48. Output:- ****************************** BIT STUFFING ************************** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Site ----------------------------------------------------------------------------------------------------------- - 48
  • 49. Enter the length of your code : 11 Enter 1 bit : 0 Enter 2 bit : 1 Enter 3 bit : 1 Enter 4 bit : 1 Enter 5 bit : 1 Enter 6 bit : 1 Enter 7 bit : 1 Enter 8 bit : 0 Enter 9 bit : 1 Enter 10 bit : 1 Enter 11 bit : 0 The Original Data entered : 0 1 1 1 1 1 1 0 1 1 0 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - Data After Stuffing : 0 1 1 1 1 1 0 1 0 1 1 0 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 49
  • 50. 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Site ----------------------------------------------------------------------------------------------------------- - Enter the length of your code : 11 Enter 1 bit : 0 Enter 2 bit : 1 Enter 3 bit : 1 Enter 4 bit : 1 Enter 5 bit : 1 Enter 6 bit : 1 Enter 7 bit : 0 Enter 8 bit : 0 Enter 9 bit : 1 Enter 10 bit : 0 Enter 11 bit : 1 The Original Data entered : 0 1 1 1 1 1 0 0 1 0 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - Data After De-Stuff : 0 1 1 1 1 1 0 1 0 1 ----------------------------------------------------------------------------------------------------------- - 50
  • 51. MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 3 -7- WALSH MATRIX #include<stdio.h> #include<conio.h> #include<stdlib.h> void stn1(); void stn2(); void stn4(); int n,i,j; void main() { 51
  • 52. clrscr(); printf("n***************** CHIPPING SEQUENCE USING WALSH MATRIX *********************nn"); while(1) { printf("n--------------------------------------------------------------------------n "); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Station No.nn"); printf(" 1. Station 1nn 2. Station 2nn 3. Station 4nn 4. ExitnnEnter Your Choice : "); scanf("%d",&n); switch(n) { case 1: printf("n----------------------------------------------------------- --------------n"); printf("ttt Station 1"); printf("n----------------------------------------------------------- --------------n"); stn1(); break; case 2: printf("n----------------------------------------------------------- --------------n"); printf("ttt Station 2"); printf("n----------------------------------------------------------- --------------n"); stn2(); break; case 3: printf("n----------------------------------------------------------- --------------n"); printf("ttt Station 4"); printf("n----------------------------------------------------------- --------------n"); stn4(); break; case 4: exit(1); default: printf("nnInvalid Entry!!!"); } } 52
  • 53. } void stn1() { int w1; printf("nYour Code For Station 1 : 1n"); } void stn2() { int w2[2][2]; for(i=0;i<2;i++) { for(j=0;j<2;j++) { if ((i==1) && (j==1)) { w2[i][j]=-1; } else { w2[i][j]=1; } } } printf("nYour Code For Station 2 : nn"); for(i=0;i<2;i++) { for(j=0;j<2;j++) { printf("%d ",w2[i][j]); } printf("n"); } } void stn4() { int w4[4][4]; for(i=0;i<4;i++) { for(j=0;j<4;j++) { if(i==0) { w4[i][j]=1; 53
  • 54. } else if(j==0) { w4[i][j]=1; } else if((i==1)&&(j==1)) { w4[i][j]=-1; } else if((i==1)&&(j==3)) { w4[i][j]=-1; } else if((i==2)&&(j==2)) { w4[i][j]=-1; } else if((i==2)&&(j==3)) { w4[i][j]=-1; } else if((i==3)&&(j==1)) { w4[i][j]=-1; } else if((i==3)&&(j==2)) { w4[i][j]=-1; } else { w4[i][j]=1; } } } printf("nYour Code For Station 4 : nn"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { printf("%dt",w4[i][j]); } printf("n"); } } 54
  • 55. Output:- ************** CHIPPING SEQUENCE USING WALSH MATRIX *********** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Station No. 1. Station 1 55
  • 56. 2. Station 2 3. Station 4 4. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Station 1 ----------------------------------------------------------------------------------------------------------- - Your Code For Station 1 : 1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Station No. 1. Station 1 2. Station 2 3. Station 4 4. Exit Enter Your Choice : 5 Invalid Entry!!! ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Station No. 56
  • 57. 1. Station 1 2. Station 2 3. Station 4 4. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Station 2 ----------------------------------------------------------------------------------------------------------- - Your Code For Station 2 : 1 1 1 -1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Station No. 1. Station 1 2. Station 2 3. Station 4 4. Exit Enter Your Choice : 3 57
  • 58. ----------------------------------------------------------------------------------------------------------- - Station 4 ----------------------------------------------------------------------------------------------------------- - Your Code For Station 4 : 1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 1 ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Station No. 1. Station 1 2. Station 2 3. Station 4 4. Exit Enter Your Choice : 4 58
  • 59. -8- BIT COMPRESSION #include<stdio.h> #include<conio.h> void main() { int i,j,a[20],cnt1,cnt2,n; clrscr(); printf("n************************** BIT COMPRESSION ************************************n"); printf("nnEnter the length of Data ( <= 20 ) : "); scanf("%d",&n); printf("nnEnter %d Bits : n",n); for(i=1;i<=n;i++) { printf("nnEnter Bit %d:",i); scanf("%d",&a[i]); } printf("nnOriginal Data : "); for(i=1;i<=n;i++) { printf("%d ",a[i]); } cnt1=0; cnt2=0; printf("nn-----------------------------------------------------------------------------n"); printf("ttt Output"); printf("n-------------------------------------------------------------------------------n"); printf("nThe Data Contains : n"); for(i=1;i<=n;i++) { if(a[i]==1) { if(cnt2!=0) { printf("nn 0's : %d",cnt2); cnt2=0; } cnt1++; } 59
  • 60. if(a[i]==0) { if(cnt1!=0) { printf("nn 1's : %d",cnt1); cnt1=0; } cnt2++; } } if(cnt1==0) printf("nn 0's : %d",cnt2); if(cnt2==0) printf("nn 1's : %d",cnt1); getch(); } 60
  • 61. Output:- ************************** BIT COMPRESSION ************************** Enter the length of Data : 11 Enter 11 Bits : Enter Bit 1 : 1 Enter Bit 2 : 1 Enter Bit 3 : 0 Enter Bit 4 : 0 Enter Bit 5 : 0 Enter Bit 6 : 0 Enter Bit 7 : 1 Enter Bit 8 : 1 Enter Bit 9 : 0 Enter Bit 10 : 1 Enter Bit 11 :1 Original Data : 1 1 0 0 0 0 1 1 0 1 1 ----------------------------------------------------------------------------------------------------------- - Output ----------------------------------------------------------------------------------------------------------- - The Data Contains : 1's : 2 0's : 4 61
  • 62. 1's : 2 0's : 1 1's : 2 -9- MONOALPHABETIC ENCRYPTION #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<ctype.h> void sender(); void receiver(); void main() { int choice; clrscr(); printf("n************************** MONOALPHABETIC ENCRYPTION ***********************n"); while(1) { printf("nn-------------------------------------------------------------------------- n"); printf("ttttMAIN MENU"); printf("n--------------------------------------------------------------------------n n"); printf("Choice No. Choice Name.nn"); printf(" 1. Sender's Sitenn 2. Receiver's Sitenn 3. ExitnnnEnter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("n----------------------------------------------------------- --------------n"); printf("ttt Sender's Site"); printf("n----------------------------------------------------------- --------------n"); sender(); break; case 2: printf("n----------------------------------------------------------- --------------n"); 62
  • 63. printf("ttt Receiver's Site"); printf("n----------------------------------------------------------- --------------n"); receiver(); break; case 3: exit(1); default: printf("nnInvalid Entry"); } } } void sender() { int i,n; char *ptr,*str,*str1; printf("nEnter the Plain Text : "); scanf("%s",str); printf("nEnter the Charter difference : "); scanf("%d",&n); printf("n-----------------------------------------------------------------------nn"); printf("nPlain Text : "); printf("%s",str); printf("nnCipher Text After Encryption : "); for(i=0;str[i]!='0';i++) { if((str[i]>=65 && str[i]<=90-n) || (str[i]>=97 && str[i]<=122-n)) { ptr[i]=str[i]+n; } else if((str[i]>90-n && str[i]<=90)||(str[i]>122-n && str[i]<=122)) { ptr[i]=str[i]-26+n; } else { ptr[i]=str[i]; } } ptr[i]='0'; printf("%s",ptr); } 63
  • 64. void receiver() { int i,n; char *ptr,*str,*str1; printf("nEnter the Cipher text : "); scanf("%s",ptr); printf("nEnter the Charter difference : "); scanf("%d",&n); printf("n-----------------------------------------------------------------------nn"); printf("nCipher Text : "); printf("%s",ptr); printf("nnPlain text After Decryption : "); for(i=0;ptr[i]!='0';i++) { if((ptr[i]>=65+n && ptr[i]<=90) || (ptr[i]>=97+n && ptr[i]<=122)) { str1[i]=ptr[i]-n; } else if((ptr[i]>=65 && ptr[i]<=65+n)||(ptr[i]>=97 && ptr[i]<=97+n)) { str1[i]=ptr[i]+26-n; } else { str1[i]=ptr[i]; } } str1[i]='0'; printf("%s",str1); } 64
  • 65. Output:- ********************* MONOALPHABETIC ENCRYPTION **************** ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 1 ----------------------------------------------------------------------------------------------------------- - Sender's Site ----------------------------------------------------------------------------------------------------------- - Enter the Plain Text : TARANNUM Enter the Charter difference : 5 ----------------------------------------------------------------------------------------------------------- - Plain Text : TARANNUM Cipher Text After Encryption : YFWFSSZR 65
  • 66. ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 3. Exit Enter Your Choice : 2 ----------------------------------------------------------------------------------------------------------- - Receiver's Site ----------------------------------------------------------------------------------------------------------- - Enter the Cipher text : yfwfsszr Enter the Charter difference : 5 ----------------------------------------------------------------------------------------------------------- - Cipher Text : yfwfsszr Plain text After Decryption : tarannum ----------------------------------------------------------------------------------------------------------- - MAIN MENU ----------------------------------------------------------------------------------------------------------- - Choice No. Choice Name. 1. Sender's Site 2. Receiver's Site 66
  • 67. 3. Exit Enter Your Choice : 3 -10- POLYALPHABETIC ENCRYPTION #include <stdio.h> #include <string.h> void main() { unsigned int i,j=1,k; char input[257],key[33],l[257]; clrscr(); k=65; printf("n************************** POLYALPHABETIC ENCRYPTION ***************************n"); printf("ntttt VIGENERE TABLE nn"); printf("------------------------------------------------------------------------------nn"); while (j <= 26) { for (i=j; i<j+26; i++) { if (k >90) k = k - 26; printf("%c ",k ); k++; } printf("n"); 67
  • 68. j++; k++; } printf("n----------------------------------------------------------------------------nn"); printf("nEnter Plain Text : "); gets(input); printf("nEnter Encryption Key : "); gets(key); printf("n----------------------------------------------------------------------------n"); printf("nKEY : t "); for(i=0,j=0;i<strlen(input);i++,j++) { if(j>=strlen(key)) { j=0; } l[i]=key[j]; } for(i=0;i<strlen(input);i++) { printf("%c",l[i]); } printf("nnPlain Text : "); printf("%s",input); printf("nnCipher Text : "); for(i=0,j=0;i<strlen(input);i++,j++) { if(j>=strlen(key)) { j=0; } printf("%c",65+(((toupper(input[i])-65)+(toupper(key[j])-65)) %26)); } getch(); } 68
  • 69. Output:- ********************* POLYALPHABETIC ENCRYPTION ***************** VIGENERE TABLE ----------------------------------------------------------------------------------------------------------- - A B C D E F G H I J K L M N O P Q R S T U V W X Y Z B C D E F G H I J K L M N O P Q R S T U V W X Y Z A C D E F G H I J K L M N O P Q R S T U V W X Y Z A B D E F G H I J K L M N O P Q R S T U V W X Y Z A B C E F G H I J K L M N O P Q R S T U V W X Y Z A B C D F G H I J K L M N O P Q R S T U V W X Y Z A B C D E G H I J K L M N O P Q R S T U V W X Y Z A B C D E F H I J K L M N O P Q R S T U V W X Y Z A B C D E F G I J K L M N O P Q R S T U V W X Y Z A B C D E F G H J K L M N O P Q R S T U V W X Y Z A B C D E F G H I K L M N O P Q R S T U V W X Y Z A B C D E F G H I J L M N O P Q R S T U V W X Y Z A B C D E F G H I J K M N O P Q R S T U V W X Y Z A B C D E F G H I J K L N O P Q R S T U V W X Y Z A B C D E F G H I J K L M O P Q R S T U V W X Y Z A B C D E F G H I J K L M N P Q R S T U V W X Y Z A B C D E F G H I J K L M N O 69
  • 70. Q R S T U V W X Y Z A B C D E F G H I J K L M N O P R S T U V W X Y Z A B C D E F G H I J K L M N O P Q S T U V W X Y Z A B C D E F G H I J K L M N O P Q R T U V W X Y Z A B C D E F G H I J K L M N O P Q R S U V W X Y Z A B C D E F G H I J K L M N O P Q R S T V W X Y Z A B C D E F G H I J K L M N O P Q R S T U W X Y Z A B C D E F G H I J K L M N O P Q R S T U V X Y Z A B C D E F G H I J K L M N O P Q R S T U V W Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Z A B C D E F G H I J K L M N O P Q R S T U V W X Y ----------------------------------------------------------------------------------------------------------- - Enter Plain Text : HIWORLD Enter Encryption Key : ME ----------------------------------------------------------------------------------------------------------- - KEY : MEMEMEM Plain Text : HIWORLD Cipher Text : TMISDPP 70
  • 71. -11- RSA ALGORITHM #include<stdio.h> #include<conio.h> #include<math.h> int phi,m,n,e,d,c,flg; void check() { int i; for(i=3;e%i==0 && phi%i==0;i+2) { flg = 1; return; } flg = 0; } void encrypt() { int i; c = 1; 71
  • 72. for(i=0;i<e;i++) c=c*m%n; c=c%n; printf("nEncrypted Plain Text : %d",c); printf("nn----------------------------------------------------------------------n"); } void decrypt() { int i; m = 1; for(i=0;i< d;i++) m=m*c%n; m = m%n; printf("nDecrypted Cipher Text : %d",m); } void main() { int p,q,s; clrscr(); printf("n************************* RSA ALGORITHM *****************************nn"); printf("nEnter Two Relative Prime Numbers : "); scanf("%d%d",&p,&q); n = p*q; phi=(p-1)*(q-1); printf("nF(n)t = %d",phi); do { printf("nnEnter value for e : "); scanf("%d",&e); check(); }while(flg==1); d = 1; do { s = (d*e)%phi; d++; }while(s!=1); d = d-1; printf("n-----------------------------------------------------------------------------nn"); printf("nPublic Keyt: {%d,%d}",e,n); printf("nnPrivate Keyt: {%d,%d}",d,phi); printf("nn---------------------------------------------------------------------------nn"); printf("nEnter The Plain Text : "); 72
  • 73. scanf("%d",&m); encrypt(); printf("nnEnter the Cipher text : "); scanf("%d",&c); decrypt(); getch(); } Output:- **************************** RSA ALGORITHM ************************* Enter Two Relative Prime Numbers : 7 11 F(n) = 60 Enter value for e : 13 ----------------------------------------------------------------------------------------------------------- - Public Key : {13,77} Private Key : {37,60} ----------------------------------------------------------------------------------------------------------- - Enter The Plain Text : 7 Encrypted Plain Text : 35 73
  • 74. ----------------------------------------------------------------------------------------------------------- - Enter the Cipher text : 35 Decrypted Cipher Text : 7 -12-DIJKSTRA’S SHORTEST PATH #include<stdio.h> #include<conio.h> #define MAX 10 #define TEMP 0 #define PERM 1 #define infinity 9999 struct node { int predecessor; int dist; int status; }; int adj[MAX][MAX]; int n; void main() 74
  • 75. { int i,j; int source,dest; int path[MAX]; int shortdist,count; clrscr(); printf("************************ DIJKSTRA'S SHORTEST PATH **********************"); create_graph(); printf("The adjacency matrix is :n"); display(); while(1) { printf("nEnter source node(0 to quit) : "); scanf("%d",&source); printf("nEnter destination node(0 to quit) : "); scanf("%d",&dest); if(source==0 || dest==0) exit(1); count = findpath(source,dest,path,&shortdist); if(shortdist!=0) { printf("nShortest distance is : %dn", shortdist); printf("nShortest Path is : "); for(i=count;i>1;i--) printf("%d->",path[i]); printf("%d",path[i]); printf("n"); } else printf("nThere is no path from source to destination noden"); } getch(); } create_graph() { int i,max_edges,origin,destin,wt; printf("Enter number of vertices : "); scanf("%d",&n); max_edges=n*(n-1); 75
  • 76. for(i=1;i<=max_edges;i++) { printf("nEnter edge %d(0 0 to quit) : ",i); scanf("%d %d",&origin,&destin); if((origin==0) && (destin==0)) break; printf("nEnter weight for this edge : "); scanf("%d",&wt); if( origin > n || destin > n || origin<=0 || destin<=0) { printf("nInvalid edge!n"); i--; } else adj[origin][destin]=wt; } } display() { int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf("%3d",adj[i][j]); printf("n"); } } int findpath(int s,int d,int path[MAX],int *sdist) { struct node state[MAX]; int i,min,count=0,current,newdist,u,v; *sdist=0; for(i=1;i<=n;i++) { state[i].predecessor=0; state[i].dist = infinity; state[i].status = TEMP; } state[s].predecessor=0; state[s].dist = 0; state[s].status = PERM; current=s; while(current!=d) 76
  • 77. { for(i=1;i<=n;i++) { if ( adj[current][i] > 0 && state[i].status == TEMP ) { newdist=state[current].dist + adj[current][i]; if( newdist < state[i].dist ) { state[i].predecessor = current; state[i].dist = newdist; } } } min=infinity; current=0; for(i=1;i<=n;i++) { if(state[i].status == TEMP && state[i].dist < min) { min = state[i].dist; current=i; } } if(current==0) return 0; state[current].status=PERM; } while( current!=0 ) { count++; path[count]=current; current=state[current].predecessor; } for(i=count;i>1;i--) { u=path[i]; v=path[i-1]; *sdist+= adj[u][v]; } return (count); } 77
  • 78. Output:- ********************** DIJKSTRA'S SHORTEST PATH ******************* Enter number of vertices : 6 Enter edge 1(0 0 to quit) : 1 2 Enter weight for this edge : 6 Enter edge 2(0 0 to quit) : 2 5 Enter weight for this edge : 3 Enter edge 3(0 0 to quit) : 2 6 Enter weight for this edge : 2 Enter edge 4(0 0 to quit) : 3 4 78
  • 79. Enter weight for this edge : 2 Enter edge 5(0 0 to quit) : 3 6 Enter weight for this edge : 3 Enter edge 6(0 0 to quit) : 4 6 Enter weight for this edge : 1 Enter edge 7(0 0 to quit) : 5 4 Enter weight for this edge : 4 Enter edge 8(0 0 to quit) : 6 5 Enter weight for this edge : 3 Enter edge 9(0 0 to quit) : 0 0 The adjacency matrix is : 0 6 0 0 0 0 0 0 0 0 3 2 0 0 0 2 0 3 0 0 0 0 0 1 0 0 0 4 0 0 0 0 0 0 3 0 Enter source node(0 to quit) : 1 Enter destination node(0 to quit) : 6 Shortest distance is : 8 Shortest Path is : 1->2->6 Enter source node(0 to quit) : 2 Enter destination node(0 to quit) :4 79
  • 80. Shortest distance is : 7 Shortest Path is : 2->5->4 Enter source node(0 to quit) : 0 Enter destination node(0 to quit) : 0 -13-PRIM’S ALGORITHM #include<stdio.h> #include<conio.h> #define MAX 10 #define TEMP 0 #define PERM 1 #define FALSE 0 #define TRUE 1 #define infinity 9999 struct node { int predecessor; int dist; int status; }; 80
  • 81. struct edge { int u; int v; }; int adj[MAX][MAX]; int n; main() { int i,j; int path[MAX]; int wt_tree,count; struct edge tree[MAX]; clrscr(); printf("********* MINIMUM SPANNING TREE FROM PRIM'S ALGORITHM ********n"); create_graph(); printf("nAdjacency matrix is : nn"); display(); count = maketree(tree,&wt_tree); printf("nWeight of spanning tree is : %dn", wt_tree); printf("nEdges to be included in spanning tree are : nn"); for(i=1;i<=count;i++) { printf("%d->",tree[i].u); printf("%dn",tree[i].v); } getch(); } create_graph() { int i,max_edges,origin,destin,wt; printf("nEnter number of vertices : "); scanf("%d",&n); max_edges=n*(n-1)/2; for(i=1;i<=max_edges;i++) { printf("nEnter edge %d(0 0 to quit) : ",i); 81
  • 82. scanf("%d %d",&origin,&destin); if((origin==0) && (destin==0)) break; printf("nEnter weight for this edge : "); scanf("%d",&wt); if( origin > n || destin > n || origin<=0 || destin<=0) { printf("nInvalid edge!n"); i--; } else { adj[origin][destin]=wt; adj[destin][origin]=wt; } } if(i<n-1) { printf("nSpanning tree is not possiblen"); exit(1); } } display() { int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) printf("%3d",adj[i][j]); printf("n"); } } int maketree(struct edge tree[MAX],int *weight) { struct node state[MAX]; int i,k,min,count,current,newdist; int m; int u1,v1; *weight=0; for(i=1;i<=n;i++) { state[i].predecessor=0; state[i].dist = infinity; state[i].status = TEMP; 82
  • 83. } state[1].predecessor=0; state[1].dist = 0; state[1].status = PERM; current=1; count=0; while( all_perm(state) != TRUE ) { for(i=1;i<=n;i++) { if ( adj[current][i] > 0 && state[i].status == TEMP ) { if( adj[current][i] < state[i].dist ) { state[i].predecessor = current; state[i].dist = adj[current][i]; } } } min=infinity; for(i=1;i<=n;i++) { if(state[i].status == TEMP && state[i].dist < min) { min = state[i].dist; current=i; } } state[current].status=PERM; u1=state[current].predecessor; v1=current; count++; tree[count].u=u1; tree[count].v=v1; *weight=*weight+adj[u1][v1]; } return (count); } int all_perm(struct node state[MAX] ) { int i; for(i=1;i<=n;i++) if( state[i].status == TEMP ) 83
  • 84. return FALSE; return TRUE; } Output:- ******** MINIMUM SPANNING TREE FROM PRIM'S ALGORITHM ******** Enter number of vertices : 7 Enter edge 1(0 0 to quit) : 1 2 Enter weight for this edge : 3 Enter edge 2(0 0 to quit) : 1 3 Enter weight for this edge : 10 Enter edge 3(0 0 to quit) : 1 4 Enter weight for this edge : 2 Enter edge 4(0 0 to quit) : 1 5 84
  • 85. Enter weight for this edge : 4 Enter edge 5(0 0 to quit) : 2 5 Enter weight for this edge : 7 Enter edge 6(0 0 to quit) : 3 4 Enter weight for this edge : 12 Enter edge 7(0 0 to quit) : 3 6 Enter weight for this edge : 15 Enter edge 8(0 0 to quit) : 4 5 Enter weight for this edge : 6 Enter edge 9(0 0 to quit) : 4 6 Enter weight for this edge : 4 Enter edge 10(0 0 to quit) : 5 6 Enter weight for this edge : 5 Enter edge 11(0 0 to quit) : 5 7 Enter weight for this edge : 2 Enter edge 12(0 0 to quit) : 6 7 Enter weight for this edge : 3 Enter edge 13(0 0 to quit) : 0 0 Adjacency matrix is : 0 3 10 2 4 0 0 3 0 0 0 7 0 0 10 0 0 12 0 15 0 2 0 12 0 6 4 0 4 7 0 6 0 5 2 0 0 15 4 5 0 3 0 0 0 0 2 3 0 85
  • 86. Weight of spanning tree is : 24 Edges to be included in spanning tree are : 1->4 1->2 1->5 5->7 7->6 1->3 86