Encryption and Decryption in Matlab
Encryption and Decryption in Matlab
ASSIGNMENT ON MODULE 2
IMPLEMENTATION OF DIFFERENT
DIFFERENT CIPHERS IN MA
MATLAB
Course: : CRYPTOGRAPHY
Subject Code : 17EC744
Semester/Section : VII / ‘A’
Submission Date : 12 – 01 – 2021
Implementation of different ciphers in matlab
OUTPUTS
OUTPUTS
~1~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
~2~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
if(r1==r2)
if c1 == 5;
c1=0;
end
if c2 == 5;
c2=0;
end
C = [C,M(r1,(c1+1)),M(r1,(c2+1))];
elseif (c1==c2)
if r1 == 5;
r1=0;
end
if r2 == 5;
r2=0;
end
C = [C,M((r1+1),c1),M((r2+1),c1)];
elseif ((r1~=r2)&&(c1~=c2))
C = [C,M(r1,c2),M(r2,c1)];
end
end
C=C(2:length(C));
disp('The Cipher text is:-');disp(char(C+double('A')));
remove_repeated.m rcsearch.m
function [k1] = function[r1 r2 c1 c2] = rcsearch(a,b,M)
remove_repeated(k) for i=1:5
ptr = 1; for j=1:5
for i=1:length(k) if M(i,j)==a
for j=i:-1:1 r1=i;
if (i~=j)&&(k(j)==k(i)) c1=j;
found = 1; end
break; end
else for i=1:5
found = 0; for j=1:5
end if M(i,j)==b
end r2=i;
if found == 0 c2=j;
k1(ptr) = k(i); end
ptr = ptr+1; end
end end
end end
end
PTO
~3~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
append_alphabets.m
function [a] = append_alphabets(k)
there_is_match = 1;
ptr = 1;
for i=0:25
for j = 1:length(k)
if k(j)==i
there_is_match = 1;
break;
else
there_is_match = 0;
end
end
if there_is_match == 0
a(ptr) = i;
ptr = ptr+1;
end
end
a = [k,a];
end
OUTPUTS
Example 1 Example 2
Enter the key within single quotes: Enter the key within single quotes:
'VISVESVARAYA' 'GUIDANCE'
Playfair matrix is:- Playfair matrix is:-
VISEA GUIDA
RYBCD NCEBF
FGHKL HKLMO
MNOPQ PQRST
TUWXZ VWXYZ
Enter the plain text in single quotes: Enter the plain text in single quotes:
'happyengineersday' 'thekeyishidden'
Enter the filler in single quotes: Enter the filler in single quotes:
'x' 'x'
Augmented plain text is;- Augmented plain text is;-
hapxpyengineersday thekeyishidxdenx
The Cipher text is:- The Cipher text is:-
LSXENCIPNYPIVCABID POCLBXDRLGIYIBEV
~4~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
OUTPUTS
Example 1
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
2
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[9 4;5 7]
k =
9 4
5 7
~5~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
Example 2
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
3
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[17 17 5;21 18 21;2 2 19]
k =
17 17 5
21 18 21
2 2 19
Example 3
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
4
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[9 7 11 13;4 7 5 6;2 21 14 9;3 23 21 06]
k =
9 7 11 13
4 7 5 6
2 21 14 9
3 23 21 6
~6~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
Example 4
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
3
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
1
Enter the key within single quotes:
'tutorials'
k =
19 20 19
14 17 8
0 11 18
~7~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
return;
end
detinv = mod(y(i-2),26);
kinv = mod((detinv*round(adjoint(k))),26);
C=input('Enter the cipher text:\n');
C=double(upper(C))-double('A');
p_append_value=(ceil(length(C)/hill_ord)*hill_ord)-length(C);
for(N=1:length(C)/hill_ord)
a=((N-1)*hill_ord)+1;
p(a:a+hill_ord-1)=mod((C(a:a+hill_ord-1)*kinv),26);
end
disp("The plain text is:")
disp(char(p+double('a')))
OUTPUTS
Example 1
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
2
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[9 4;5 7]
k =
9 4
5 7
Example 2
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
3
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[17 17 5;21 18 21;2 2 19]
k =
17 17 5
21 18 21
2 2 19
~8~
Assignment on module 2 Cryptography[17EC744]
Implementation of different ciphers in matlab
Example 3
Enter the order of hill cipher like (for 3x3-3; for 2x2-2 and so on...):
4
How do you enter key matrix?: 1.Alphabet 2.Matrix form:
2
Enter the key in matrix format:
[9 7 11 13;4 7 5 6;2 21 14 9;3 23 21 06]
k =
9 7 11 13
4 7 5 6
2 21 14 9
3 23 21 6
~9~
Assignment on module 2 Cryptography[17EC744]