Created
September 15, 2022 16:19
-
-
Save CodeByAidan/b548127b4b8268060b0bdcd0f65a0a31 to your computer and use it in GitHub Desktop.
Vigenère cipher encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
a = string.ascii_lowercase | |
p = "mei" | |
k = "biru" | |
if len(k) > len(p): k = k[:len(p)] | |
if len(k) < len(p): | |
i = 0 | |
while len(k) != len(p): | |
k += k[i % len(k)] | |
i += 1 | |
pIndex = [a.index(char) for char in p if char.isalpha()] | |
kIndex = [a.index(char) for char in k if char.isalpha()] | |
index = [pIndex, kIndex] | |
index = [sum(a) % 26 for a in zip(*index)] | |
print(str().join([chr(i + 97) for i in index])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment