Skip to content

Instantly share code, notes, and snippets.

@dssstr
Last active December 16, 2023 09:01
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dssstr/aedbb5e9f2185f366c6d6b50fad3e4a4 to your computer and use it in GitHub Desktop.
Save dssstr/aedbb5e9f2185f366c6d6b50fad3e4a4 to your computer and use it in GitHub Desktop.
Simple Vigenere Cipher written in Python 3.5.
def encrypt(plaintext, key):
key_length = len(key)
key_as_int = [ord(i) for i in key]
plaintext_int = [ord(i) for i in plaintext]
ciphertext = ''
for i in range(len(plaintext_int)):
value = (plaintext_int[i] + key_as_int[i % key_length]) % 26
ciphertext += chr(value + 65)
return ciphertext
def decrypt(ciphertext, key):
key_length = len(key)
key_as_int = [ord(i) for i in key]
ciphertext_int = [ord(i) for i in ciphertext]
plaintext = ''
for i in range(len(ciphertext_int)):
value = (ciphertext_int[i] - key_as_int[i % key_length]) % 26
plaintext += chr(value + 65)
return plaintext
@SHTEFOZOID
Copy link

bravo Raihan!! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment