Aligned CN Record[1]
Aligned CN Record[1]
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:-
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
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
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:-
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
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:-
clc;
clear;
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
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
end
%auto correlation%
temp=out(len);
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)
else
fprintf('\n auto correlation property not satisfied');
end
OUTPUT:-
No of runs=8
PN sequence is.... 1 1 1 0 1 0 1 1 0 0 1 0 0 0 1
%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:-
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:-
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:-
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:
CASE I
3 9 27 7 25 21 26 14 6 17
3 30 12 27 23 14 6 17
CASE III
9 32 17 30
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;
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:-
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
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
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:-
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
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;
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
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;
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
%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']
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
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:
CIPHER TEXT
L8'~cU
DECRYPTED TEXT
flower