CN All Programs
CN All Programs
(a)
#include<stdio.h>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame length:");
scanf("%d",&n);
printf("Enter input frame (0's & 1's only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0; count=1; j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1 && k<n && count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
}
Out Put:
Enter frame length:6
Enter input frame (0's & 1's only):1
1
1
1
1
1
After stuffing the frame is:1111101
1.(b)
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("Enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("Enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);}
printf("Enter the character\n");
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\nframe after stuffing:\n");
printf("%s",b);
}
Enter string
SVCETA
Enter position
2
Enter the character
frame after stuffing:
dlestxSdldleVCETAdleetx
(2)
#include<stdio.h>
#include<stdlib.h>
k = 0;
for(i=0;i<nq;i++)
{
if(r[i]==0)
{
for(j=i;j<(i+ng);j++)
{
r[j]=r[j]^0;
}
q[i]=0;
}
else
{
for(j=i;j<(i+ng);j++)
{
r[j]=r[j]^g[k];
k++;
}
q[i]=1;
k=0;
}
}
return (0);
}
main()
{
int *gx,*tx,*q,*r;
int i,j,nt,ng,nq,n,flag=1;
n=nt+ng-1;
nq=nt;
gx=malloc(sizeof(int)*ng);
tx=malloc(sizeof(int)*n);
r=malloc(sizeof(int)*n);
q=calloc(nq,sizeof(int));
/* *****AT TRANSMITTER***** */
printf("\n CRC at transmitter :");
printf("\n Message to be transmitted :");
print(tx,nt);
printf("\n G(x)=");
print(gx,ng);
printf("\n Message with '0' appended :");
print(r,n);
crc(gx,q,r,ng,nq);
for(i=0;i<nt;i++)
{
r[i]=tx[i];
}
/* ***** AT RECEIVER***** */
printf("\n CRC at receiver :");
printf("\n Message received :");
print(r,n);
printf("\n G(x)=");
print(gx,ng);
crc(gx,q,r,ng,nq);
for(i=0;i<n;i++)
{
if(r[i]!=0)
{
flag=0;
break;
}
}
if(flag)
printf("\n No error detected -->CRC algorithm implemented
successfully.");
else
printf("\n Error detected.");
getch();
Enter message :0 1 1 0 1 1 0 1
Enter G(x) :1 0 1 0 1
CRC at transmitter :
Message to be transmitted :01101101
G(x)=10101
Quotient at transmitter:01110111
CRC at receiver :
Message received :011011011011
G(x)=10101
(3)
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
scanf("%d",&w);
scanf("%d",&f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in the following manner (assuming
no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for acknowledgement sent by the
receiver\n\n",w);
for(i=1;i<=f;i++)
if(i%w==0)
printf("%d\n",frames[i]);
else
printf("%d ",frames[i]);
if(f%w!=0)
return 0;
Output:
(4)
#include<conio.h>
#include<stdio.h>
static int dsp[10][10],nodes,perm,tem;
struct
{
char src;
char dest;
int length;
} stemp,permanent[10]={' ',' ',0},temp[10]={' ',' ',-1};
void sort()
{
int i,j,k;
for(i=0;i<=tem;i++)
{
k=1;
for(j=0;j<=tem;j++)
{
if((temp[j].length<=temp[j+1].length))
{
stemp=temp[j];
temp[j]=temp[j+1];
temp[j+1]=stemp;
k=0;
}
}
if(k)
break;
}
permanent[perm++]=temp[tem-1];
temp[tem-1].src=' ';
temp[tem-1].dest=' ';
temp[tem-1].length=-1;
tem--;
}
void main()
{
int i,j,k,l,m,n=0,point;
char initial,dest,path[10]={' '};
clrscr();
printf("\t\t Shortest path dijkstra's algothrim");
printf("\n **************************************\n");
printf("Enter the number of nodes:\n");
scanf("%d",&nodes);
printf("\nEnter the adjacency matrix");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
scanf("%d",&dsp[i][j]);
}
fflush(stdin);
printf("\n Enter the source node");
scanf("%c",&initial);
fflush(stdin);
printf("\n Enter the destination node\n");
scanf("%c",&dest);
permanent[perm].src=initial;
permanent[perm].dest=initial;
permanent[perm++].length=0;
i=permanent[perm-1].dest-97;
for(j=0;j<nodes;j++)
{
if(i!=j)
{
if(dsp[i][j]>0)
{
temp[tem].src=permanent[perm-1].src;
temp[tem].dest=j+97;
temp[tem++].length=dsp[i][j];
}
}
}
sort();
while(tem>=0)
{
j=permanent[perm-1].dest-97;
for(i=0;i<nodes;i++)
{
if(i!=initial-97)
{
if(dsp[j][i]>0)
{
l=-1;
for(k=0;k<perm;k++)
{
if(permanent[k].dest==(i+97))
l=k;
}
for(k=0;k<=tem;k++)
{
if(temp[k].dest==(i+97))
l=k;
}
if(l<0)
{
temp[tem].src=j+97;
temp[tem].dest=i+97;
for(m=0;m<perm;m++)
{
if(permanent[m].dest==temp[tem].src)
n=permanent[m].length;
}
temp[tem++].length=dsp[j][i]+n;
}
else
{
for(m=0;m<perm;m++)
{
if(permanent[m].dest==j+97)
{
n=permanent[m].length+dsp[j][i];
break;
}
else
n=dsp[j][i];
}
if((n<temp[l].length))
{
temp[l].length=n;
temp[l].src=j+97;
tpaemp[l].dest=i+97;
} } } } }
sort();
}
printf("\n shortest path :\n\n");
printf("from %c to %c is:",initial,dest);
for(i=0;i<perm-1;i++)
{
if(permanent[i].dest==dest)
{
point=i;
n=i;
break;
}
}
i=0;
for(j=perm;j>0;j--)
{
if(permanent[j-1].dest==permanent[point].src)
{
path[i++]=permanent[point].dest;
point=j-1;
} }
path[i]=initial;
for(j=i;j>=0;j--)
{
printf("%c",path[j]);
if(j>0)
printf("----->"); }
printf("\t length=%d",permanent[m].length);
getch();
}
Output :
(5)
#include<stdio.h>
main()
{
int n,a[10][10],i,j,k;
}
Output :
(6)
#include"stdio.h"
#include"conio.h"
void main()
int i=0,j=0,nei,n,ah[20];
int v[50][50],r[20],min=10000,si;
char s[50],dest,line[50];
for(i=0;i<50;i++)
s[i]= NULL;
clrscr();
scanf("%d",&n);
scanf("%s",&dest);
scanf("%d",&nei);
for(i=0;i<=nei;i++)
scanf("%s",s[i]);
for(j=0;j<nei;)
scanf("%d",&ah[j]);
j++; }
for(i=0;i<n;i++)
for(j=0;j<nei;j++)
scanf("%d",&v[i][j]);
for(i=0;i<n;i++)
{
min=10000;
for(j=0;j<nei;j++)
if(v[i][j]+ah[j]<min)
{
min=v[i][j]+ah[j];
line[i]=s[j];
}r[i]=min;
if(dest-97==i)
{ r[i]=0;
line[i]=' ';
printf(" Line\n____________________________
_________________\n\n");
for(i=0;i<n;i++)
getch();
OUTPUT:
(7)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
int i,ch,lp;
char cipher[50],plain[50];
char key[50];
clrscr();
while(1)
{
printf("\n-----MENU-----");
printf("\n1:Data Encryption\t2:Data Decryption\t3:Exit");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nData Encryption");
printf("\nEnter the plain text:");
fflush(stdin);
gets(plain);
printf("\nEnter the encryption key:");
gets(key);
lp=strlen(key);
for(i=0;plain[i]!='\0';i++)
cipher[i]=plain[i]^lp;
cipher[i]='\0';
printf("\nThe encrypted text is:");
puts(cipher);
break;
case 3: exit(0);
}
}
Output:
-------Menu--------
1. Data Encryption
2. Data Decryption
3. Exit
Data Encryption
-------Menu--------
1. Data Encryption
2. Data Decryption
3. Exit
Data Decryption
-------Menu--------
1. Data Encryption
2. Data Decryption
3. Exit
7(b)
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
void main()
{
char pwd[20];
char alpha[26]="abcdefghijklmnopqrstuvwxyz";
int num[20],i,n,key;
clrscr();
printf("\nEnter the password:");
scanf("%s",&pwd);
n=strlen(pwd);
for(i=0;i<n;i++)
num[i]=toascii(tolower(pwd[i]))-'a';
printf("\nEnter the key:");
scanf("%d",&key);
for(i=0;i<n;i++)
num[i]=(num[i]+key)%26;
for(i=0;i<n;i++)
pwd[i]=alpha[num[i]];
printf("\nThe key is:%d",key);
printf("\nEncrypted text is:%s",pwd);
for(i=0;i<n;i++)
{
num[i]=(num[i]-key)%26;
if(num[i]<0)
num[i]=26+num[i];
pwd[i]=alpha[num[i]];
}
printf("\nDecrypted text is:%s",pwd);
getch();
}
Output:
Input:
Output:
(8)
#include< stdio.h>
#include< conio.h>
int phi,M,n,e,d,C,FLAG;
void check()
{
int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{
FLAG = 1;
return;
}
FLAG = 0;
}
void encrypt()
{
int i;
C = 1;
for(i=0;i< e;i++)
C=C*M%n;
C = C%n;
printf("\n\tEncrypted keyword : %d",C);
}
void decrypt()
{
int i;
M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
printf("\n\tDecrypted keyword : %d",M);
}
void main()
{
int p,q,s;
clrscr();
printf("Enter Two Relatively Prime Numbers\t: ");
scanf("%d%d",&p,&q);
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do
{
printf("\n\nEnter e\t: ");
scanf("%d",&e);
check();
}while(FLAG==1);
d = 1;
do
{
s = (d*e)%phi;
d++;
}while(s!=1);
d = d-1;
printf("\n\tPublic Key\t: {%d,%d}",e,n);
printf("\n\tPrivate Key\t: {%d,%d}",d,n);
printf("\n\nEnter The Plain Text\t: ");
scanf("%d",&M);
encrypt();
printf("\n\nEnter the Cipher text\t: ");
scanf("%d",&C);
decrypt();
getch();
}
OUTPUT :
F(n) = 96
Enter e : 5
Encrypted keyword : 66
(9)
1.ping: ping(8) sends an ICMP ECHO_REQUEST packet to the specified host. If the
host responds, you get an ICMP packet back. Sound strange? Well, you can “ping” an IP
address to see if a machine is alive. If there is no response, you know something is wrong.
2.Traceroute:
Tracert is a command which can show you the path a packet of information takes from
your computer to one you specify. It will list all the routers it passes through until it reaches its
destination, or fails to and is discarded. In addition to this, it will tell you how long each 'hop'
from router to router takes.
3.nslookup:
C:\Users\Thyagarajan>nslookup
Default Server: dns.google
Address: 2001:4860:4860::8888
A better version of tracert that gives you statics about packet lost and latency.
(10)
Aim:
To Configure IP Address in a system in LAN (TCP/IP Configuration) and Configure DNS to establish
interconnection between systems
Principle: Following is required to be study under this practical.
• Classification of IP address
Class A 1.0.0.1 to 126.255.255.254 Supports 16 million hosts on each of 127 networks.
Class B 128.1.0.1 to 191.255.255.254 Supports 65,000 hosts on each of 16,000 networks.
Class C 192.0.1.1 to 223.255.254.254 Supports 254 hosts on each of 2 million networks.
Class D 224.0.0.0 to 239.255.255.255 Reserved for multicast groups.
Class E 240.0.0.0 to 254.255.255.254 Reserved.
• Sub netting
• Subnet ting is dividing the network into two or more networks is called subnet ting.
Procedure:
(a) Steps to configure IP address, Subnet mask and Default Gateway:
1. Click on the Start button and select Control Panel then Network and Internet Connections.
2. Click Network and Internet Connections.
3. Right click on the Local Area Connection icon and select Properties.
4. Select Internet Protocol (TCP/IP).
5. Click on the Properties button.
6. Uncheck that Obtain an IP address automatically and Obtain DNS server address automatically and
put
IP, Subnet mask & Default Gateways.
7. Click on the Advanced button and select the DNS tab in the Advanced TCP/IP Settings window.
8. Ensure that Register this connection's addresses in DNS is not selected.
9. Click OK, OK, then Close to close all boxes.
Result :
Configuration of IP Address in a system in LAN (TCP/IP Configuration) and Configuration to establish
interconnection between systems have been done successfully