[Edu-sig] More lesson planning...
kirby urner
kirby.urner at gmail.com
Wed Oct 3 20:06:26 CEST 2007
My thanks to the coffee clutch mathematicians [1] for
inspiring lesson plans around L337.[2]
You might think writing a decrypter would be easy,
but I'm showing below why the simply one-for-one
letter substitution idea won't work. I'd hesitate to
use regular expressions. The idea of tokenizing, a
subclass of parsing, rears its (not so ugly) head.
So the code below, while perhaps motivational, is
not (repeat not) a solution, as the test code clearly
proves.
Kirby
[1] http://mathforum.org/kb/thread.jspa?threadID=1628625&tstart=0
[2] http://www.urbandictionary.com/define.php?term=L337
====
# -*- coding: cp1252 -*-
L337 = dict(
A='4',
B='B',
C='(',
D='|',
E='3',
F='Ph',
G='6',
H='(-)',
I='1',
J='j',
K='K',
L='!',
M='/\\/\\', # escaping \
N='/\\/',
O='Ø',
P='P',
Q='Q',
R='r',
S='$',
T='7',
U='()',
V='\/',
W='\/\/',
X='xx',
Y='¥',
Z='Z')
def reverse_dict(anydict):
newdict = {}
for thekey in anydict:
newdict[anydict[thekey]] = thekey
return newdict
rev_L337 = reverse_dict(L337)
def decrypt(c, permuter):
p = []
for letter in c:
p.append(permuter.get(letter,letter))
return ''.join(p)
def test():
# NOTE: the test fails
print decrypt('641|_ +|-|4<|<3|2y 5|_|x0|25.', rev_L337)
if __name__ == '__main__':
test()
More information about the Edu-sig
mailing list