Skip to content

Instantly share code, notes, and snippets.

@CodeByAidan
Created September 15, 2022 16:19
Show Gist options
  • Save CodeByAidan/b548127b4b8268060b0bdcd0f65a0a31 to your computer and use it in GitHub Desktop.
Save CodeByAidan/b548127b4b8268060b0bdcd0f65a0a31 to your computer and use it in GitHub Desktop.
Vigenère cipher encryption
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