Professional Documents
Culture Documents
Assignment 1
Name: Agrima Khanna
Roll Number: 2019UCO1511
I/J T H M B
C D E F K
N P Q S U
V W X Y Z
Answer:
IO NL YR EG RE TX TH AT IH AV EB UT ON EL IF ET OG IV EF
MA PA ZO QH GJ HW HM LI TM IA JH PB AS DG MC DH RO CA FJ
OR MY CO UN TR YX
RA FO FA NP BL ZY
3. Encrypt the message “meet me at the usual place at ten rather than eight o clock”.
using the Hill cipher with the key ( 7 3 ) . Show your calculations and the result.
25
Answer:
Alphabet:
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
P=
ME ET ME AT T H EU SU AL PL AC
12 4 4 19 12 4 0 19 19 7 4 20 18 20 0 11 15 11 02
EA TT EN RA TH ER TH AN EI GH
40 19 19 4 13 17 0 19 7 4 17 19 7 0 13 48 67
TO CL OC KA
19 14 2 11 14 2 10 0
C = KP mod 26
1. ( 7 3 )( 12 ) mod 26 = ( 96 ) mod 26 = ( 18 ) = ( S )
2 5 4 44 18 S
2. ( 7 3 )( 4 ) mod 26 = ( 85 ) mod 26 = ( 7 ) = ( H )
2 5 19 103 25 Z
3. ( 7 3 )( 12 ) mod 26 = ( 96 ) mod 26 = ( 18 ) = ( S )
2 5 4 44 18 S
4. ( 7 3 )( 0 ) mod 26 = ( 57 ) mod 26 = ( 5 ) = ( F )
2 5 19 95 17 R
6. ( 7 3 )( 4 ) mod 26 = ( 88 ) mod 26 = ( 10 ) = ( K )
2 5 20 108 4 E
8. ( 7 3 )( 0 ) mod 26 = ( 33 ) mod 26 = ( 7 ) = ( H )
2 5 11 55 3 D
4. Using the Vigenère cipher, encrypt the word “cryptographic” using the word “eng”.
Answer:
Key: engengengenge
Plaintext: cryptographic
Alphabet:
A B C D E F G H I J K L M
0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z
13 14 15 16 17 18 19 20 21 22 23 24 25
Key (Ki) 4 13 6 4 13 6 4 13 6 4 13 6 4
Plaintext (Pi) 2 17 24 15 19 14 6 17 0 15 7 8 2
P i + Ki 6 30 30 19 32 20 10 30 6 19 20 14 6
Ciphertext 6 4 4 19 6 20 10 4 6 19 20 14 6
(Ci = (Pi + Ki) mod 26)
Ciphertext: geetgukegtuog
5. Write a C/C++/Java/python program that can encrypt and decrypt using the general
Caesar cipher.
Answer:
CODE:
#include <iostream>
using namespace std;
string encrypt(string text,int n)
{
string result = "";
for (int i=0;i<text.length();i++)
{
if (isupper(text[i]))
result += char(int(text[i]+n-65)%26 +65);
else
result += char(int(text[i]+n-97)%26 +97);
}
return result;
}
int main()
{
string text;
int num;
cout<<"Main menu\n1.Encrypt\n2.Decrypt\nChoice: ";
cin>>num;
switch(num)
{
case 1:
cout<<"\nEnter plaintext to be encrypted: ";
cin>>text;
cout << "\nCiphertext: " << encrypt(text,3);
break;
case 2:
cout<<"\nEnter ciphertext to be decrypted: ";
cin>>text;
cout << "\nPlaintext: " << encrypt(text,23);
break;
default: cout<<"\nEnter valid number.";
}
return 0;
}
OUTPUT: