1.
Implement a Caesar cipher encryption and decryption algorithm for
the given pseudo function.
a. Function encrypt (message=” SKYISBLUE”, key=13)
b. Function decrypt (cipher=encrypt (message=”SKYISBLUE”, key=13),
key=13)
(10 marks)
Answer,
Algorithm for Caesar Cipher:
Input:
i. A String of upper-case letters, called Text.
ii. An Integer between 0-25 denoting the required shift that is 13.
Procedure:
i. Traverse the given text one character at a time
ii. For each character, transform the given character as per the rule, depending
on whether we’re encrypting or decrypting the text.
iii. Return the new string generated.
Implementation in Python:
Encryption function
# A python program to illustrate Caesar Cipher Technique
def encrypt(text, s):
result = ""
# traverse text
for i in range(len(text)):
char = text[i]
# Encrypt uppercase characters
if (char.isupper()):
result += chr((ord(char) + s - 65) % 26 + 65)
# Encrypt lowercase characters
else:
result += chr((ord(char) + s - 97) % 26 + 97)
return result
# check the above function
text = "SKYISBLUE"
s = 13
print( "Text : " + text)
print( "Shift : " + str(s))
print("Cipher: " + encrypt(text, s))
In the above function:
Text: SKYISBLUE
Then using the give key: 13, we shift each characters in the Text by 13 letters.
The encryption algorithm results in the text “FXLVFOYHR”.
Decryption Function:
# A python program to illustrate Caesar Cipher Technique
def decrypt(text, s):
result = ""
# traverse text
for i in range(len(text)):
char = text[i]
# Encrypt uppercase characters
if (char.isupper()):
result += chr((ord(char) + s - 65) % 26 + 65)
# Encrypt lowercase characters
else:
result += chr((ord(char) + s - 97) % 26 + 97)
return result
# check the above function
text = "FXLVFOYHR"
s = 13
print( "Text : " + text)
print( "Shift : " + str(s))
print("Cipher: " + decrypt(text, s))
Similarly,
In the above function:
Text: FXLVFOYHR
Then using the give key: 13, we shift each characters in the Text by 13 letters.
The decryption algorithm results in the text “SKYISBLUE”.
2. Perform the encryption and decryption using RSA algorithm for the
following”
p = 73, q = 151; plaintext M = 3314.
a. In Public key system using RSA, Bob sent a plaintext M = 3314 to Alice
using her public key. What is the generated cipher text C?
(4 marks)
Answer,
p=73, q=151 public key is e=7 M=3314
n=p*q = 73*151 =11023
Φ (n) = (p-1)(q-1) = (73-1)(151-1) = 72*150 = 10800
gcd (Φ (n), e) = gcd (10800,7) = 1, 1<e< ϕ(n)
Now According to RSA algorithm,
d=𝑒 −1mod ϕ(n) which is equals to
de= 1mod ϕ(n)
7d=1mod10800
Hence d=1543
Now,
e=7, ϕ(n)= 160, and d=23
Private Key{d, n}={1543,11023}
plain text M = 3314
Again
C = 𝑀𝑒 mod n
=3314 mod 11023
=691’
b. A man in the middle intercept the cipher text C from Bob sent to Alice.
Discuss the complete working process how to find the plaintext M.
(6 marks)
Answer,
p=73, q=151 public key is e=7 M=3314
n=p*q = 73*151 =11023
Φ (n) = (p-1)(q-1) = (73-1)(151-1) = 72*150 = 10800
gcd(Φ (n),e) = gcd(10800,7)= 1, 1<e< ϕ(n)
Now Calculating d based on RSA key algorithm we have,
d=𝑒 −1mod ϕ(n) which is equals to
de= 1mod ϕ(n)
7d=1mod10800
Hence d=1543
Now,
e=7 , ϕ(n)= 160, and d=23
Private Key{d,n}={1543,11023}
plain text M = 3314
Again
C = 𝑀𝑒 mod n
=3314 mod 11023
=691’
Now
M = 𝐶𝑑mod n
= 6911543mod11023
=3314
3. One time pad algorithms are devised by Gilbert Vernam for AT&T.
Encrypt the plain text shown below by using Vernam ciphers
technique and given random number. Write your calculation.
Plaintext KNALB
Random Number: 92, 55, 83, 21, 34
Number Equivalent A – Z = 0 - 25
(10 marks)
Answer,
Plaintext: KNALB
Random Number: 92, 55, 83, 21, 34
Numeric Equivalent: A – Z = 0 – 25
Step 1:
We generate equal number of random numbers as plaintext, here random number are
already given:
Random number: 92,55,83,21,34
Plaintext: KNALB
Step 2:
We assigned number to alphabet in ascending order.
0 = A , 1 = B , 2 = C , 3 = D , 4 = E , 5 = F , 6 = G , 7 = H , 8 = I , 9 = J , 10 = K , 11
= L , 12 = M , 13 = N ,
14 = O , 15 = P , 16 = Q , 17 = R , 18 = S , 19 = T , 20 = U , 21 = V , 22 = W , 23 = X
, 24 = Y, 25 = Z
Step 3:
We change plaintext into assigned number:
K = 10, N = 13, A = 0 , L = 11, B = 1
Which is: 10,13,0,11,1
Step 4:
To encrypt text, we add random number with plaintext number:
Plaintext: 10,13,0,11,1
Random: 92,55,83,21,34
Encrypt = 102,68,83,32,35
Step 5:
If number are more the 25, we do modulo (26)
Final number = 24, 16, 5, 6, 9
Final encrypt text = YQFGJ
______________________________________________________________
5.For the Sentence “STUDYISFUN”, generate an equivalent cipher text
using play fair cipher the given key is “MONARCHY”.
Answer:
Definition:
The Playfair cipher is a written code or symmetric encryption technique that
was the first substitution cipher used for the encryption of data. Introduced in
1854, it involved the use of keys that arrange alphabetical letters in geometric
patterns in order to encode messages.
The Algorithm consistes of 2 steps:
1). Generate the key Square(5×5):
The key square is a 5×5 grid of alphabets that acts as the key for encrypting the
plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet
(usually J) is omitted from the table (as the table can hold only 25 alphabets). If
the plaintext contains J, then it is replaced by I.
The initial alphabets in the key square are the unique alphabets of the key in the
order in which they appear followed by the remaining letters of the alphabet in
order.
For example:
The key is "monarchy"
Thus the initial entires are
'm', 'o', 'n', 'a', 'r', 'c', 'h', 'y'
followed by remaining characters of
a-z(except 'j') in that order.
M O N A R
C H Y B D
E F G I K
L P Q S T
U V W X Z
2). Algorithm to encrypt the plain text: The plaintext is split into pairs of two
letters (digraphs). If there is an odd number of letters, a Z is added to the last
letter.
For example:
PlainText: " STUDYISFUN "
After Split: 'st' 'ud' 'yi' 'sf' 'un'
Rules for Encryption:
If both the letters are in the same column: Take the letter below each one (going
back to the top if at the bottom).
For example:
Diagraph: "me"
Encrypted Text: cl
Encryption:
m -> c
e -> l
If both the letters are in the same row: Take the letter to the right of each one
(going back to the leftmost if at the rightmost position).
For example:
Diagraph: "st"
Encrypted Text: tl
Encryption:
s -> t
t -> l
If neither of the above rules is true: Form a rectangle with the two letters and
take the letters on the horizontal opposite corner of the rectangle.
For example:
Diagraph: "ud"
Encrypted Text: zc
Encryption:
u -> z
d -> c
Final output of encryption for the given word is:
Plain Text: " STUDYISFUN "
Key: MONARCHY
Encrypted Text: TLZCBGPIWM
Encryption:
ST == TL
UD == ZC
YI == BG
SF == PI
UN == WM
Plain text: STUDYISFUN
Key: MONARCHY
Encrypted text: TLZCBGPIWM
********END HERE**********