Last active
August 6, 2021 17:26
-
-
Save nick3499/30e6bb2ede33e64328566e43cc913599 to your computer and use it in GitHub Desktop.
Python3: Decode ROT13-Encoded String: regex, ord(), chr()
This file contains hidden or 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
#!/bin/python3 | |
'''Decode picoGym flag based on ROT13 cypher.''' | |
import re | |
def decode_rot13(s: str) -> str: | |
'''Decode string.''' | |
decode = '' | |
for char in s: | |
if ord(char) > 64 and ord(char) < 78: | |
decode += chr(ord(char) + 13) | |
elif ord(char) > 77 and ord(char) < 91: | |
decode += chr(ord(char) - 13) | |
elif ord(char) > 96 and ord(char) < 110: | |
decode += chr(ord(char) + 13) | |
elif ord(char) > 109 and ord(char) < 123: | |
decode += chr(ord(char) - 13) | |
else: | |
decode += char | |
return f'\x1b[44mDecoded string\x1b[0m: {decode}' | |
if __name__ == '__main__': | |
print(decode_rot13(input('\x1b[44mPaste encoded string\x1b[0m: '))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ROT13 flips letters of the alphabet half-wise. <-- I know, that's vague.
HELLO WORLD becomes URYYB JBEYQ