-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvigenere_cipher.py
More file actions
28 lines (22 loc) · 836 Bytes
/
vigenere_cipher.py
File metadata and controls
28 lines (22 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
init_phrase = "Hi! I'm a Software Developer"
custom_key = 'qwertyuiopasdfghjklzxcvbnm'
def vigenere(message, key):
key_index = 0
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
# Define the offset and the encrypted letter
offset = alphabet.index(key_char)
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_text += alphabet[new_index]
return encrypted_text
encryption = vigenere(init_phrase, custom_key)
print(encryption)