Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active August 6, 2021 17:26
Show Gist options
  • Save nick3499/30e6bb2ede33e64328566e43cc913599 to your computer and use it in GitHub Desktop.
Save nick3499/30e6bb2ede33e64328566e43cc913599 to your computer and use it in GitHub Desktop.
Python3: Decode ROT13-Encoded String: regex, ord(), chr()
#!/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: ')))
@nick3499
Copy link
Author

nick3499 commented Aug 6, 2021

The ROT13 flips letters of the alphabet half-wise. <-- I know, that's vague.

A B C D E F G H I J K L M 
N O P Q R S T U V W X Y Z

HELLO WORLD becomes URYYB JBEYQ

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