Last active
September 14, 2023 20:00
-
-
Save goteusz-maszyk/401f451c4fc870c03bed9168b725af6a to your computer and use it in GitHub Desktop.
My Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import decoder | |
import encoder | |
if __name__ == "__main__": | |
if sys.argv[1] == "encode": | |
print(encoder.encode(sys.argv[2])) | |
elif sys.argv[1] == "decode": | |
print(decoder.decode(sys.argv[2])) | |
else: | |
print("Unknown option: " + sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
def decode(code: str): | |
cod = list(map(int, code.split("."))) | |
out: str = '' | |
random.seed(cod[0]) | |
for i in range(1, len(code)): | |
out += chr(cod[i] // random.randint(1, 1000)) | |
return out | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("USAGE: py decoder.py <message>") | |
exit(1) | |
print(decode(sys.argv[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import random | |
def encode(msg: str): | |
out: list[str] = [] | |
seed = random.randint(0, 10000) | |
random.seed(seed) | |
out.append(str(seed)) | |
for i in range(len(msg)): | |
out.append(str(random.randint(1, 1000) * ord(msg[i]))) | |
return '.'.join(map(str, out)) | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("USAGE: py encoder.py <message>") | |
exit(1) | |
print(encode(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment