Skip to content

Instantly share code, notes, and snippets.

@meicookies
Created September 15, 2022 16:16
Show Gist options
  • Save meicookies/4b6cb29811c0b730c1daf71cb0bfa763 to your computer and use it in GitHub Desktop.
Save meicookies/4b6cb29811c0b730c1daf71cb0bfa763 to your computer and use it in GitHub Desktop.
Vigenère 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]))
# Vigenère cipher encryption coded by meicookies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment