Skip to content

Instantly share code, notes, and snippets.

@DomNomNom
Created October 12, 2013 06:21
Show Gist options
  • Save DomNomNom/6946442 to your computer and use it in GitHub Desktop.
Save DomNomNom/6946442 to your computer and use it in GitHub Desktop.
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