N= input ('Number of letters')
k = input('key')
for j=1:N # This loop to read the plain text and make encryption for each letter
switch input('letter') # Mapping letters of plain text to numbers
case 'a'
i=0;
case 'b'
i=1;
case 'c'
i=2;
case 'd'
i=3;
case 'e'
i=4;
case 'f'
i=5;
case 'g'
i=6;
case 'h'
i=7;
case 'i'
i=8;
case 'j'
i=9;
case 'k'
i=10;
case 'l'
i=11;
case 'm'
i=12;
case 'n'
i=13;
case 'o'
i=14;
case 'p'
i=15;
case 'q'
i=16;
case 'r'
i=17;
case 's'
i=18;
case 't'
i=19;
case 'u'
i=20;
case 'v'
i=21;
case 'w'
i=22;
case 'x'
i=23;
case 'y'
i=24;
case 'z'
i=25;
end
disp(i)
c = mod(i+k,26) # encryption function
switch © # Mapping numbers to letters for cipher text
case (0)
cipher='a';
case (1)
cipher='b';
case (2)
cipher='c';
case (3)
cipher='d';
case (4)
cipher='e';
case (5)
cipher='f';
case (6)
cipher='g';
case (7)
cipher='h';
case (8)
cipher='i';
case (9)
cipher='j';
case (10)
cipher='k';
case (11)
cipher='l';
case (12)
cipher='m';
case (13)
cipher='n';
case (14)
cipher='o';
case (15)
cipher='p';
case (16)
cipher='q';
case (17)
cipher='r';
case (18)
cipher='s';
case (19)
cipher='t';
case (20)
cipher='u';
case (21)
cipher='v';
case (22)
cipher='w';
case (23)
cipher='x';
case (24)
cipher='y';
case (25)
cipher='z';
end
disp(cipher)
end
2- Repeat step(1) where k=20 for the following plain text:
“Caesar cipher is the simplest form of substitution technique”
Q2: Give the plain text of the following cipher text where k=3:
Cipher text: PHHW PH DIWHU WKH WRJD SDUWB
4.Hill Cipher: is defined as multi letter cipher,
- The encryption algorithm takes m successive plaintext letters and substitutes for them m ciphertext letters. The substitution is determined by m linear equations in which each character is assigned a numerical value (a = 0, b = 1 ... z = 25).
- In general terms, the Hill system can be expressed as follows:
C = E(K, P) = KP mod 26
P = D(K, P) = K-1C mod 26 = K-1KP = P
For m = 3, the system can be described as follows:
c1 = (k11P1 + k12P2 + k13P3) mod 26
c2 = (k21P1 + k22P2 + k23P3) mod 26
c3 = (k31P1 + k32P2 + k33P3) mod 26
This can be expressed in term of column vectors and matrices:
mod26
or
C = KP mod 26
where C and P are column vectors of length 3, representing the plaintext and ciphertext, and K is a 3 x 3 matrix, representing the encryption key. Operations are performed mod 26.
Procedure:
- consider the plaintext "paymoremoney" and use the encryption key
K=
- The first three letters of the plaintext are represented by the vector:
, then implement the following program:
N= input ('Number of letters')
k = input('key')
for j=1:N # This loop to read the plain text and make encryption for each letter
switch input('letter') # Mapping letters of plain text to numbers
case 'a'
i=0;
case 'b'
i=1;
case 'c'
i=2;
case 'd'
i=3;
case 'e'
i=4;
case 'f'
i=5;
case 'g'
i=6;
case 'h'
i=7;
case 'i'
i=8;
case 'j'
i=9;
case 'k'
i=10;
case 'l'
i=11;
case 'm'
i=12;
case 'n'
i=13;
case 'o'
i=14;
case 'p'
i=15;
case 'q'
i=16;
case 'r'
i=17;
case 's'
i=18;
case 't'
i=19;
case 'u'
i=20;
case 'v'
i=21;
case 'w'
i=22;
case 'x'
i=23;
case 'y'
i=24;
case 'z'
i=25;
end
disp(i)
l(j) = i
p= l'
end;
c = mod((k*p), 26) # Encryption function
for i=1:N
switch (c(i)) # Mapping numbers of cipher text to letters
case (0)
cipher(i)='a';
case (1)
cipher(i)='b';
case (2)
cipher(i)='c';
case (3)
cipher(i)='d';
case (4)
cipher(i)='e';
case (5)
cipher(i)='f';
case (6)
cipher(i)='g';
case (7)
cipher(i)='h';
case (8)
cipher(i)='i';
case (9)
cipher(i)='j';
case (10)
cipher(i)='k';
case (11)
cipher(i)='l';
case (12)
cipher(i)='m';
case (13)
cipher(i)='n';
case (14)
cipher(i)='o';
case (15)
cipher(i)='p';
case (16)
cipher(i)='q';
case (17)
cipher(i)='r';
case (18)
cipher(i)='s';
case (19)
cipher(i)='t';
case (20)
cipher(i)='u';
case (21)
cipher(i)='v';
case (22)
cipher(i)='w';
case (23)
cipher(i)='x';
case (24)
cipher(i)='y';
case (25)
cipher(i)='z';
end;
display(cipher(i))
end
- Write the plain text of the following cipher text: WMTRWX, using same key in step 1.