Chapter No 3
Cryptography
Symmetric encryption
• Symmetric encryption involves using a single key to encrypt and decrypt
data, while asymmetric encryption uses two keys - one public and one
private - to encrypt and decrypt data.
• In Symmetric-key encryption the message is encrypted by using a key and
the same key is used to decrypt the message which makes it easy to use
but less secure. It also requires a safe method to transfer the key from one
party to another.
• It uses one key for both encryption and decryption.
• Faster and more efficient for large amounts of data.
• Requires a secure method to share the key between sender and receiver.
• Common algorithms include AES, DES, Blowfish.
• It is used in file encryption, VPNs, and secure data storage.
Asymmetric key encryption
• Asymmetric key encryption is one of the most common cryptographic
methods that involve using a single key and its pendent, where one key is
used to encrypt data and the second one is used to decrypt an encrypted
text. The second key is kept highly secret, while the first one which is called
a public key can be freely distributed among the service’s users.
• It uses two keys a public key for encryption and a private key for
decryption.
• More secure but slower than symmetric encryption.
• No need to share the private key, reducing the risk of exposure.
• Common algorithms include RSA, ECC, Diffie-Hellman.
• It is used in digital signatures, SSL/TLS, and secure email communication.
Caesar cipher
• The Caesar cipher is a simple encryption technique that was used by Julius
Caesar to send secret messages to his allies.
• It works by shifting the letters in the plaintext message by a certain number
of positions, known as the “shift” or “key”.
• The Caesar Cipher technique is one of the earliest and simplest methods of
encryption techniques.
• It’s simply a type of substitution cipher, i.e., each letter of a given text is
replaced by a letter with a fixed number of positions down the alphabet.
For example with a shift of 1, A would be replaced by B, B would become C,
and so on. The method is apparently named after Julius Caesar, who
apparently used it to communicate with his officials.
Cryptography Algorithm For the Caesar Cipher
• hus to cipher a given text we need an integer value, known as a shift
which indicates the number of positions each letter of the text has
been moved down.
The encryption can be represented using modular arithmetic by first
transforming the letters into numbers, according to the scheme, A =
0, B = 1,…, Z = 25. Encryption of a letter by a shift n can be described
mathematically as.
• For example, if the shift is 3, then the letter A would be replaced by
the letter D, B would become E, C would become F, and so on. The
alphabet is wrapped around so that after Z, it starts back at A.
• To decrypt the message, you simply need to shift each letter back by
the same number of positions. In this case, you would shift each
letter in “KHOOR” back by 3 positions to get the original message,
“HELLO”.
•
En(x)=(x+n)mod 26 En(x)=(x+n)mod 26
(Encryption Phase with shift n)
• Dn(x)=(x−n)mod 26 Dn(x)=(x−n)mod 26
(Decryption Phase with shift n)
Playfair Cipher
• The Playfair Cipher Encryption Algorithm:
The Algorithm consists of 2 steps:
• 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.
• 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.
• E.g Pair cannot be made with same letter. Break the letter in single
and add a bogus letter to the previous letter.
• Plain Text: “hello”
• After Split: ‘he’ ‘lx’ ‘lo’
• Here ‘x’ is the bogus letter.
Vigenère Cipher
• Vigenere Cipher is a method of encrypting alphabetic text. It uses a simple
form of polyalphabetic substitution. A polyalphabetic cipher is any cipher
based on substitution, using multiple substitution alphabets. The
encryption of the original text is done using the Vigenère square or
Vigenère table.
• The table consists of the alphabets written out 26 times in different rows,
each alphabet shifted cyclically to the left compared to the previous
alphabet, corresponding to the 26 possible Caesar Ciphers.
• At different points in the encryption process, the cipher uses a different
alphabet from one of the rows.
• The alphabet used at each point depends on a repeating keyword.
Example:
Input : Plaintext : GEEKSFORGEEKS
Keyword : AYUSH
Output : Ciphertext : GCYCZFMLYLEIM
For generating key, the given keyword is repeated
in a circular manner until it matches the length of
the plain text.
The keyword "AYUSH" generates the key "AYUSHAYUSHAYU"
The plain text is then encrypted using the process
explained below.
• Encryption:
• The first letter of the plaintext, G is paired with A, the first letter of
the key. So use row G and column A of the Vigenère square, namely
G. Similarly, for the second letter of the plaintext, the second letter of
the key is used, the letter at row E, and column Y is C. The rest of the
plaintext is enciphered in a similar fashion.
A more easy implementation could be to visualize Vigenère algebraically by
converting [A-Z] into numbers [0–25].
Encryption
The plaintext(P) and key(K) are added modulo 26.
Ei = (Pi + Ki) mod 26
Decryption
Di = (Ei - Ki) mod 26
Note: Di denotes the offset of the i-th character of the plaintext. Like offset of A is 0 and
of B is 1 and so on.
Vernam Cipher or One Time Pad Algorithm
• One Time Pad algorithm is the improvement of the Vernam Cipher,
proposed by An Army Signal Corp officer, Joseph Mauborgne. It is the only
available algorithm that is unbreakable(completely secure). It is a method
of encrypting alphabetic plain text. It is one of the Substitution techniques
which converts plain text into ciphertext. In this mechanism, we assign a
number to each character of the Plain-Text.
• The two requirements for the One-Time pad are
• The key should be randomly generated as long as the size of the message.
• The key is to be used to encrypt and decrypt a single message, and then it
is discarded.
• So encrypting every new message requires a new key of the same
length as the new message in one-time pad.
• The ciphertext generated by the One-Time pad is random, so it does
not have any statistical relation with the plain text.
• The assignment is as follows:
A B C D E F G H I J
0 1 2 3 4 5 6 7 8 9
K L M N O P Q R S T
10 11 12 13 14 15 16 17 18 19
U V W X Y Z
20 21 22 23 24 25
Examples: