Created
October 12, 2013 06:21
-
-
Save DomNomNom/6946442 to your computer and use it in GitHub Desktop.
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 collections | |
from contextlib import contextmanager | |
import sys | |
cypherText = '''HSCDIYCDXWSCWIYGYCHCWLRCOXGSC | |
BHKYACLCMLSCWIXCRLHBYACDXCRYLC | |
LSACIYCDXBACFRCXTCIHRCBHTYC | |
HSCDIYCBLSACXTCRFOMLGHSYR | |
''' | |
# C has to be separate because of trailing space culling | |
subsitutions = 'C ' + ''' | |
HI | |
LA | |
DT | |
IH | |
YE | |
XO | |
OB | |
GR | |
RS | |
WW | |
BL | |
AD | |
TF''' | |
# KV | |
# MM | |
# FU | |
#SN''' | |
sub = { k:v for k,v in subsitutions.split('\n') } | |
assert len(sub) == len(set(sub.values())), 'not a 1-1 mapping' | |
p = sys.stdout.write # shorthand for print (without spacing) | |
@contextmanager | |
def printcolour(colour): | |
p('\033[{0}m'.format(colour)) | |
yield | |
p('\033[m') | |
for c in cypherText: | |
if c in sub: | |
with printcolour(93): | |
p(sub[c]) | |
else: | |
p(c) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment