Docsity

Symmetric Cryptography and Cipher Techniques, Summaries of Mathematics

Toggle sidebar
bg1
Terna Engineering College
Computer Engineering Department
Class: TE Sem.: VI
Course: System Security Lab
PART A
(PART A: TO BE REFERRED BY STUDENTS)
Experiment No.01
A.1 Aim:
Design and Implementation of a product cipher using Substitution and
Transposition ciphers.
A.2 Prerequisite:
1. Basic Knowledge of Cryptography.
2. Knowledge of Substitution Cipher techniques.
A.3 Outcome:
After the successful completion of this experiment, students will be able to
apply the knowledge of symmetric cryptography to implement simple ciphers.
A.4 Theory:
●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.
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Symmetric Cryptography and Cipher Techniques and more Summaries Mathematics in PDF only on Docsity!

Terna Engineering College

Computer Engineering Department

Class: TE Sem.: VI

Course: System Security Lab

PART A

(PART A: TO BE REFERRED BY STUDENTS)

Experiment No.

A.1 Aim:

Design and Implementation of a product cipher using Substitution and Transposition ciphers.

A.2 Prerequisite:

  1. Basic Knowledge of Cryptography.
  2. Knowledge of Substitution Cipher techniques.

A.3 Outcome:

After the successful completion of this experiment, students will be able to apply the knowledge of symmetric cryptography to implement simple ciphers.

A.4 Theory:

● 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.

● Symmetric Cipher Model

A symmetric encryption scheme has five ingredients (Figure 2.1):

  • Plaintext: This is the original intelligible message or data that is fed into the algorithm as input.
  • Encryption algorithm: The encryption algorithm performs various substitutions and transformations on the plaintext.
  • Secret key: The secret key is also input into the encryption algorithm. The key is a value independent of the plaintext and the algorithm. The algorithm will produce a different output depending on the specific key being used at the time. The exact substitutions and transformations performed by the algorithm depend on the key. - Ciphertext: This is the scrambled message produced as output. It depends on the plaintext and the secret key. For a given message, two different keys

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.

A.5 EXAMPLE:

  1. Plaintext: CryPto(Sender’s input) Key: 5(agreement key, here input) Cipher text: (C+5)(r+5)(y+5)(P+5)(t+5)(o+5) : HwdUyt(output)
  2. Cipher Text: XdkcZm(Receiver’s Input) Key: 5(agreement key, here input) Plaintext: CiphEr (output)

A.6 ALGORITHM:

@Encryption..... A - Substitution Cipher

  1. Take the Value of Plaintext.
  2. Take Value of Key.
  3. Run the loop n times here n will be the length of the text.
  4. Convert the string into characters and that same time add with Key.
  5. After Addition, mod 26 or 125 can be used depending on where you want to limit that entry of plain text.
  6. Then save and convert the calculated part (character) into a string or StringBuffer.
  7. Now the Final output will be the actual Cipher Text. B - Transposition Cipher
  8. The input of this Cipher will be the output from the Substitution Cipher.
  9. Convert into a matrix with the help of the key (the key is different these times).
  10. And with the help of the matrix, just lay down the content of the matrix or save the content into a simple string.
  11. This String will be the Cipher Text.

PART B

(PART B: TO BE COMPLETED BY STUDENTS)

(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:

B.1 The output of Product Cipher:

(add a snapshot of the output of product cipher)

B.2 Source Code 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)

B.3 Question of Curiosity:

  1. What are the Ciphers? Ans:

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:

  1. Read each alphabet of plain text.
  2. Replace each alphabet with 3 places down.
  3. Repeat the process for all alphabet in plain text. ➔ A Modified Version of Caesar Cipher: This cipher works the same as Caesar cipher, the only difference is – in Caesar cipher, each alphabet is replaced by three-place down wherein a modified version of Caesar cipher, the number is decided by a user to replace the alphabet and this number will be constant. For example, EDUCBA and number for the replacement are 1, so E will replace by F, D will replace by E, U will replace by V, C will replace by D, B will replace by C and A will replace by B. So here the plain text is EDUCBA and ciphertext Is FEVDCB. ➔ A modified version of the Caesar cipher algorithm is as follows
  4. Read each alphabet of plain text.
  5. Take the number for replacement.
  6. Replace each alphabet with a specified number down.
  7. Repeat the process for all alphabet in plain text. 2. Monoalphabetic Cipher ➔ As Caesar cipher and a modified version of Caesar cipher is easy to break, a monoalphabetic cipher comes into the picture. In monoalphabetic, each alphabet in plain text can be replaced by any other alphabet except the original alphabet. That is A can be replaced by any other alphabet from B to Z. B can be replaced by A or C to Z. C can be replaced by A, B, and D to z, etc. ➔ Mono alphabetic cipher causes difficulty to crack the message as there are random substitutions and a large number of permutations and combinations are available. 3. Homophonic Substitution Cipher ➔ A homophonic substitution cipher is similar to a monoalphabetic cipher the only difference is in monoalphabetic we replace the alphabet with any other random alphabet except the original alphabet wherein homophonic substitution cipher, the alphabet is replaced by fixed alphabet or set of alphabet. The substitution alphabet is replaced with the fixed. ➔ For example, replace A with x, E with B, S with A, etc., or replace A with E, x or L, B with T, A, Z, etc. 4. Polygram Substitution Cipher

➔ 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:

  1. A String of both lower and upper case letters, called PlainText.
  2. An Integer is denoting the required key. ➔ Procedure:
  1. Create a list of all the characters.
  2. Create a dictionary to store the substitution for all characters.
  3. For each character, transform the given character as per the rule, depending on whether we’re encrypting or decrypting the text.
  4. Print the new string generated.
  5. What is a Transposition Cipher? Explain with an example. Ans: Transposition Cipher ➔ Transposition Cipher is a cryptographic algorithm where alphabets in the plaintext are rearranged to form a ciphertext. In this process, the actual plain text alphabets are not included. Example ➔ A simple example for a transposition cipher is a columnar transposition cipher where each character in the plain text is written horizontally with specified alphabet width. The cipher is written vertically, which creates an entirely different ciphertext. ➔ Consider the plain text Amey Thakur, and let us apply the simple columnar transposition technique shown below. ENCRYPTION Given Text: Amey Thakur Keyword: MEGA Length of Keyword: 4(No. Of rows) Order of Alphabets in MEGA: 4231 M E G A 4 2 3 1 A m e y _ T h a k u r _ Print Characters of Column: 1,2,3,4. Encrypted Text: ya_mTuehrA_k Output:

➔ 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.”

B.4 Conclusion:

(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.