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
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
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
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
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
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
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
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
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
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
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
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
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