0% found this document useful (0 votes)
4K views26 pages

Implement On A Data Set of Characters The Three CRC Polynomials

The document describes an implementation of broadcasting in a network. It defines variables to store the adjacency matrix and broadcast tree. It gets the number of routers as input and their time delays. It then iterates to find the minimum time delay edge and adds it to the broadcast tree, removing it from the graph. This continues until all routers are spanned in the broadcast tree.

Uploaded by

Slim Shady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views26 pages

Implement On A Data Set of Characters The Three CRC Polynomials

The document describes an implementation of broadcasting in a network. It defines variables to store the adjacency matrix and broadcast tree. It gets the number of routers as input and their time delays. It then iterates to find the minimum time delay edge and adds it to the broadcast tree, removing it from the graph. This continues until all routers are spanned in the broadcast tree.

Uploaded by

Slim Shady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP

#include<stdio.h>

#include<conio.h>

void main()

int f[150],g[150],r[150],t[150],i,j,k,m,n,c=0;

clrscr();

printf("\n Enter f: ");

scanf("%d",&n);

for(i=0;i<n;i++)

scanf("%d",&f[i]);

t[i]=f[i];

printf("\n Enter g: ");

scanf("%d",&m);

for(i=0;i<m;i++)

scanf("%d",&g[i]); }

for(i=n;i<n+m;i++)

t[i]=0;

for(i=0;i<n;i++)

k=i;

if(t[i]==1)

{
for(j=0;j<m;j++,k++)

if(t[k]==g[j])

t[k]=0;

else

t[k]=1;

printf("\n check sum is : ");

for(i=n;i<m+n-1;i++)

printf(" %d ",t[i]);

f[i]=t[i];

printf("\n\n BCS : ");

for(i=0;i<m+n-1;i++)

printf(" %d ",f[i]);

printf("\n\nEnter received data : ");

for(i=0;i<m+n-1;i++)

scanf("%d",&r[i]);

for(i=0;i<n;i++)

k=i;

if(r[i]==1)

{
for(j=0;j<m;j++,k++)

if(r[k]==g[j])

r[k]=0;

else

r[k]=1;

printf(“Received data checksum\n”);

for(i=n;i<m+n-1;i++)

printf(“%d”,r[i]);

if(r[i]!=0)

c=1;

if(c==1)

printf("\n Error ");

else

printf("\n NO error");

getch();

OUTPUT 1:
Enter f: 24

111100001010101010000000

Enter g: 12

1 10000001 1 1 1

check sumis:010000001 10

BCS : 111100001010101010000000 01000000110

Enter received data: 1 1 1 100001010101010000000 0100 0000 1 10

Check sum is; 00000000000 NO error

OUTPUT 2:

Enter f: 24

101010101111111 100000000

Enter g: 16

11000000000000101

check sumis:001000001000110

BCS: 101010101111111100000000 001000001000110

Enter received data : 1111111111111111 111111111111 1111111111

Checksum is: 110110011001101 Error

Program 4

Implement Dijkstra‘s algorithm to compute the Shortest path through a graph

#include<stdio.h>

#include<conio.h>

#define INFINITY 10000

void main()

int gptr[20][20],set[20],path[20],length[20],s,i,j,k,n,m,temp,c;
clrscr();

/* INPUT */

printf("Enter No Of Vertexes\n");

scanf("%d",&n);

printf("Enter Adjacency Matrix of a Graph \n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

scanf("%d",&gptr[i][j]);

printf("Enter Source node \n");

scanf("%d",&s);

/* INTIALIZATION PART */

for(i=1;i<=n;i++)

set[i]=0;

for(i=1;i<=n;i++)

if(gptr[s][i]==0)

length[i]=INFINITY;

path[i]=0;

else

length[i]=gptr[s][i];
path[i]=s;

set[s]=1;

length[s]=0;

/*ITERATION PART */

temp=1;

while(temp)

c=0;

j=search_min(length,set,n);

set[j]=1;

for(i=1;i<=n;i++)

if(set[i]!=1)

if(gptr[i][j]!=0)

if(length[j]+gptr[i][j]<length[i])

length[i]=length[j]+gptr[i][j];

path[i]=j;

for(i=1;i<=n;i++)

{
if(set[i]==0)

c++;

if(c==0)

temp=0;

else

temp=1;

/*OUTPUT */

printf("length\tpath\n");

for(i=1;i<=n;i++)

printf("%d\t%d\n",length[i],path[i]);

printf("\n-------------------------------------------------------\n");

printf("\tPath\t\tLength\tShortest path \n");

printf("----------------------\n");

printf("From(sourcevertex) To \n");

printf("--------------------------------------------------------\n");

printf("\t%d\n",s);

for(i=1;i<=n;i++)

if(i!=s)

printf("\t\t%4d\t%2d",i,length[i]);

j=i;

while(j!=s)

printf("\t%d->%d",j,path[j]);

j=path[j];

}
printf("\n");

getch();

/* search min function */

search_min(int length[],int set[],int n)

int i,j,v,min=100;

for(i=1;i<=n;i++)

if(set[i]==0)

if(length[i]<min)

min=length[i];

v=i;

return v;

OUTPUT 1:

Enter No Of Vertexes

5
Enter Adjacency Matrix of a Graph

01600

10235

62042

03402

05220

Enter Source node

length path

0 0

1 1

3 2

4 2

5 3

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

Path Length Shortest path

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

From(sourcevertex) To

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

2 1 2->1

3 3 3->2 2->1

4 4 4->2 2->1

5 5 5->3 3->2 2->1

OUTPUT 2:
Enter No Of Vertexes

Enter Adjacency Matrix of a Graph

01600

10235

62042

03402

05220

Enter Source node

length path

3 2

2 3

0 0

4 3

2 3

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

Path Length Shortest path

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

From(sourcevertex) To

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

1 3 1->2 2->3

2 2 2->3

4 4 4->3

5 2 5->3
Program 5

IMPLEMENTATION OF DISTANCE VECTOR:

#include<stdio.h>

#include<conio.h>

#define INFINITY 10000

void main()

int adj[50][50],length[50][50],path[50][50],set[50],i,j,n,s,t,c;

clrscr();

printf("Enter No Of Routers\n");

scanf("%d",&n);

printf("Enter Adjacency Matrix \n");

for(i=0;i<n;i++)

for(j=0;j<n;j++)

scanf("%d",&adj[i][j]);

//**********Intialization Part*********

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(adj[i][j]==0 && i!=j)

length[i][j]=INFINITY;

path[i][j]=0;

else

length[i][j]=adj[i][j];
path[i][j]=j;

if(i==j)

path[i][j]=131;

//**********Iteration Part*********

t=1;

while(t)

c=0;

for(s=0;s<n;s++)

for(j=0;j<n;j++)

if(adj[s][j])

for(i=0;i<n;i++)

if(length[s][j]+length[j][i]<length[s][i])

length[s][i]=length[s][j]+length[j][i];

path[s][i]=j;

for(s=0;s<n;s++)

for(i=0;i<n;i++)
if(length[s][i]==INFINITY)

c++;

if(c==0)

t=0;

else

t=1;

printf("\nRouting table\n\n");

for(i=65;i<(n+65);i++)

printf(" %c ",i);

printf("\n----------------------------------------------------\n");

for(i=0;i<n;i++)

printf(" l p");

printf("\n---------- ----- ------ ------ ------ ------ -------\n");

for(i=0;i<n;i++)

printf("%c",i+65);

for(s=0;s<n;s++)

printf(" %3d%3c |",length[s][i],path[s][i]+65);

printf("\n");

getch();

}
OUTPUT 1:

Enter No Of Routers

Enter Adjacency Matrix

0 9 0 0 8 10

7 0 6 0 0 15

050204

003050

12 0 0 4 0 12

11 16 4 0 10 0

Routing table

A B C D E F

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

l p l p l p l p l p l p

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

A 0 - | 7 A | 12 B | 15 C | 12 A | 11 A |

B 9 B | 0 - | 5 B | 8 C | 12 D | 9 C |

C 14 F | 6 C | 0 - | 3 C | 7 D | 4 C |

D 12 E | 8 C | 2 D | 0 - | 4 D | 6 C |

E 8 E | 15 A | 7 D | 5 E | 0 - | 10 E |

F 10 F | 10 C | 4 F | 7 C | 11 D | 0 - |

OUTPUT 2:
Enter No Of Routers

Enter Adjacency Matrix

0055

0063

8400

3100

Routing table

A B C D

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

l p l p l p l p

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

A 0 -| 6 D| 8 A| 3 A|

B 6 D| 0 -| 4 B| 1 B|

C 5 C| 6 C| 0 -| 7 B|

D 5 D| 3 D| 7 B| 0 -|

Program 6

IMPLEMENTATION OF BROADCASTING

#include<stdio.h>

#include<conio.h>

#define INFINITY 10000

//void search_min();

void main()

{
int c1,c2,gptr[50][50],bt[50][50],st[50][50],i,j,n,l,s,m,k,p,t;

int min,a=0,b=0,stcost=0,x[50],y[50];

clrscr();

//INPUT

printf("Enter No Of Routers \n");

scanf("%d",&n);

printf("Enter time delays between routers\n");

for(i=1;i<=n;i++)

for(j=i+1;j<=n;j++)

printf("%d->%d time delay ",i,j);

scanf("%d",&gptr[i][j]);

gptr[j][i]=gptr[i][j];

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

st[i][j]=0;

bt[i][j]=0;

if(i==j)

gptr[i][j]=0;

/***********Iteration************/

t=n;

while(t>1)

min=100;

for(i=1;i<=n;i++)
{

for(j=i+1;j<=n;j++)

if(gptr[i][j])

if(gptr[i][j]<min)

min=gptr[i][j];

l=i;

s=j;

gptr[l][s]=0;

c1=0;

for(i=0;i<a;i++)

if(x[i]==l)

c1++;

if(x[i]==s)

c1++;

if(c1==0)

x[a++]=l;

}
c2=0;

for(i=0;i<b;i++)

if(y[i]==s)

c2++;

if(y[i]==l)

c2++;

if(c2==0)

y[b++]=s;

if(c1!=2 && c2!=2 )

st[l][s]=min;

t--;

printf("Path\tTimedelay\n");

for(i=1;i<=n;i++)

for(j=i+1;j<=n;j++)

if(st[i][j])

printf("%d --> %d %4d \n",i,j,st[i][j]);

stcost+=st[i][j];
bt[i][j]=1;

bt[j][i]=1;

printf("It takes minimum %d seconds to broad cast data in given subnet",stcost);

printf("\nBroad cast tree is \n");

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

printf("%4d",bt[i][j]);

printf("\n");

getch();

OUTPUT 1:

Enter No Of Routers

Enter time delays between routers

1->2 time delay 0

1->3 time delay 4

1->4 time delay 5

2->3 time delay 6

2->4 time delay 2


3->4 time delay 0

Path Timedelay

1 --> 3 4

1 --> 4 5

2 --> 4 2

It takes minimum 11 seconds to broad cast data in given subnet

Broad cast tree is

0 0 1 1

0 0 0 1

1 0 0 0

1 1 0 0

OUTPUT 2:

Enter No Of Routers

Enter time delays between routers

1->2 time delay 20

1->3 time delay 0

1->4 time delay 0

1->5 time delay 0

1->6 time delay 23

1->7 time delay 1

2->3 time delay 15

2->4 time delay 0

2->5 time delay 0

2->6 time delay 0

2->7 time delay 4


3->4 time delay 3

3->5 time delay 0

3->6 time delay 0

3->7 time delay 9

4->5 time delay 17

4->6 time delay 0

4->7 time delay 16

5->6 time delay 28

5->7 time delay 25

6->7 time delay 36

Path Timedelay

1 --> 6 23

1 --> 7 1

2 --> 7 4

3 --> 4 3

3 --> 7 9

4 --> 5 17

It takes minimum 57 seconds to broad cast data in given subnet

Broad cast tree is

0 0 0 0 0 1 1

0 0 0 0 0 0 1

0 0 0 1 0 0 1

0 0 1 0 1 0 0

0 0 0 1 0 0 0

1 0 0 0 0 0 0

1 1 1 0 0 0 0

Program 7

IMPLEMENTATION OF RSA
#include<stdio.h>

#include<conio.h>

void main()

char pt[50],en[50],de[50];

long int i,j,t,z,p1,p2,c,nc,rn,sn;

long int ipt[50],temp[50],e=4,d,n,phi;

clrscr();

i=0;

printf("Enter plain text\n");

do

c=getchar();

pt[i++]=c;

}while(c!='\n');

pt[i]='\0';

nc=i-1;

l1:printf("Enter Any Random Number\n");

scanf("%ld",&rn);

if(rn<8 || rn>=180)

goto l1;

p1=prime(rn);

sn=p1+1;

p2=prime(sn);

n=p1*p2;

phi=(p1-1)*(p2-1);

while(gcd(phi,e)!=1 && e>1 && e<phi)

e++;
d=0;

while( (d*e)%phi!=1 )

d++;

printf(" p1 = %ld p2 = %ld \n Public key : {e,n}={%ld,%ld}: ",p1,p2,e,n);

printf("\n Private key : {d,n}={%ld,%ld}: ",d,n);

//Encryption

for(i=0;i<nc;i++)

ipt[i]=pt[i];

temp[i]=rsa(ipt[i],e,n);

en[i]=temp[i];

printf("\n Equalent Cipher text of given plain text is \n");

for(i=0;i<nc;i++)

printf("%c",en[i]);

//Decription

for(i=0;i<nc;i++)

temp[i]=rsa(temp[i],d,n);

de[i]=temp[i];

printf("\n Equlalent Plaint text of given cipher text is\n");

for(i=0;i<nc;i++)

printf("%c",de[i]);

getch();

prime(long int x)

{
long int i,j,t=1;

while(t)

j=0;

for(i=2;i<x;i++)

if(x%i==0)

j=1;

if(j==0)

t=0;

else

x++;

return x;

gcd(long int x,long int y)

long int temp;

if(x<y)

temp=x;

x=y;

y=temp;

while(y!=0)

temp=x%y;

x=y;

y=temp;

}
return x;

rsa(long int a,long int b,long int n)

long int i,d,c,l,k,binary[100];

k=0;

while(b!=1)

l=b/2;

binary[k]=b%2;

k++;

b=l;

binary[k]=b;

d=1;

for(i=k;i>=0;i--)

d=(d*d)%n;

if(binary[i]==1)

d=(d*a)%n;

return d;

OUTPUT 1:
Enter plain text

abcdABCD0123456789

Enter Any Random Number

36

p1 = 37 p2 = 41

Public key : {e,n}={7,1517}:

Private key : {d,n}={823,1517}:

Equalent Cipher text of given plain text is

BR"&FÑ---+ +#ª?`¦à

Equlalent Plaint text of given cipher text is

abcdABCD0123456789

You might also like