Experiment No: 7: Name: Rhugved Satardekar Roll No: 17141208
Experiment No: 7: Name: Rhugved Satardekar Roll No: 17141208
Experiment No: 7
Theory:
Poly-alphabetic Cipher:
In a polyalphabetic cipher, multiple cipher alphabets are used. To facilitate encryption, all the
alphabets are usually written out in a large table, traditionally called a tableau. Usually the
tableau is 26 × 26, so that 26 full ciphertext alphabets are available. The method of filling the
tableau, and of choosing which alphabet to use next, defines the particular polyalphabetic
cipher. All such ciphers are easier to break than were believed since the substitution alphabets
are repeated for sufficiently large plaintexts. One of the most popular was that of Vigenere
cipher. A simple substitution cipher involves a single mapping of the plaintext alphabet onto
ciphertext characters (Menezes et al 1997). A more complex alternative is to use different
substitution mappings (called multiple alphabets) on various portions of the plaintext. This
results in so-called polyalphabetic substitution. In the simplest case, the different alphabets
are used sequentially and then repeated, so the position of each plaintext character in the
source string determines which mapping is applied to it. Under different alphabets, the same
plaintext character is thus encrypted to different ciphertext characters, precluding simple
frequency analysis as per monoalphabetic substitution. The simple Vigenere cipher is a
polyalphabetic substitution cipher. The definition is repeated here for convenience.
A stream cipher is a polyalphabetic cipher if the value of id does depend on the position of
the plain text character in the plain text stream. Each alphabetic character of plain text can be
mapped onto ‘m’ alphabetic characters of a cipher text. The relationship between a character
in the plain text and the characters in the cipher text is one-to-many.
VIGENERE ` CIPHER:
The best known, and one of the simplest, polyalphabetic ciphers is the Vigenère cipher. In
this scheme, the set of related monoalphabetic substitution rules consists of the 26 Caesar
ciphers with shifts of 0 through 25. Each cipher is denoted by a key letter, which is the
ciphertext letter that substitutes for the plaintext letter a. Thus, a Caesar cipher with a shift of
3 is denoted by the key value . We can express the Vigenère cipher in the following manner.
Assume a sequence of plaintext letters and a key consisting of the sequence of letters , where
typically < .The sequence of ciphertext letters is calculated as follows: Thus, the first letter of
the key is added to the first letter of the plaintext, mod 26, the second letters are added, and so
on through the first letters of the plaintext. For the next letters of the plaintext, the key letters
are repeated. This process continues until all of the plaintext sequence is encrypted.
The advantage of Polyalphabetic ciphers is that they make frequency analysis more difficult.
Frequency analysis is the practice of decrypting a message by counting the frequency of
ciphertext letters, and equating it to the letter frequency of normal text. For instance if P
occurred most in a ciphertext whose plaintext is in English, one could suspect that P
corresponded to E, because E is the most frequently used letter in English. Using the
Vigenere cipher, E can be enciphered as any of several letters in the alphabet in the Vigenere
cipher, thus defeating simple frequency analysis .
Program:
import math
import time
import random
encrypt_letter_to_num =
{"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,"l":11,"m":12,"n":13,"o":14,
"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,"v":21,"w":22,"x":23,"y":24,"z":25,"'":26,",":27,".":
28,"?":29,"/":30," ":31}
encrypt_num_to_letter =
{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",26:"'",27:",",28:
".",29:"?",30:"/",31:" "}
while True:
en_de = ""
en_de = input("Would you like to encrypt a message or decrypt a message?[e/d]: ").lower()
if en_de == "e":
displacement_word = input("Please enter your displacement word: ")
main_body = (input("Please input your message, all cases will be changed to lower:
")).lower()
new_word = ""
displacement_list = []
for x in displacement_word:
displacement_list.append(encrypt_letter_to_num[x])
displacement_list_position_count = 0
for x in main_body:
if displacement_list_position_count == len(displacement_list):
displacement_list_position_count = 0
old_value = encrypt_letter_to_num[x]
new_value = old_value + displacement_list[displacement_list_position_count]
while new_value > 31:
new_value -= 32
new_word += encrypt_num_to_letter[new_value]
displacement_list_position_count += 1
print(new_word)
if en_de == "d":
displacement_word = input("Please enter your displacement word: ")
main_body = (input("Please input your message, all cases will be changed to lower:
")).lower()
new_word = ""
displacement_list = []
for x in displacement_word:
displacement_list.append(encrypt_letter_to_num[x])
displacement_list_position_count = 0
for x in main_body:
if displacement_list_position_count == len(displacement_list):
displacement_list_position_count = 0
old_value = encrypt_letter_to_num[x]
new_value = old_value - displacement_list[displacement_list_position_count]
while new_value < 0:
new_value += 32
new_word += encrypt_num_to_letter[new_value]
displacement_list_position_count += 1
print(new_word)
Output:
Conclusion: Thus we have studied how to Implement and write advantages of Poly-
alphabetic Cipher.