0% found this document useful (0 votes)
142 views5 pages

Vigenere Cipher Report

This document defines functions for a basic encryption/decryption algorithm using a randomly generated key of letters. The Key_Generation function generates a random key of a given length by randomly selecting letters from the alphabet. The Enc function encrypts plaintext by shifting each letter according to its corresponding key letter. The Dec function decrypts ciphertext by reversing the encryption shift using the same key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views5 pages

Vigenere Cipher Report

This document defines functions for a basic encryption/decryption algorithm using a randomly generated key of letters. The Key_Generation function generates a random key of a given length by randomly selecting letters from the alphabet. The Enc function encrypts plaintext by shifting each letter according to its corresponding key letter. The Dec function decrypts ciphertext by reversing the encryption shift using the same key.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',

'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] (*)

import random
This is a library function for generating random numbers

def Key_Generation(size):
We have defined the function for generating the key ????

key = ''
We have defined an empty key
temp_copy = Alphabet.copy()
????
for i in range(26):
This for loop is to.???????
key = key +
temp_copy.pop(random.randint(0,len(temp_copy)-1))
?
if i == (size-1):
This statement will check
break
This statement will stop the for loop once..
return key
The function returns the ciphertext when plaintext..?

def Enc(plaintext, key):


This is the encrypton functon whch takes plaintext and key
where key is a pair
ciphertext = ''
We have defined an empty cipher text
counter = 0
?
size = len(key)
?
print('key:: ', key)
We are printing the key in case if the key is generated
randomly although it is not neccessary
print()
??
for char in plaintext:
This for loop reads all the character of the plain text

if char in Alphabet:
This statement will check whether the character of the plain
text is in the set of the defined alphabet (*)

ciphertext = ciphertext +
Alphabet[(Alphabet.index(char) + Alphabet.index(key[counter]))
% 26]
If the character of the plain text is in alphabet then we
encrypted it by shifting with the value of key
counter = counter + 1
??
if counter == size:
This statement will check whether te size
counter = 0
If the counter 0 then we..??
else:
If the character of the plain text is not in alphabet (*) then we
do the following
ciphertext = ciphertext + char
We make the character part of the character without encrypting

return ciphertext
The function returns the ciphertext when plaintext is encryipted
completely

def Dec(ciphertext, key):


This is the decryiption function which takes cipher text and key.
plaintext = ''
We have defined empty plaintext

counter = 0
???
size = len(key)
??
print('key:: ', key)
We are printing the key to make sure that it matches
encryption key
for char in ciphertext:
This for loop will read each character of the cipher text
if char in Alphabet:
This statement will check whether the cipher text character is in
alphabet if so then we do the following
plaintext = plaintext + Alphabet[(Alphabet.index(char) Alphabet.index(key[counter]))% 26]
We decript the cipher text character by
counter = counter + 1
?
if counter == size:
?
counter = 0
?
else:
If the character is not in the alphabet then we do the following
plaintext = plaintext + char

We make the character part of the plain text

return plaintext
Once a ciphertext is decrypted completely than we returned the
plain text

You might also like