0% found this document useful (0 votes)
11 views70 pages

Aligned CN Record[1]

The document contains multiple MATLAB programs that simulate various probability distributions, including Poisson, Uniform, Binomial, Negative Binomial, Exponential, Gaussian, Geometric, Gamma, and Rayleigh distributions, and visualize their results using bar and plot graphs. Additionally, it analyzes user bandwidth allocation and error rates based on user input for the number of users and time slots, incorporating concepts of buffering and bandwidth management. The programs also calculate average bit error rates with and without buffering, providing insights into network performance under different conditions.

Uploaded by

saravanan
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)
11 views70 pages

Aligned CN Record[1]

The document contains multiple MATLAB programs that simulate various probability distributions, including Poisson, Uniform, Binomial, Negative Binomial, Exponential, Gaussian, Geometric, Gamma, and Rayleigh distributions, and visualize their results using bar and plot graphs. Additionally, it analyzes user bandwidth allocation and error rates based on user input for the number of users and time slots, incorporating concepts of buffering and bandwidth management. The programs also calculate average bit error rates with and without buffering, providing insights into network performance under different conditions.

Uploaded by

saravanan
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/ 70

PROGRAM:-

clear all;
clc;
disp('POISSION DISTRIBUTION');
lamda=input('ENTER THE VALUE OF LAMDA:');
x=1:50;
a=poisspdf(x,lamda);
subplot(5,2,1);
stem(a(1:10));
title('POISSION DISTRIBUTION');

x=1:50;
disp('UNIFORM (CONTINUOUS) DISTRIBUTION');
a1=input('ENTER THE VALUE OF A:');
b1=input('ENTER THE VALUE OF B:');
b=unifpdf(x,a1,b1);
subplot(5,2,2);
stem(x,b);
title('UNIFORM (CONTINUOUS) DISTRIBUTION');

x=1:50;
disp('UNIFORM (DISCRETE) DISTRIBUTION');
n=input('ENTER THE VALUE OF N:');
c=unidpdf(x,n);
subplot(5,2,3);
stem(x,c);
title('UNIFORM (DISCRETE) DISTRIBUTION');

x=1:50;
disp('BINOMIAL DISTRIBUTION');
n1=input('ENTER THE VALUE OF N:');
p=input('ENTER THE VALUE OF P:');
d=binopdf(x,n1,p);
subplot(5,2,4);
stem(d(1:20));
title('BINOMIAL DISTRIBUTION');

x=1:50;
disp('NEGATIVE BINOMIAL DISTRIBUTION');
n2=input('ENTER THE VALUE OF R:');
p1=input('ENTER THE VALUE OF P:');
e=nbinpdf(x,n2,p1);

subplot(5,2,5);
stem(e(1:20));
title('NEGATIVE BINOMIAL DISTRIBUTION');
x=0:0.1:50;
disp('EXPONENTIAL DISTRIBUTION');
mu=input('ENTER THE VALUE OF MU:');
f=exppdf(x,mu);
subplot(5,2,6);
plot(x,f);
title('EXPONENTIAL DISTRIBUTION');

x=-50:0.1:50;
disp('GAUSSIAN (NORMAL) DISTRIBUTION');
mu1=input('ENTER THE VALUE OF MU:');
sig=input('ENTER THE VALUE OF SIGMA:');
g=normpdf(x,mu1,sig);
subplot(5,2,7);
plot(x,g);
title('GAUSSIAN (NORMAL) DISTRIBUTION');

x=0:50;
disp('GEOMETRIC DISTRIBUTION');
p2=input('ENTER THE VALUE OF P(interval[0,1]):');
h=geopdf(x,p2);
subplot(5,2,8);
bar(h(1:20));
title('GEOMETRIC DISTRIBUTION');

x=0:.001:20;
disp('GAMMA DISTRIBUTION');
a2=input('ENTER THE VALUE OF A:');
b2=input('ENTER THE VALUE OF B:');
i=gampdf(x,a2,b2);
subplot(5,2,9);
plot(x,i);
title('GAMMA DISTRIBUTION');

x=0:.001:20;
disp('RAYLEIGH DISTRIBUTION');
b3=input('ENTER THE VALUE OF B:');
j=raylpdf(x,b3);
subplot(5,2,10);
plot(x,j);
title('RAYLEIGH DISTRIBUTION');
OUTPUT:-

POISSION DISTRIBUTION
ENTER THE VALUE OF LAMDA:5
UNIFORM (CONTINUOUS) DISTRIBUTION
ENTER THE VALUE OF A:5
ENTER THE VALUE OF B:15
UNIFORM (DISCRETE) DISTRIBUTION
ENTER THE VALUE OF N:15
BINOMIAL DISTRIBUTION
ENTER THE VALUE OF N:10
ENTER THE VALUE OF P:5
NEGATIVE BINOMIAL DISTRIBUTION
ENTER THE VALUE OF R:5
ENTER THE VALUE OF P:.5
EXPONENTIAL DISTRIBUTION
ENTER THE VALUE OF MU:5
GAUSSIAN (NORMAL) DISTRIBUTION
ENTER THE VALUE OF MU:1
ENTER THE VALUE OF SIGMA:10
GEOMETRIC DISTRIBUTION
ENTER THE VALUE OF P(interval[0,1]):.5
GAMMA DISTRIBUTION
ENTER THE VALUE OF A:5
ENTER THE VALUE OF B:3
RAYLEIGH DISTRIBUTION
ENTER THE VALUE OF B:10
POISSION DISTRIBUTION UNIFORM (CONTINUOUS) DISTRIBUTION
0.2 0.1

0.1 0.05

0 0
0 2 4 6 8 10 0 10 20 30 40 50
UNIFORM (DISCRETE) DISTRIBUTION BINOMIAL DISTRIBUTION
0.1 1

0.05 0

0 -1
0 10 20 30 40 50 0 5 10 15 20
NEGATIVE BINOMIAL DISTRIBUTION EXPONENTIAL DISTRIBUTION
0.2 0.2

0.1 0.1

0 0
0 5 10 15 20 0 10 20 30 40 50
GAUSSIAN (NORMAL) DISTRIBUTION GEOMETRIC DISTRIBUTION
0.04 0.5

0.02

0 0
-50 0 50 0 5 10 15 20 25
GAMMA DISTRIBUTION RAYLEIGH DISTRIBUTION
0.1 0.1

0.05 0.05

0 0
0 5 10 15 20 0 5 10 15 20
PROGRAM:-

clc;
clear all;
x=1:10;
t=1:100;
on=input('Enter the average time:');
%USER VS AVERAGE ON TIME
ton=zeros(10,100);
for i=1:10
ton(i,:)=poissrnd((on*10),1,100);
end
a=ton';
b=mean(a);
c=b/10;
figure(1);
bar(x,c);
xlabel('user');
ylabel('Average on time');
%TIME SLOT VS NUMBER OF USER
n=zeros(10,100);
for i=1:10
for j=1:100
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
d=sum(n);
figure(2);
bar(t,d);
xlabel('Time slots');
ylabel('Number of user');
%TIME SLOTS VS BANDWIDTH
bw=64000*n;
for i=1:10
figure(3);
subplot(5,2,i);
bar(t,bw(i,:),0.2);
xlabel('Time slot');
ylabel('Bw allocation');
end

OUTPUT:-
Enter the average time:0.35
PROGRAM:-

clc;
clear all;
use=input('enter the no of user:');
ts=input('enter the no of time slot:');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts;
ton(i,:)=poissrnd((on*10),1,ts);
if ton(i,j)>=3.5
n(i,j)=1;
end
end
end
voice=64000*n;
%TIME SLOT VS BANDWIDTH
d=sum(voice);
figure(1);
bar(d);
xlabel('time slot');
ylabel('bandwidth(bps)');
%TIME SLOT VS ERROR
e=zeros(1,ts);
bm=1540000;
for i=1:ts;
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('time slot');
ylabel('error rate(bps)');
avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('average bit error without buffering');
disp(ber);
while ber>1e-6
buff=buff+10;
bm=bm+10;
for i=1:ts
if e(i)>0
e(i)=d(i)-bm;
end
end
s=sum(e');
ber=s/(ts*bm);
end
disp('bit error rate with buffer');
disp(ber);
disp('optimum buffer size:');
disp(buff);

OUTPUT:-

enter the no of user:60


enter the no of time slot:100
average bit error without buffering
0.1857

bit error rate with buffer


9.6736e-007

optimum buffer size:


1147740
PROGRAM:-

clear all;
close all;
clc;
use=input('enter the no of user:');
ts=input('enter the no of time slot:');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
test=randint(use,ts,[1,1000]);
data=n;
for i=1:use
for j=1:ts
if n(i,j)==1
if test(i,j)>=1 & test(i,j)<=980
data(i,j)=64000;
else if test(i,j)>980 & test(i,j)<=990
data(i,j)=128000;
else if test(i,j)>990 & test(i,j)<=998
data(i,j)=256000;
else
data(i,j)=512000;
end
end
end
end
end
end

%TIME SLOT VS BANDWIDTH


d=sum(data);
figure(1);

bar(d);
xlabel('time slot');
ylabel('bandwidth(bps)');
%TIME SLOT VS ERROR RATE
e=zeros(1,ts);
bm=1540000;
for i=1:ts
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('time slot');
ylabel('error rate(bps)');
avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('average bit error without buffering:');
disp(ber);
while ber>1e-6
buff=buff+10;
bm=bm+10;
for i=1:ts
if e(i)>0
e(i)=d(i)-bm;
end
end
s=sum(e');
ber=s/(ts*bm);
end
disp('bit error rate with buffer:');
disp(ber);
disp('optinum buffer size:');
disp(buff);

OUTPUT
enter the no of user:80
enter the no of time slot:120
average bit error without buffering: 0.6274
bit error rate with buffer: 9.8282e-007
optinum buffer size: 1851600
PROGRAM:-

clear all;
close all;
clc;
use=input('enter the no of user:');
ts=input('enter the no of time slot:');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
test=randint(use,ts,[1,1000]);
data=n;
for i=1:use
for j=1:ts
if n(i,j)==1
if test(i,j)>=1 & test(i,j)<=980
data(i,j)=64000;
else
data(i,j)=384000;
end
end
end
end

%TIME SLOT VS BANDWIDTH


d=sum(data);
figure(1);
bar(d);
xlabel('Time slot');
ylabel('Bandwidth(bps)');

%TIME SLOT VS ERROR RATE


e=zeros(1,ts);
bm=1540000;
for i=1:ts;
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('time slot');
ylabel('error rate(bps)');

avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('Average bit error without buffering:');
disp(ber);
while ber>1e-6
buff=buff+10;
bm=bm+10;
for i=1:ts
if e(i)>0
e(i)=d(i)-bm;
end
end

s=sum(e');
ber=s/(ts*bm);
end
disp('Bit error rate with buff:');
disp(ber);
disp('Optimum buffer size:');
disp(buff);

OUTPUT:-

enter the no of user:60


enter the no of time slot:100
Average bit error without buffering: 0.2464
Bit error rate with buff: 9.8120e-007
Optimum buffer size: 1211730
PROGRAM:-

clear all;
close all;
clc;
use=input('enter the no of user:');
ts=input('enter the no of time slot:');
on=0.35;
voiceuser=0;
datauser=0;
voipuser=0;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
userprob=randint(1,use,[1,10]);
userinden=ones(1,use);
for i=1:use
if userprob(i)>=1 &&userprob(i)<=5
useriden(i)=1;
voiceuser=voiceuser+1;
elseif userprob(i)>5 &&userprob(i)<=8
useriden(i)=2;
voipuser=voipuser+1;
else
useriden(i)=3;
datauser=datauser+1;
end
end

isdn=64000*n;
test=randint(voipuser,ts,[1,1000]);
for i=voiceuser+1:voipuser+voiceuser
for j=1:ts
if n(i,j)==1
if test(i-voiceuser,j)>=1 & test(i-voiceuser,j)<=800
isdn(i,j)=64000;
else
isdn(i,j)=384000;
end
end
end
end
test1=randint(datauser,ts,[1,1000]);
for i=voiceuser+voipuser+1:use
for j=1:ts
if n(i,j)==1
if test(i-(voiceuser+voipuser),j)>=1 && test1(i-(voiceuser+voipuser),j)<=800
isdn(i,j)=64000;
elseif test1(i-(voiceuser+voipuser),j)>800 && test1(i-(voiceuser+voipuser),j)<=900
isdn(i,j)=128000;
elseif test1(i-(voiceuser+voipuser),j)>900 && test1(i-
(voiceuser+voipuser),j)<=950
isdn(i,j)=256000;
else
isdn(i,j)=512000;
end
end
end
end

%TIME SLOT VS BANDWIDTH


d=sum(isdn);
figure(1);
bar(d);
xlabel('time slot'),ylabel('Bandwidth');

%TIME SLOT VS ERROR RATE


e=zeros(1,ts);
bm=1984000;
for i=1:ts
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('time slot'),ylabel('error rate');
buff=0;
newbw=1984000+buff;
prisdn=isdn(1:voiceuser,:);
voipsort=isdn(voiceuser+1:voiceuser+voipuser,:);
prisdn(voiceuser+1:voiceuser+voipuser,:)=sort(voipsort,1);
datasort=isdn(voiceuser+voipuser+1:use,:);
prisdn(voiceuser+voipuser+1:use,:)=sort(datasort,1);

%TO FIND HOW USER GO UNSEVERED LENGTH WITHOUT BUFFER


unservedvoice=zeros(1,ts);
unservedvoip=zeros(1,ts);
unserveddata=zeros(1,ts);
for i=1:ts
j=0;
bwalloc=0;
while(bwalloc<=newbw&& j<use)
j=j+1;
bwalloc=bwalloc+prisdn(j,i);
end
ch=j;%-1
if ch<voiceuser
unservedvoice(i)=voiceuser-ch;
unservedvoip(i)=voipuser;
unserveddata(i)=datauser;
else if ch>=(voiceuser) &&ch<(voiceuser+voipuser)
unservedvoip(i)=voiceuser+voipuser-ch;
unserveddata(i)=datauser;
elseif ch>=(voiceuser+voipuser) &&ch<use
unserveddata(i)=use-ch;
end
end
end

figure(3);
bar(unservedvoice);
xlabel('time slot');
ylabel('unserved voice user');
figure(4);
bar(unservedvoip);
xlabel('time slot'),ylabel('unserved voipuser');
figure(5);
bar(unserveddata);
xlabel('time slot'),ylabel('unserved data');

OUTPUT:-

enter the no of user:60


enter the no of time slot:100
ISDN TRAFFIC
PROGRAM:-

clc;

clear;

x=input('enter the no.of reg:');

len=(2^x)-1;

fori=1:x

if (i==1)

r(i)=1;

else

r(i)=0;

end

disp(r(i));

end

for j=1:len

out(j)=xor(r(1),r(x));

for s=x:-1:1

if(s==1)

r(s)=out(j);

else

r(s)=r(s-1);

end

end

end
%balance property%

ones=0;

zeros=0;

fori=1:len

if (out(i)==1)

ones=ones+1;

else

zeros=zeros+1;

end

end

if (ones==(zeros+1))

disp('balance properytsaiesfied');

else

disp('balance property not satisfied');

end

%runlength property%

run=0;

for j=1:(len-1)

if (out(j)~=out(j+1))

run=run+1;

end

end

fprintf('\n no of runs=%d',run);

if (run==2^(x-1))
fprintf('\n run property satisfied');

else

printf('\n run property not satisfied')

end

%auto correlation%

temp=out(len);

fprintf('\n pn sequence is....');

output=out;

for j=1:-1:2

output(j)=output(j-1);

end

output(1)=temp;

disp(output);

agree=0;

disagree=0;

for j=1:len

if(output(j)==out(j))

agree=agree+1;

end

end

if(disagree>agree)

fprintf('\n auto correlation property is satisfied');

else
fprintf('\n auto correlation property not satisfied');

end

OUTPUT:-

Enter the No.of Reg:4

Balance property satisfied

No of runs=8

Run property satisfied

PN sequence is.... 1 1 1 0 1 0 1 1 0 0 1 0 0 0 1

Auto correlation property not satisfied


PROGRAM:-
clc;
clear all;
arrivalrate=input('ENTER THE ARRIVAL RATE:');
servicerate=input('ENTER THE DATA SERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS:');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr(1,:)=poissrnd((arrivalrate),1,timeslots);
tser(1,:)=poissrnd((servicerate),1,timeslots);

%TIMESLOT VS PACKETLOSS

n=zeros(1,timeslots);
for j=1:timeslots
if(tarr(1,j)>tser(1,j))
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;
bar(t,n,0.01);
xlabel('TIMESLOT'),ylabel('PACKETLOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);

%BUFFERSIZE VS PACKETLOSS

buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
count=count+1;
buff=buff+1;
tser=tser+1;
for j=1:timeslots
if(n(1,j)>0)
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;
avg=mean(n);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');

OUTPUT:-

ENTER THE ARRIVAL RATE:50


ENTER THE DATA SERVICE RATE:30
ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2
THE MAXIMUM PACKET LOSS IS:40
THE AVERAGE PACKETLOSS BEFORE BUFFERING IS: 18.9500
THE MAX PACKET LOSS AFTER BUFFERING IS:17
THE AVERAGE PACKET LOSS AFTER BUFFERING IS: 1.9800
THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS: 23
40

35

30

25
PACKETLOSS

20

15

10

0
0 20 40 60 80 100 120
TIMESLOT

20

18

16

14
PACKETLOSS

12

10

0
0 5 10 15 20 25
BUFFERSIZE
PROGRAM:-
clc;
clear all;
arrivalrate=input('ENTER THE ARRIVAL RATE:');
servicerate=input('ENTER THE DATA SERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr(1,:)=poissrnd((arrivalrate),1,timeslots);
tser(1,:)=exprnd((servicerate),1,timeslots);
tser=round(tser);

%TIMESLOT VS PACKETLOSS

n=zeros(1,timeslots);
for j=1:timeslots
if(tarr(1,j)>tser(1,j))
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;
bar(t,n,0.01);
xlabel('TIMESLOT'),ylabel('PACKETLOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);

%BUFFERSIZE VS PACKETLOSS

buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
count=count+1;
buff=buff+1;
tser=tser+1;
for j=1:timeslots
if(n(1,j)>0)
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;
avg=mean(n);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');

OUTPUT:-

ENTER THE DATAARRIVAL RATE:50


ENTER THE DATASERVICE RATE:30
ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2
THE MAXIMUM PACKET LOSS IS:
57

THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:


25.1700

THE MAX PACKET LOSS AFTER BUFFERING IS:


17

THE AVERAGE PACKET LOSS AFTER BUFFERING IS:


1.7800

THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:


40
40

35

30

25
PACKETLOSS

20

15

10

0
0 20 40 60 80 100 120
TIMESLOT

20

18

16

14
PACKETLOSS

12

10

0
0 5 10 15 20 25
BUFFERSIZE
PROGRAM:-

clc;
clear all;
arrivalrate=input('ENTER THE DATAARRIVAL RATE:');
servicerate=input('ENTER THE DATASERVICE RATE:');
errorrate=input('ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:');
%timeslots=input('ENTER THE NO.OF TIMESLOTS:');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr1(1,:)=normrnd((arrivalrate),5,1,timeslots);
tarr=round(tarr1);
tser1(1,:)=exprnd((servicerate),1,timeslots);
tser=round(tser1);

%TIMESLOT VS PACKETLOSS

n=zeros(1,timeslots);
for j=1:timeslots
if(tarr(1,j)>tser(1,j))
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;
bar(t,n,0.01);
xlabel('TIMESLOT'),ylabel('PACKET LOSS');
disp('THE MAXIMUM PACKET LOSS IS:');
disp(max(n));
disp('THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:');
avg=mean(n);
disp(avg);

%BUFFERSIZE VS PACKETLOSS

buff=0;
count=1;
avgloss(1,count)=avg;
buffersize(1,count)=buff;
while(avg>errorrate)
count=count+1;
buff=buff+1;
tser=tser+1;

for j=1:timeslots
if(n(1,j)>0)
n(1,j)=(tarr(1,j)-tser(1,j));
end;
end;

avg=mean(n);
avgloss(1,count)=avg;
buffersize(1,count)=buff;
end;
disp('THE MAX PACKET LOSS AFTER BUFFERING IS:');
disp(max(n));
disp('THE AVERAGE PACKET LOSS AFTER BUFFERING IS:');
disp(avg);
disp('THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:');
disp(buff);
figure(2);
line(buffersize,avgloss);
xlabel('BUFFERSIZE'),ylabel('PACKETLOSS');

OUTPUT:-

ENTER THE DATAARRIVAL RATE:50


ENTER THE DATASERVICE RATE:30
ENTER THE MAXIMUM ACCEPTABLE PACKET LOSS RATE:2
THE MAXIMUM PACKET LOSS IS:
57

THE AVERAGE PACKETLOSS BEFORE BUFFERING IS:


25.1700

THE MAX PACKET LOSS AFTER BUFFERING IS:


17

THE AVERAGE PACKET LOSS AFTER BUFFERING IS:


1.7800

THE MAX BUFF SIZE FOR THE GIVEN ERRORRATE IS:


40
60

50

40
PACKET LOSS

30

20

10

0
0 20 40 60 80 100 120
TIMESLOT

30

25

20
PACKETLOSS

15

10

0
0 5 10 15 20 25 30 35 40
BUFFERSIZE
PROGRAM:-
clc;
clear all;
close all;
% GETTING TEXT TO BE ENCRYPTED & FINDING LENGTH OF THE TEXT
x=input('Enter Input Text =','s');
len=length(x);
Array1=[];
input1=[];
% GETTING THE KEY FOR ENCRYPTION
key = input( 'Enter Key Value:');
fori=1:len
input1(i)=x(i);
end;
% ASCII VALUE OF EACH ALPHABET IS ADDED WITH KEY VALUE
fori=1:len
Array1(i)=input1(i)+key;
%HANDLING SMALL ALPHABETS
if Array1(i)>122 && input1(i)>=97
Array1(i)=Array1(i)-122;
Array1(i)=Array1(i)+96;
end;
%HANDLING CAPITAL ALPHABETS
if Array1(i)>90 && input1(i)<=90
Array1(i)=Array1(i)-90;
Array1(i)=Array1(i)+64;
end;
end
% DISPLAYING ENCRYPTED TEXT
disp('Ecryption Result')
disp(char(Array1));

fori=1:len
Array1(i)=Array1(i)-key;
%HANDLING SMALL ALPHABETS IN DECRYPTION
if Array1(i)<=97 && input1(i)>=97
Array1(i)=97-Array1(i);
Array1(i)=123-Array1(i);
end;
%HANDLING CAPITAL ALPHABETS
if Array1(i)<65 && input1(i)<=90
Array1(i)=65-Array1(i);
Array1(i)=91-Array1(i);
end;
end;
% DISPLAYING DECRYPTED TEXT
disp('Decryption Result');
disp(char(Array1));
SAMPLE INPUT & OUTPUT:

Enter Input Text =mit


Enter Key Value: 5
Ecryption Result
ENCRYPT = rny
Decryption Result
DECRYPT = mit
PROGRAM
% START
clc;
clear all;
% INITIALIZE TWO PRIME NOS ‘p’ AND ‘q’
p=3;
q=11;
n=p*q;
z=(p-1)*(q-1);
d=2;
e=2;
% CALCULATING DECRYPTION KEY
while(gcd(d,z)>1)
d=d+1;
end;
% CALCULATING ENCRYPTION KEY
while(mod(d*e,z)>1)
e=e+1;
end;
disp(e);
disp(sprintf('The encryption key is %d',e));
disp(sprintf('The decryption key is %d',d));
disp(sprintf('1. Message using upper case symbols(^_[])'));
disp(sprintf('2. Message using lower case symbols ({}~/)'));
disp(sprintf('3. Message using numbers and remaining symbols'));
ch=input('\n Enter the choice:');
% GETTING THE MESSAGE TO BE ENCRYPTED
m=input('\n Enter the message to be encrypted:','s');
switchch
% MESSAGE IS IN LOWER CASE SYMBOLS ( { } ~ / ) ' ) THEN CASE 2
case 2
t=double(m)-96;
t(find(t<1))=0;
fori=1:length(m)
g(i)=mod(t(i)^e,n);
end;
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
fori=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
rx(find(rx<=0))-64;
r=char(rx+96);

% MESSAGE IS IN UPPER CASE SYMBOLS( ^_ [ ] ) ') THEN CASE 1


case 1
t=double(m)-64;
t(find(t<1))=0;
fori=1:length(m)
g(i)=mod(t(i)^e,n);
end;
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
fori=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
rx(find(rx<=0))=-32;
r=char(rx+64);
% MESSAGE IS IN NUMBERS AND REMAINING SYMBOLS
case 3
t=double(m)-32;
fori=1:length(m)
g(i)=mod(t(i)^e,n);
end;
% DISPLAYING ENCRYPTED MESSAGE
disp(sprintf('\n The encrypted message is:\n'));
disp(g);
fori=1:length(m)
rx(i)=mod(g(i)^d,n);
end;
r=char(rx+32);
end;
% DISPLAYING DECRYPTED MESSAGE
disp(sprintf('\n The decrypted message is :\n'));
disp(r);
SAMPLE INPUT &OUTPUT:

CASE I

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])

2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice:1

Enter the message to be encrypted:[COMPUTER]

The encrypted message is:

3 9 27 7 25 21 26 14 6 17

The decrypted message is:[COMPUTER]


CASE II

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])

2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice:2

Enter the message to be encrypted:{flower}

The encrypted message is:

3 30 12 27 23 14 6 17

The decrypted message is :{flower}

CASE III

The encryption key is 7

The decryption key is 3

1. Message using upper case symbols(^_[])

2. Message using lower case symbols ({}~/)

3. Message using numbers and remaining symbols

Enter the choice:3

Enter the message to be encrypted:#@^&

The encrypted message is:

9 32 17 30

The decrypted message is :#@^&


PROGRAM:-
clc;
% PROVIDE No OF FRAMES AND LENGTH OF EACH FRAME
m=input('Enter the number of frames to be transmitted:');
n=input('Enter the length of the frame:');
i=1;j=1;l=0;
% RANDOM GENERATION OF FRAMES BITS
d=randint(1,n);
% ADDING PARITY BIT TO THE FRAME SEQUENCE
d(n+1)=rem(sum(d),2);
while((i<=m)&j)
q=randint(1,1);
% FRAME IS TRANSMITTED
disp(sprintf('transmitted frame %d:',i));
disp(d);
% SWITCHING CASE BASED ON Q VALUE
switch q
case 0
disp(sprintf('No Acknowledgement\n'));
disp(sprintf('Retransmitting...'));
l=l+1;
if(l==5)
j=0;
disp(sprintf('Transmission failed\n'));
end;
case 1
p=randint(1,1,[1,n]);
disp(p);
d(p)=randint(1,1);
disp(d(p));
disp(sprintf('Received frame'));
disp(d);
% CHECKING IF RECEIVED FRAME CONTAINS ERROR OR NOT
y=sum(d)-d(n+1);
c=rem(y,2);
if(c==d(n+1))
disp(sprintf('Acknowledgement received\n'));
l=0;
i=i+1;
if(i<=m)
n=input('Enter the length of the frame:');
d=randint(1,1);
d(n+1)=rem(sum(d),2);
end;

else
disp(sprintf('Negative Acknowledgement'));
disp(sprintf('Retransmitting...'));
l=l+1;
% CONTINUOUSLY IF FIVE RETRANSMISSION OCCURS, THEN TRANSMISSION GETS
FAILED
if(l==5)
j=0;
disp(sprintf('Transmission failed\n'));
end;
d(p)=~d(p);
disp(sprintf('\n'));
end;
end;
end;

SAMPLE INPUT & OUTPUT:


% GIVE No OF FRAMES AND LENGTH OF FRAMES
Enter the number of frames to be transmitted:1
Enter the length of the frame:8
Transmitted frame 1:
0 1 0 0 1 0 0 0 0
No Acknowledgement
Retransmitting...
Transmitted frame 1:
0 1 0 0 1 0 0 0 0
3
0
Received frame
0 1 0 0 1 0 0 0 0
Acknowledgement received
PROGRAM:
% START
clc;
clear all;
close all;

b=1;
while(b==1)
clc;
% GETTING TOTAL NO OF FRAMES , WINDOW SIZE AND LENGTH OF SEQUENCE
m=input('Enter the total no of frames:');
n=input('Enter the window size:');
t=input('Enter the length of the sequence:');
fprintf('\n');
% CHECKING WHETHER NO OF FRAMES IS LESS THAN WINDOW SIZE
while(m~=0)
if(m<n)
n=m;
end;
fori=1:1:n
% RANDOM GENERATION OF FRAME SEQUENCE BASED ON FRAME LENGTH
d=randint(1,t);
d(t+1)=rem(sum(d),2);
a(i,1:t+1)=d;
% FRAME TRANSMISSION STARTS
fprintf('Transmitting frame%d:',i);
disp(a(i,1:t+1));
end;
% GENERATING RANDOM POSITION AND RANDOM ERROR
p=randint(1,1,[1,n]);
q=randint(1,1,[1,t+1]);
a(p,q)=randint(1,1);
% FRAME IS RECEIVED
fori=1:1:n
fprintf('Receiving frame%d:',i);
disp(a(i,1:t+1));
end;
f=zeros(1,n);
fori=1:1:n
% CHECKING IF RECEIVED FRAME CONTAINS ERROR OR NOT
f(i)=rem(sum(a(i,1:t+1)),2);
if(f(i)==1)
k=i;
end;
end;
if(f==0)
fprintf('Acknowdegement received\n');
else
fprintf('Rejected frames%d\n',k);

disp('Retransmiting....');
% CORRECTING ERROR
a(p,q)=~a(p,q);
fori=k:1:n
fprintf('\nTransmittingframe%d:',i);
disp(a(i,1:t+1));
end;
fori=k:1:n
fprintf('Receivedframe%d',i);
disp(a(i,1:t+1));
end;
fprintf('\nAcknowledgement received\n');
end;
% REDUCING NO OF FRAMES BY WINDOW SIZE
m=m-n;
end;
b=input('\nEnter 1 to continue else 0:');
end;
SAMPLE INPUT &OUTPUT:
% ENTERING NO OF FRAMES, WINDOW SIZE AND LENGTH OF THE
SEQUENCE
Enter the total no of frames:2
Enter the window size:4
Enter the length of the sequence:6
Transmitting frame1: 0 1 0 1 0 0 0
Transmitting frame2: 1 1 0 1 1 0 0
Receiving frame1: 0 1 0 1 0 0 0
Receiving frame2: 1 1 1 1 1 0 0
Rejected frames2
Retransmitting....
Transmitting frame2: 1 1 0 1 1 0 0
Receivedframe2 1 1 0 1 1 0 0
Acknowledgement received
Enter 1 to continue else 0:
PROGRAM:
% START
clc;
b=1;
while(b==1)
% GETTING No OF FRAMES, WINDOW SIZE AND LENGTH OF SEQUENCE
m=input('Enter the total no of frames=');
n=input('Enter the window size=');
t=input('Enter the length of sequence=');
fprintf('\n');
% CHECKING WHETHER m VALUE IS 0
while(m~=0)
if(m<n)
n=m;
end;
fori=1:1:n
% RANDOM GENERATION OF FRAME SEQUENCE BASED ON THE FRAME LENGTH
d=randint(1,t);
d(t+1)=rem(sum(d),2);
a(i,1:t+1)=d;
% FRAME IS TRANSMITTED
fprintf('Transmitting frame%d:',i);
disp(a(i,1:t+1));
end;
% RANDOM GENERATION OF ERROR POSITION AND ERROR VALUE
p=randint(1,1,[1,n]);
q=randint(1,1,[1,t+1]);
a(p,q)=randint(1,1);
fori=1:1:n
% RECEIVED FRAME
fprintf('Receiving frame%d:',i);
disp(a(i,1:t+1));
end;
f=zeros(1,n);
% CHECKING RECEIVED FRAME CONTAINS ERROR OR NOT
fori=1:1:n
f(i)=rem(sum(a(i,1:t+1)),2);
if(f(i)==1)
k=i;
end;
end;
if(f==0)
fprintf('Acknowledgement Received\n');

else
fprintf('Rejected frames%d\n\n',k);
disp('Retransmitting....');
% CORRECTING ERROR IF THE FRAME CONTAIN ERROR
a(p,q)=~a(p,q);
fprintf('\nTransmittingframe%d:',k);
disp(a(k,1:t+1));
fprintf('\nReceivedframe%d:',k);
disp(a(k,1:t+1));
fprintf('\nAcknowledgement received\n');
end;
% REDUCING NO OF FRAMES BY WINDOW SIZE
m=m-n;
end;
b=input('\nEnter 1 to continue or else 0:');
end;
SAMPLE INPUT &OUTPUT:
% GETTING No OF FRAMES. WINDOW SIZE AND LENGTH OF SEQUENCE
Enter the total no of frames=3
Enter the window size=5
Enter the length of sequence=6
Transmitting frame1: 1 1 0 0 0 0 0
Transmitting frame2: 1 0 1 0 1 0 1
Transmitting frame3: 1 1 1 0 1 1 1
Receiving frame1: 1 1 0 0 0 0 0
Receiving frame2: 1 0 1 0 1 1 1
Receiving frame3: 1 1 1 0 1 1 1
Rejected frames2
Retransmitting....
Transmitting frame2: 1 0 1 0 1 0 1
Received frame2: 1 0 1 0 1 0 1
Acknowledgement received
Enter 1 to continue or else 0:
PROGRAM:-
clc;
clear all;
a=input ('Enter the generator :','s');
g=str2num(a);
L1=length(g);
for i=1:L1
temp(i)=g(L1-i+1);
end
y=binvec2dec(temp);
a= input('Enter the message :','s');
m=str2num(a);
L2=length(m);fori=1:L1
m(L2+i)=0;
end
for i=1:L1+L2
temp(i)=m(L1+L2-i+1);
end
x=binvec2dec(temp);
z=mod(x,y);
z1=y-z;
g1=dec2binvec(x+z1);
for i=1:L1+L2
tx(i)=g1(L1+L2-i+1);
end
for i=1:3
disp('Transmitted data');
disp(tx);
tx1=tx;
err=randint(1,1,[1 10]);
if err>5
pos = randint(1,1,[1 L1+L2]);
tx1(pos)=~tx1(pos);
end
disp('Received data');
disp(tx1);
for j=1:L1+L2
temp(j)=tx1(L1+L2-j+1);
end
rec = binvec2dec(temp);
if mod(rec,y)==0
disp('No error');
else
disp('Error');
end
end
OUTPUT:-

Enter the generator :[1 1 0 1 ]


Enter the message :[1 1 1 1 0 1]
Transmitted data
1 1 1 1 0 1 1 1 0 0
Received data
1 1 1 1 0 0 1 1 0 0
Error
Transmitted data
1 1 1 1 0 1 1 1 0 0
Received data
1 1 1 1 0 1 1 0 0 0
Error
Transmitted data
1 1 1 1 0 1 1 1 0 0
Received data
1 1 1 0 0 1 1 1 0 0
Error
PROGRAM:-
clc;
clear all;
n=input('Enter the no of nodes:');
conn = input('Enter the connected nodes :');
delarr = ones(n);
delarr =10000*delarr;
len =length(conn);
delay2=randint(1,(len/2),[10,50]);
k=1;
for i=1:2:len
delarr(conn(i),conn(i+1))=delay2(k);
delarr(conn(i+1),conn(i))=delay2(k);
k=k+1;
end
for i=1:n
delarr(i,i)=0;
end
disp('...........Delay Time...........');
disp(delarr);
gr=delarr;
v=[1:n];
p=perms(v);
start=input('Enter the source node :');
dest = input('Enter the destination node :');

%FINDING ALL THE POSSIBLE PATHS AND THEIR DELAYS

paths = zeros(factorial(n-1),n);
index=0;
for i=1:factorial(n)
if p(i,1)~=start
continue;
end
de=0;
temp=p(i,1);
index =index +1;
paths(index,1)=temp;
for j=2:n
if((gr(temp,p(i,j))>0)&(gr(temp,p(i,j))<10000))
flag=1;
de=de+gr(temp,p(i,j));
temp =p(i,j);
paths(index,j)=temp;
if temp==dest
delay(index)=de;
break;
end
else
flag=0;
index = index-1;
break;
end
end
end

%REMOVING THE REPEATED PATH

j=1;
delay1(j)=delay(j);
paths1(j,:)=paths(1,:);
for i=2:length(delay)
if delay(i-1)~=delay(i)
j=j+1;
delay1(j)=delay(i);
paths1(j,:)=paths(i,:);
end
end
target=min(delay1);
for i=1:length(delay1)
if delay1(i)==target
break;
end
end
shortint=i;
%Displaying all the paths and also selected one
for i=1:length(delay1)
for j=1:n
if paths1(i,j)~=0
fprintf('%d->',paths(i,j));
else
break;
end
end
fprintf('\b\b:delay=%d\n',delay1(i));
end

%SHORTEST PATH AND ITS DELAY

disp('');
disp('The shortest path is :');
for j=1:n
if paths1(shortint,j)~=0
fprintf('%d->',paths1(shortint,j));
else
break;
end
end
fprintf('\b\b\t\tdelay=%d\n',delay1(shortint));

OUTPUT:-

i) enter the number of nodes:3


enter the connection nodes:[1 2 1 3 2 3]
delay time
0 35 13
35 0 21
13 21 0
enter the source node:1
enter the destination node:3
1->2->3:delay=56
1->3:delay=13
the shortest path is
1->3 delay=13

ii)enter the number of nodes:4


enter the connection nodes:[1 2 1 3 2 4 3 4]
delay time
0 43 47 10000
43 0 10000 15
47 10000 0 47
10000 15 47 0
enter the source node:1
enter the destination node:4
1->3->4:delay=94
1->2->4:delay=58
the shortest path is
1->2->4 delay=58

iii) enter the number of nodes:5


enter the connection nodes:[1 2 1 3 2 4 3 4 4 5]
delay time
0 32 49 10000 10000
32 0 10000 49 10000
49 10000 0 16 10000
10000 49 16 0 49
10000 10000 10000 49 0

enter the source node:1


enter the destination node:5
1->3->4->5:delay=114
1->2->4->5:delay=130
the shortest path is
1->3->4->5
delay=114
PROGRAM:-

clc;
clear all;
c=input('Enter the number of clusters:');
for i=1:c
fprintf('Enter the number of nodes in the cluster %d\n',i);
n(i)=input('');
nw(i).gr=randint(n(i),n(i),[10,90]);
for k=1:n(i)
nw(i).gr(k,k)=0;
end
for k=1:n(i)
for m=k+1:n(i)
nw(i).gr(m,k)=nw(i).gr(k,m);
end
end
end
for i=1:c
fprintf('Delay Table of cluster:%d\n',i);
disp(nw(i).gr);
end

%RANDOMLY INTERCONNECTING THE CLUSTERS

disp('Interconnection between clusters :');


for i=1:c
for j=1:c
if i==j
interconn(i,j)=0;
continue;
end
interconn(i,j)=randint(1,1,[1,n(i)]);
end
end
disp(interconn);
cs = input('Enter the cluster in which the starting node is present :');
start = input ('Enter the starting node:');
cd = input('Enter the cluster in which destination nodeis present :');
dest = input ('Enter the destination node :');

%TREATING ENTIRE INTERCONNECTION OF NETWORKS AS SINGLE


NETWORK

newdim=sum(n');
newgr = zeros(newdim,newdim);
%FORMING THE NEW GRAPH CONTAINING ALL THE NETWORKS
offset=0;
for x=1:length(n)
for i=1:n(x)
for j=i+1:n(x)
newgr(i+offset,j+offset)=nw(x).gr(i,j);
end
end
offset= offset+n(x);
end
tempgr=newgr;

%Linking the clustres


for i=1:c
rowoffset=0;
for k=1:i-1
rowoffset=rowoffset+n(k);
end
for j=i+1:c
if interconn(i,j)>0
offset =0;
for k=1:j-1
offset =offset+n(k);
end
newgr(interconn(i,j) + rowoffset,interconn(j,i)+offset)=randint(1,1,[1,20]);
end
end
end
for i=1:newdim
for j=i+1:newdim
newgr(j,i)=newgr(i,j);
end
end

%THE OVERALL GRAPH IS GIVEN BY NEWGR

disp(newgr);
%Finding the new start and new destination node that corresponds to the
%newgraph
startoffset = 0;
for i=1:cs-1
startoffset = startoffset + n(i);
end
newstart = start + startoffset;
destoffset= 0;
for i=1:cd-1
destoffset=destoffset+n(i);
end
newdest= dest +destoffset;
%framing identities for the nodes wrt the graph
index=1;
for i=1:c
for j=1:n(i)
iden(index).notation=sprintf('%d.%d',i,j);
index = index +1;
end
end

%FINDING THE SHRTEST PATH VIA THE SHOTEST CODING


v=[1:newdim];
p=perms(v);

%FINDING ALL THE POSSIBLE PATHS AND THEIR DELAYS

paths = zeros(factorial (newdim-1),newdim);


index=0;
for i=1:factorial(newdim)
if p(i,1) ~= newstart
continue;
end
de=0;
temp = p(i,1);
index= index +1;
paths(index,1)=temp;
for j=2:newdim
if newgr(temp,p(i,j))>0
flag=1;
de = de + newgr(temp,p(i,j));
temp =p(i,j);
paths(index,j)=temp;
if temp == newdest
delay(index)=de;
break;
end
else
flag=0;
index=index-1;
break;
end
end
end
%REMOVING THE REPEATED PATHS

j=1;
delay1(j) = delay(1);

paths1(j,:)=paths(1,:);
for i=2:length(delay)
if delay(i-1)~=delay(i)
j=j+1;
delay1(j)=delay(i);
paths1(j,:)=paths(i,:);
end
end
target = min(delay1);
for i=1:length(delay1)
if delay1(i)== target
break;
end
end
shortind = i;

%DISPLAYING ALL THEPATHS AND ALSO THE SELECTED ONE

for i=1:length(delay1)
for j=1:newdim
if paths1(i,j)~=0
fprintf('%s ->',iden(paths1(i,j)).notation);
else
break;
end
end
fprintf('\b\b: delay = %d\n',delay1(i));
end
%shrtest path n its delay
disp('');
disp('The shortest path is :');
for j=1:newdim
if paths1(shortind,j)~=0
fprintf('%s ->',iden(paths1(shortind,j)).notation);
else
break;
end
end

fprintf('\b\b : delay=%d\n',delay1(shortind));
OUTPUT:-
Enter the number of clusters:4
Enter the number of nodes in the cluster 1
2
Enter the number of nodes in the cluster 2
2
Enter the number of nodes in the cluster 3
2
Enter the number of nodes in the cluster 4
2
Delay Table of cluster:1
0 71
71 0
Delay Table of cluster:2
0 23
23 0
Delay Table of cluster:3
0 37
37 0
Delay Table of cluster:4
0 30
30 0
Interconnection between clusters :
0 2 2 2
2 0 1 1
1 2 0 1
2 1 2 0

Enter the cluster in which the starting node is present :2


Enter the starting node:1
Enter the cluster in which destination nodeis present :4
Enter the destination node :2
0 71 0 0 0 0 0 0
71 0 0 7 4 0 0 6
0 0 0 23 0 13 10 0
0 7 23 0 0 0 0 0
0 4 0 0 0 37 0 8
0 0 13 0 37 0 0 0
0 0 10 0 0 0 0 30
0 6 0 0 8 0 30 0
2.1 ->4.1 ->4.2 : delay = 40
2.1 ->3.2 ->3.1 ->4.2 : delay = 58
2.1 ->3.2 ->3.1 ->1.2 ->4.2 : delay = 60
2.1 ->2.2 ->1.2 ->3.1 ->4.2 : delay = 42
2.1 ->2.2 ->1.2 ->4.2 ->3.2 : delay = 36

The shortest path is :


2.1 ->2.2 ->1.2 ->4.2 ->3.2 : delay=36
PROGRAM:-
clc;
clear all;
a=input('enter the message:','s');
g=str2num(a);
%tx(:,1)=zeros(7,1);
tx(3)=g(1);tx(5)=g(2);tx(6)=g(3);tx(7)=g(4);
%evaluating tx(1) from 3,5,7
tx(1)=xor(tx(3),xor(tx(7),tx(5)));
%evaluating tx(1) from 3,6,7
tx(2)=xor(tx(3),xor(tx(6),tx(7)));
%evaluating tx(1) from 5,6,7
tx(4)=xor(tx(5),xor(tx(6),tx(7)));
for i=1:3
disp('transmitted data');
disp(tx);
tx1=tx;
err=randint(1,1,[1,6]);
if err>3
pos=randint(1,1,[1,7]);
tx1(pos)=~tx1(pos);
disp('received data');
disp(tx1);
%evaluating z from 1,3,5,7
z=xor(xor(tx1(3),tx1(1)),xor(tx1(7),tx1(5)));
%evaluating y from 2,3,6,7
y=xor(xor(tx1(3),tx1(2)),xor(tx1(6),tx1(7)));
%evaluating x from 4,5,6,7
x=xor(xor(tx1(4),tx1(5)),xor(tx1(6),tx1(7)));
temp=binvec2dec([z y x]);
fprintf('error in %d position\n',temp);
tx1(temp)=~tx1(temp);
disp('corrected data');
disp(tx1);
else
disp('received data');
disp(tx1);
disp('no error');
end
end
SAMPLE INPUT AND OUTPUT
enter the message:1 0 1 0
transmitted data
1011010
received data
1011110
error in 5 position
corrected data
1011010
transmitted data
1011010
received data
1001010
error in 3 position
corrected data
1011010
transmitted data
1011010
received data
1111010
error in 2 position
corrected data
1011010
PROGRAM:-
clc;
clear all;
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
disp('Monoalphabetic (caesar cipher) ');
disp('');
shift=input('Enter the number of end around shifts (key):');

%ENCRYPTION
mt=asc;
for i=1:length(mt)
mt(i)=mt(i)+shift;
if mt(i)>127
corr=mt(i)-127;
mt(i)=32+corr-1;
end
end
disp(' ');
disp('CIPHER TEXT');
disp(char(mt));

%DECRYPTION
for i=1:length(mt)
mt(i)=mt(i)-shift;
if mt(i)<32
corr=32-mt(i);
mt(i)=127-corr+1;
end
end
disp(' ');
disp('DECRYPTED TEXT');
disp(char(mt));
OUTPUT:-
Enter the plain text:['computer']

Monoalphabetic (caesar cipher)

Enter the number of end around shifts (key):3

CIPHER TEXT

frpsxwhu

DECRYPTED TEXT

computer
PROGRAM:-

clc;
clear all;
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
disp('Polyalphabetic (trithemius progressive key )');
%FORMING THE TRITHEMIUS KEY TABLE
disp(' ');
type= input('Enter the left shift(+1) or right shift(-1);');
start=32:127;
for i=1:96
if type==1
k=96-i+1;
elseif type==-1
k=i+1;
if i==96
k=1;
end
end
for j=1:96
tri(i,j)=start(k);
if k==96
k=0;
end
k=k+1;
end
end

%ENCRYPTION
mt=asc;
for i=1:length(mt)
col=mt(i)-31;
mt(i)=tri(i,col);
end
disp(' ');
disp('CIPHER TEXT');
disp(char(mt));

%DECRYPTION
for i=1:length(mt)
col=mt(i)-31;
mt(i)=tri(96-i,col);

end

disp(' ');
disp('DECRYPTED TEXT');
disp(char(mt));

OUTPUT:
Enter the plain text:['flower']
Polyalphabetic (trithemius progressive key )
Enter the left shift(+1) or right shift(-1);+1
CIPHER TEXT
ejls`l
DECRYPTED TEXT
flower
PROGRAM:-

clc;
clear all;
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
disp('VIGENERE KEY METHOD');
disp(' ');
type= input('Enter the left shift(+1) or right shift(-1);');
start=32:127;
for i=1:96
if type==1
k=96-i+1;
elseif type==-1
k=i+1;
if i==96
k=1;
end
end
for j=1:96
tri(i,j)=start(k);
if k==96
k=0;
end
k=k+1;
end
end
key=input('Enter the key word :');
keyasc=double(key);
keylen=length(key);

%ENCRYPTION
mt=asc;
x=1;
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=96-(keyasc(x)-31)+1;
if row==0
row=96;
end
else

row=keyasc(x)-31-1;
if row==0
row=96;
end
end
mt(i)=tri(row,col);
if x==keylen
x=0;
end
x=x+1;
end
disp(' ');
disp('CIPHER TEXT');
disp(char(mt));

%DECRYPTION
x=1;
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=(keyasc(x)-31)-1;
if row==0
row=96;
end
else
row=96-(keyasc(x)-31-1);
if row==0
row=96;
end
end
mt(i)=tri(row,col);
if x==keylen
x=0;
end
x=x+1;
end
disp(' ');
disp('DECRYPTED TEXT');
disp(char(mt));
OUTPUT:
Enter the plain text:['ECE DEPT']
VIGENERE KEY METHOD

Enter the left shift(+1) or right shift(-1);-1


Enter the key word :'CDT'

CIPHER TEXT
hgyChysx

DECRYPTED TEXT
ECE DEPT
PROGRAM:-

clc;
clear all;
pt=input('Enter the plain text:');
asc=double(pt);
disp('');
type= input('Enter the left shift(+1) or right shift(-1);');
start=32:127;
for i=1:96
if type==1
k=96-i+1;
elseif type==-1
k=i+1;
if i==96
k=1;
end
end
for j=1:96
tri(i,j)=start(k);
if k==96
k=0;
end
k=k+1;
end
end
disp('VIGENERE AUTO(cipher)KEY METHOD');
disp(' ');
auto1=input('Enter the key letter :');

%ENCRYPTION
autoasc=double(auto1);
mt=asc;
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=96-(autoasc-31)+1;
if row==0
row=96;
end

else
row=autoasc-31-1;
if row==0
row=96;
end
end
mt(i)=tri(row,col);
autoasc=mt(i);
end
disp(' ');
disp('CIPHER TEXT');
disp(char(mt));

%DECRYPTION
autoasc=double(auto1);
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=(autoasc-31)-1;
if row==0
row=96;
end
else
row=96-(autoasc-31-1);
if row==0
row=96;
end
end
cipkey =mt(i);
mt(i)=tri(row,col);
autoasc=cipkey;
end
disp(' ');
disp('DECRYPTED TEXT');
disp(char(mt));
OUTPUT:

Enter the plain text:['flower']


Enter the left shift(+1) or right shift(-1);-1
VIGENERE AUTO(cipher)KEY METHOD

Enter the key letter :'f'

CIPHER TEXT
L8'~cU

DECRYPTED TEXT
flower

You might also like