









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Design and Implementation of a product cipher using Substitution and Transposition ciphers.
After the successful completion of this experiment, students will be able to apply the knowledge of symmetric cryptography to implement simple ciphers.
● Cryptography is the art of achieving security by encoding messages to make them non-readable. There are two types of cryptographic algorithms: ● Substitution and ● Transposition. Product cipher is a combination of both these types to achieve a better effect of security. An original message is known as the plaintext , while the coded message is called the ciphertext.
The process of converting from plaintext to ciphertext is known as enciphering or encryption ; restoring the plaintext from the ciphertext is deciphering or decryption. The many schemes used for encryption constitute the area of study known as cryptography. Such a scheme is known as a cryptographic system or a cipher. Techniques used for deciphering a message without any knowledge of the enciphering details fall into the area of cryptanalysis. Cryptanalysis is what the layperson calls “breaking the code.”The areas of cryptography and cryptanalysis together are called cryptology. ● Cryptography is the art of achieving security by encoding messages to make them non-readable. There are two types of cryptographic algorithms: Substitution and Transposition. Product cipher is a combination of both these types to achieve a better effect of security. ● Substitution Cipher: Additive or Shift or Caesar Cipher algorithm is a cryptographic algorithm invented by Caesar. It is a substitution based algorithm.
A symmetric encryption scheme has five ingredients (Figure 2.1):
These chips are widely available and incorporated into several products. With the use of symmetric encryption, the principal security problem is maintaining the secrecy of the key. Let us take a closer look at the essential elements of a symmetric encryption scheme, using Figure 2.2. A source produces a message in plaintext, X=[X1, X2, X3, …….., Xm]. The M elements of X are letters in some finite alphabet. Traditionally, the alphabet usually consisted of 26 capital letters. Nowadays, the binary alphabet {0, 1} is typically used. For encryption, a key of the form K=[K1, K2, K3,……, Kj] is generated. If the key is generated at the message source, then it must also be provided to the destination employing some secure channel. Alternatively, a third party could generate the key and securely deliver it to both source and destination. With the message and the encryption key K as input, the encryption algorithm forms the ciphertext Y=[Y1, Y2, Y3,……….., Yn]. We can write this as; Y=E(K, X) This notation indicates that Y is produced by using encryption algorithm E as a function of the plaintext X, with the specific function determined by the value of the key K.
The intended receiver, in possession of the key, can invert the transformation: X=D(K,Y) An opponent, observing Y but not having access to K or X, may attempt to recover X or K or both X and K.It is assumed that the opponent knows the encryption (E) and decryption (D) algorithms. If the opponent is interested in only this particular message, then the focus of the effort is to recover X by generating a plaintext estimate X. Often, however, the opponent is interested in being able to read future messages as well, in which case an attempt is made to recover K by generating an estimate K.
@Encryption..... A - Substitution Cipher
(Students must submit the soft copy as per the following segments within two hours of the practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned lab in charge faculties at the end of the practical in case there is no Blackboard access available) Roll No. 50 Name: AMEY THAKUR Class: Comps TE B Batch: B Date of Experiment: 29/01/2021 Date of Submission: 29/01/ Grade:
(add a snapshot of the output of product cipher)
(Add source code of product Cipher) Product_Cipher.py
key = 'abcdefghijklmnopqrstuvwxyz' def encrypt(n, plaintext): result = '' for l in plaintext.lower(): try: i = (key.index(l) + n) % 26 result += key[i] except ValueError: result += l return result.lower() def decrypt(n, ciphertext): result = '' for l in ciphertext: try: i = (key.index(l) - n) % 26 result += key[i] except ValueError: result += l return result text=input(str("Enter a message for Encryption: ")) print("Enter a Key: ") offset=input() offset=int(offset,10) print ("Plaintext: " + text) encrypted = encrypt(offset, text) print('Encrypted Message: ', encrypted) decrypted = decrypt(offset, encrypted) print('Decrypted Message: ', decrypted)
down. Let’s see one example. The plain text is EDUCBA. As a Caesar cipher, each alphabet is replaced by three-place down, so E will replace by H, D will replace by G, U will replace by X, C will replace by F, B will replace by E and A will replace by D. So here the plain text is EDUCBA and ciphertext Is HGXFED. ➔ Caesar cipher algorithm is as follows:
➔ In polygram substitution cipher, rather than replacing each alphabet with another, the Block of alphabets is replaced with another block of alphabets. Replace EDUCBA with XYQLAB. In this case, EDUCBA will be replaced with XYQLAB, but EDU can be replaced with another set of the block, let’s assume EDU will replace LOD. In this type of ciphers, the replacement of plain text is done through the block by block rather than character by character.
5. Polyalphabetic Substitution Cipher ➔ Polyalphabetic Cipher is also known as Vigenere Cipher which is invented by Leon Battista Alberti. In Polyalphabetic Substitution Cipher is a method of encrypting alphabetic texts. It uses multiple substitution alphabets for encryption. Vigenere square or Vigenere table is used to encrypt the text. The table contains 26 alphabets written in different rows each alphabet being cyclically shifted to the left following the previous alphabet, equivalent to the 26 possible Caesar Ciphers. The cipher uses a different alphabet from one of the rows at various points in the encryption process. ➔ Let’s consider Original text is Educba and the keyword is Apple. For the encryption process, The first letter of the original text, E is paired with A, the first letter of the key. So use row E and column A of the Vigenère square, which is E. Similarly, for the second letter of the original text, the second letter of the key is used, the letter at row d and column p is s. The rest of the original text is enciphered in the same way. The final encryption of Educba is Esjnfa. 6. Playfair Cipher ➔ Playfair cipher is also called Playfair square. It is a cryptographic technique that is used to encrypt the data. ➔ The Playfair cipher process is as follows: 1. Creation and population of the matrix. 2. Encryption process. ➔ Let’s discuss the above-mentioned steps in detail: manners, creation and population of the matrix. It uses a 5 * 5 matrix to store the keyword or the key which is used for the encryption and decryption process. ➔ This step is working as follows: 1. Enter the keyword in the matrix in a row-wise manner i.e., from left to right and top to bottom. 2. Skip the duplicate words in the keyword. 3. Fill the remaining spaces with the rest of the alphabets (A – Z) that were not a part of the keyword. Note: while doing so, combine I and J in the same cell of the table. i.e. If I or J is present in the keyword, discard both I and J while filling the remaining space encryption process.
depending on a key. For example, with a shift of 1, A would be replaced by B, B would become C, and so on. Note: Special case of Substitution cipher is known as Caesar cipher where the key is taken as 3. Mathematical representation ➔ 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. En ( x )=( x + n ) mod (^26) ❑ (Encryption Phase with shift n) Dn ( x )=( x − n ) mod (^26) ❑ (Decryption Phase with shift n) Original: ABCDEFGHIJKLMNOPQRSTUVWXYZ Shifted: DEFGHIJKLMNOPQRSTUVWXYZABC Examples: Algorithm for Substitution Cipher: ➔ Input:
➔ With the integer values of the plaintext letters found, the next step is to perform the calculations on those values. In this instance, the math needed is (5x+8). Finally, we must ensure that all our answers are calculated mod 26 and convert the integers back to ciphertext letters. All this information is shown in the table below. The affine cipher with a = 5, b = 8. We work out values of letters, then do the calculations before converting numbers back to letters. ➔ Thus the ciphertext produced is "IHHWVC SWFRCP.” Decryption ➔ In deciphering the ciphertext, we must perform the opposite (or inverse) functions on the ciphertext to retrieve the plaintext. Once again, the first step is to convert each of the ciphertext letters into their integer values. We must now perform the following calculation on each integer. D(x) = c(x - b) mod m Where c is the modular multiplicative inverse of a, an x c = 1 mod m (c is the number such that when you multiply a by it and keep taking away the alphabet’s length, you get to 1). ➔ Continuing our example, we shall decrypt the ciphertext "IHHWVC SWFRCP,” using a key of a = 5, b = 8. The first step here is to find the inverse of a, which in this case is 21 (since 21 x 5 = 105 = 1 mod 26, as 26 x 4 = 104, and 105 - 104 = 1). We must now perform the inverse calculations on the integer values of the ciphertext. In this case, the calculation is 21(y - 8). Once again, we must take these answers modulo 26 and finally convert the integers back to plaintext letters. This is shown in the table below. The decryption process for a key of a = 5, b = 8. We had to find the inverse of a first, which is 21.
➔ We retrieve our plaintext of "affine cipher.”
(Write an appropriate conclusion.) After completing this experiment, we will be able to apply symmetric cryptography knowledge to implement simple ciphers. Also, we can now work with cryptology as we learned about various mathematical models and algorithms. We got an in-depth understanding of ciphers with the programs and mathematical implementation. This experiment helped to understand Plaintext, Encryption, and Decryption theory.