Professional Documents
Culture Documents
EXPERIMENT 4
Objective: Study of Symmetric Encryption Scheme. Task to be performed:
Implementation of following Techniques:
Vigenere cipher (Polyalphabetic technique)
code:
#poly alphabetic
#vignere cipher
n=input("enter your plain text ")
k=input("enter key for cipher: ")
if(len(k)<len(n)):
while(len(k)!=len(n)):
k+=k
lst=[]
lst2=[]
et=[]
dt=[]
for i in n:
lst.append(i)
for i in k:
lst2.append(i)
for i in range(len(lst)):
et.append(chr((((ord(lst[i])-97)+(ord(lst2[i])-97))%26)+97))
print(et)
#decrypt
for i in range(len(lst)):
dt.append(chr((((ord(et[i])-97)-(ord(lst2[i])-97))%26)+97))
print(dt)
Output:
rail, direction = 0, 1
for i in range(len(cipher_text)):
fence[rail][i] = '*'
rail += direction
for i in range(rails):
for j in range(len(cipher_text)):
if fence[i][j] == '*' and index < len(cipher_text):
fence[i][j] = cipher_text[index]
index += 1
plain_text = ''
rail, direction = 0, 1
for i in range(len(cipher_text)):
plain_text += fence[rail][i]
rail += direction
return plain_text
Output: