Last active
September 8, 2015 20:28
-
-
Save ryz/1befdaea60f41838bc09 to your computer and use it in GitHub Desktop.
GC Decoder
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 re | |
import codecs | |
# decimal to ascii | |
replacements = {"45": "-", "46": "."} | |
# morse code lookup table | |
encoding = { | |
"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": "--..", " ": "/", | |
"0": "-----", "1": ".----", "2": "..---", | |
"3": "...--", "4": "....-", "5": ".....", | |
"6": "-....", "7": "--...", "8": "---..", | |
"9": "----." | |
} | |
paragraphs = ['46454545 45464646 46454545 45454645 46464646 464645 4546 46464546 454546 464546 46464546 4546 45464545 46464546 45464646 45 464546 46464546 46454546 464645 4546 464646 464646 454546 45454645 46464645 464546 46464546 464645 46464645 464546 46 4545 46464646 464546 4645 454546 46464546 46454546 464645 45464545 46464646 464546 46464546 46464546 464546 45464545 4645 46464645 46454546 464645 464645 4546 464546 454546 454546 464546 464545 4546 4645 46464645 46454546 464645 454546 45 464546 45 45464545 4546 46464646 454545 454546 45454645 4546 46464546 464545 464546 45454646 4546 4645 45454645 46464546 45464646 46454545 464546 46464645 454546 45464645 45464646 45454646 45454646 454546 4546 454545 464546 46 45454645 4546 45454645 46464646 464546 46464546 4645 46464646 4645 45 464546 46464546 46454546 464645 4546 464646 464646 454546 464645 4546 46464546 454546 464546 46 464645 4546 464546 45464545 454546 46464546 454546 45454645 46464646 45454645 464546 4645 46464546 46454546 464645 45464545 46464646 464546 46464546 46464546 464546 45464545 464646 46464646 464546 46 45454645 464546 4645 4645 4546 464546 46454546 464645 46464546 454546 464546 4645 4546 454545 46464546 4546 454546 4545 464546 46 45464545 4546 46464646 454546 464546 454546 4645 46464646 45464545 45464545 464546 46464645 4645 46464546 4545 46454545 464546 46464645 45454645 46 464546 46464645 4646 46464645 464546 46 464646 46464646 464546 4645 464646', | |
'45454645 45454645 45464545 46454545 46464546 4545 46464645 46464546 46454546 45464645 46454545 46454545 46464546 4545 46 46454545 45454645 4646 46464546 46464546 454545 46 46454545 45 46464546 4645 46454646 46 46454646 46454546 45 45454645 454646 4545 45454645 4646 464646 464546 46 45464546 464546 4545 464645 4545 45464545 45 4546 45464646 4545 46464546 45464645 45464545 4546 454645 464645 46464546 46454546 45464546 45464546 46454646 46464646 4646 45454646 464546 464645 46454646 464546 45454646 454646 4545 45454645 45 46464646 45454645 454646 45464546 4546 45 464646 454546 46454546 45464646 4545 4545 4645 46454546 45464546 464646 45464546 45464646 464546 45454646 46454646 46454646 45464646 4646 454546 46454646 45 4545 45454645 454646 464546 454646 45464546 454645 45464546 4545 46464645 45 45464545 4546 464546 45454646 45454645 45454645 45464546 45464546 46454646 46454546 45464545 454546 46454546 45464546 45464646 4545 45464545 464645 454646 454646 4545 4646 46464546 4646 45454646 45464646 45464546 454545 464546 4645', | |
'46454545 46454646 4546 45454645 46 45464645 4646 454545 454545 464545 4646 45 46464646 45454646 464545 464545 454646 46454546 454545 45464545 45454646 454545 4646 45464646 4646 454545 46454546 46464646 46464645 45464646 45464545 4645 4645 46454646 464546 45464545 454546 46454545 454646 45464645 45454645 45454646 454645 454645 4546 46464646 46454646 4545 454546 45464646 45464646 454546 4646 46464546 45454645 46464645 46454646 4646 46464546 45464645 46464546 46454546 4645 454645 45464545 454546 4545 45454646 464646 46464646 4545 46454646 454645 45464546 4645 464645 454545 45464645 4546 45464545 46454546 454645 4646 454645 4645 45 45454646 45464645 454545 46464646 464646 45 454545 464545 464545 46464645 4546 46464645 46454545 454546 46464645 45 4645 4545 464646 46454646 4646 45464646 4646 454545 45454646 454646 464545 46464546 454645 46454546 46454545 46464646', | |
'45464545 45464546 46 454646 464646 454645 454646 45454646 464546 46454546 45464645 46464646 46454646 45464546 45 464646 46464646 45464545 464646 454545 45 46464645 45454645 46 454545 454646 4645 464645 45454646 45464646 46464546 46 454545 46454545 45464645 45464646 46464546 454646 45454645 4646 45454646 46464546 4645 45 464546 4646 45454645 454646 46454646 45 46454646 46454545 45454645 454545 46454646 45 46464645 4645 464545 45454646 4546 45464545 464546 45464646 45454646 46464546 45 45464545 4646 4646 454645 454545 464646 464646 454646 46454545 45454645 45464545 464645 46464645 46464645 4645 464545 45454646 45454646 46454546 46464645 45454646 46 464545 45464646 45464545 4645 464645 45454646 45464646 45454645 4545 4646 464646 454645 4645 45464646 46 454545 454645 46 464545 45464646 45464545 4646 4646 464646 46464646 45 45464545 4646 4646 454645 454545 464646' | |
] | |
testCode = ".... . .-.. .-.. --- -.. .- .. .-.. -.-- .--. .-. --- --. .-. .- -- -- . .-. --. --- --- -.. .-.. ..- -.-. -.- --- -. - .... . -.-. .... .- .-.. .-.. . -. --. . ... - --- -.. .- -.-- " | |
decoding = {} | |
for key, val in encoding.items(): | |
decoding[val] = key | |
def encodeMorse(text): | |
return ' '.join(map(lambda x, g=encoding.get: g(x, ' '), text.upper())) | |
def decodeMorse(message): | |
ans = ''.join(map(lambda x, g=decoding.get: g(x, ' '), message.split(' '))) | |
return ' '.join(ans.split()) | |
def replace(match): | |
return replacements[match.group(0)] | |
print '---------------------' | |
print "GC49MWD Solver by ryz" | |
print '---------------------' | |
print '' | |
for index, paragraph in enumerate(paragraphs): | |
print 'Paragraph #', index+1 | |
print '' | |
print "Source text:" | |
print paragraph | |
print '' | |
print "Morse code:" | |
paragraph1Morse = re.sub('|'.join(r'%s' % re.escape(s) for s in replacements), replace, paragraph) | |
print paragraph1Morse | |
print '' | |
print "Decoded morse:" | |
paragraph1Decoded = decodeMorse(paragraph1Morse) | |
print paragraph1Decoded | |
print '' | |
print "ROT13 decode:" | |
print codecs.decode(paragraph1Decoded, 'rot13') | |
print '' | |
print '-------------' | |
print '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment