Professional Documents
Culture Documents
Css Exp 2
Css Exp 2
Css Exp 2
Experiment No 2
Theory:
Introduction
The vigenere cipher is an algorithm that is used to encrypt and decrypt the text. The vigenere
cipher is an algorithm of encrypting an alphabetic text that uses a series of interwoven caesar
ciphers. It is based on a keyword's letters. It is an example of a polyalphabetic substitution
cipher. This algorithm is easy to understand and implement. This algorithm was first described in
1553 by Giovan Battista Bellaso. It uses a Vigenere table or Vigenere square for encryption and
decryption of the text. The vigenere table is also called the tabula recta.
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
Program
import re
import string
c = ""
for x in k:
kpos.append(alphabets.find(x))
i=0
for x in p:
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
if i == len(kpos):
i=0
pos = alphabets.find(x) + kpos[i] #find the number or index of the character and perform the
shift with the key
print(pos)
i +=1
return c
p = ""
kpos = []
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
for x in k:
kpos.append(alphabets.find(x))
i=0
for x in c:
if i == len(kpos):
i=0
if pos < 0:
pos = pos + 26
p += alphabets[pos].lower()
i +=1
return p
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
try:
"The text message should contain only characters and the key should be one character
word \n"
if choose == '1':
p = p.replace(" ", "") # this will make sure that there is no space in the message
if p.isalpha():
if k.isalpha():
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
# print(k)
c = encrypt(p, k)
else:
print(k)
else:
if c.isalpha():
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
if not k.isalpha():
else:
p = decrypt(c, k)
else:
else:
except Exception as e:
print(e)
Vidya Vikas Education Trust’s
Universal College of Engineering, Kaman Road, Vasai-401208
Accredited by B+ Grade by NAAC
exit()
Output:
Conclusion: