Skip to content

Instantly share code, notes, and snippets.

@TheRealRyGuy
Created March 12, 2024 21:50
Show Gist options
  • Save TheRealRyGuy/d461857e6f09675af2aff1ebe00250e6 to your computer and use it in GitHub Desktop.
Save TheRealRyGuy/d461857e6f09675af2aff1ebe00250e6 to your computer and use it in GitHub Desktop.
Trying to make some ciphers just look absolutely atrocious, but they work!

What the Cipher

End goal of this is to essentially just write the worst looking ciphers you possibly can. Some of these were just proof of concepts cause I was bored in class, then some I took the extra mile to intentionally look terrible -- the things you do when you're bored.

Example Use Case

import ceaser 

encryption = ceaser.encrypt("Who writes code like this!", 7, ceaser.Shift.LEFT)
print("Encrypted Text:", encryption)
print("Decrypted Text:", ceaser.decrypt(encryption, 7, ceaser.Shift.LEFT))

Not sure if this will be maintained - it's more just something to do. If you ever got bored, feel free to PR! There's no licensing of any sort under this project, so go crazy.

#This was entirely oversimplified for no reason at all, and could absolutely be a lot worse. I got bored
from enum import Enum
__letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Shift = Enum('Shift', ['LEFT', 'RIGHT'])
def encrypt(message: str, amount: int, shift: Shift) -> str: return ''.join(map(lambda letter: __transform(letter, amount, shift == Shift.RIGHT), message))
def decrypt(message: str, amount: int, shift: Shift) -> str: return ''.join(map(lambda letter: __transform(letter, amount, shift == Shift.LEFT), message))
def __transform(letter, shift: int, add: bool):
if(__letters.find(letter.upper()) == -1): return letter
index = __letters.find(letter.upper()) + shift if add else __letters.find(letter.upper()) - shift
if index > len(__letters): index -= len(__letters)
if(index < 0): index += len(__letters)
return __letters[index] if letter.isupper() else __letters[index].lower()
__letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
__shifted = "NOPQRSTUVWYXZABCDEFGHIJKLMnopqrstuvwyxzabcdefghijklm"
def encrypt(message: str) -> str:
return ''.join(list(map(lambda letter: __shifted[__letters.index(letter)] if letter in __letters else letter, message)))
def decrypt(message: str) -> str:
return ''.join(list(map(lambda letter: __letters[__shifted.index(letter)] if letter in __letters else letter, message)))
__letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def encrypt(message: str, key: str) -> str:
res = ""
key_index = 0
for letter in message:
res += __transform(letter, key[key_index], letter.isupper(), True)
key_index += 1
if key_index == len(key): key_index = 0
return res
def decrypt(message: str, key: str) -> str:
res = ""
key_index = 0
for letter in message:
res += __transform(letter, key[key_index], letter.isupper(), False)
key_index += 1
if key_index == len(key): key_index = 0
return res
def __transform(letter, key, uppercase, encoding: bool):
if(__letters.find(letter.upper()) == -1): return letter
if(encoding):
index = __letters.find(letter.upper()) + __letters.find(key.upper())
if(index > len(__letters)): index -= len(__letters)
return __letters[index] if uppercase else __letters[index].lower()
else:
index = __letters.find(letter.upper()) - __letters.find(key.upper())
if(index < 0): index += len(__letters)
return __letters[index] if uppercase else __letters[index].lower()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment