"""
This is a very basic method for encrypting and decrypting vigenere ciphers with a given key
Includes ALL CHARACTERS within the ASCII Value range of 32-127 (All printable characters) unlike other vigenere cipher methods I've seen so far that only do uppercase/lowercase letters which is why I'm posting this
Sorry about the messy code, I'm mostly self-taught and do not have a lot of experience with Python but it works, I swear
"""
def repeat_string(a_string, target_length):
number_of_repeats = target_length // len(a_string) + 1
a_string_repeated = a_string * number_of_repeats
a_string_repeated_to_target = a_string_repeated[:target_length]
return a_string_repeated_to_target
def encrypt(key, test):
repeated_string = repeat_string(key, len(test))
finalthing = ""
asciiText = [ord(c) for c in test]
asciiKey = [ord(c) for c in repeated_string]
for x in range(0, len(asciiText), 1):
asciiText[x] = asciiText[x] + asciiKey[x]
while asciiText[x] > 126:
asciiText[x] -= 95
while asciiText[x] < 32:
asciiText[x] += 95
for x in range(0, len(asciiText), 1):
finalthing += chr(asciiText[x])
return finalthing
def decrypt(key, test):
repeated_string = repeat_string(key, len(test))
finalthing = ""
asciiText = [ord(c) for c in test]
asciiKey = [ord(c) for c in repeated_string]
for x in range(0, len(asciiText), 1):
asciiText[x] = asciiText[x] - asciiKey[x]
while asciiText[x] > 126:
asciiText[x] -= 95
while asciiText[x] < 32:
asciiText[x] += 95
for x in range(0, len(asciiText), 1):
finalthing += chr(asciiText[x])
return finalthing
encrypted = encrypt("code", "Scissor Seven is a painfully underrated show!!")
print(encrypted)
decrypted = decrypt("code", encrypted)
print(decrypted)