You are on page 1of 4

2) AIM: Implement Transposition Cipher using Route Cipher. Use Spiral Technique.

CODE:

clc
close all
clear all

inf=input('Enter information message :- ')


disp('number of coloum ==3')
col=3

lengthofinf=length(inf)
row=lengthofinf/col
row=round(row)

k=1

%% to make cipher text

for i=1:row
for j=1:col
if k<=lengthofinf
if (inf(k)==' ')
mess(j,i)='*'
k=k+1
else
mess(j,i)=inf(k)
k=k+1
end
else
mess(j,i)='*'
end
end
end

%%transmitted message

k=1

for i=1:col
for j=1:row
if i==1 & j<row
tran(k)=mess(i,j)
k=k+1

elseif i==1 & j==row


for h=1:col
tran(k)=mess(h,row)
k=k+1
end
end
end
end

for i=row-1:-1:1
tran(k)=mess(col,i)
k=k+1
end

for i=col-1:-1:2
tran(k)=mess(i,1)
k=k+1
end

for i=2:row-1
tran(k)=mess(2,i)
k=k+1
end

%%receiver part

receive=tran

col=3

lengthofreceive=length(receive)
row=lengthofinf/col
row=round(row)

k=1

%%to make sender cipher text

for i=1:col
for j=1:row
if i==1 & j<row
mess1(i,j)=receive(k)
k=k+1

elseif i==1 & j==row


for h=1:col
mess1(h,row)=receive(k)
k=k+1
end
end
end
end
for i=row-1:-1:1
mess1(col,i)=receive(k)
k=k+1
end

for i=col-1:-1:2
mess1(i,1)=receive(k)
k=k+1
end

for i=2:row-1
mess1(2,i)=receive(k)
k=k+1
end

%% to read from cipher text received information

k=1

for i=1:row
for j=1:col
if k<=lengthofreceive
if (mess(j,i)=='*')
recinf(k)=' '
k=k+1
else
recinf(k)=mess1(j,i)
k=k+1
end
else
recinf(k)=' '
end
end
end
OUTPUT:

1) Transmitter Part:-

2) Receiver Part:-

You might also like