a python puzzle
holger krekel
pyth at devel.trillke.net
Wed Sep 25 18:03:15 EDT 2002
Michal Wallace wrote:
> Here's a python puzzle. Solve it and you win a prize. :)
>
> """
> Ha'f ahoy ad ayfa wdqr srxhekdpyr! H phmm zhby
> fhv odeajf dc cryy pys jdfahez ad ajy chrfa kyrfde
> ad fdmby ajhf irwkadzrxo. Ixe wdq chzqry ha dqa?
>
> Fheiy wdq jxby axgye ow ijxmmyezy xet tyirwkayt
> ajy fyirya oyffxzy, H phmm ybye zhby wdq ajy
> irwkadzrxo-oxghez fdqriy idty ad xoxuy wdqr
> crhyetf!
> """
> hokdra fwf, farhez, rxetdo
> ihkjyr = mhfa(farhez.myaayrf[:26])
> rxetdo.fjqccmy(ihkjyr)
> ihkjyr = "".ldhe(ihkjyr)
> ihkjyr += ihkjyr.qkkyr()
> oxk = {}
> cdr kmxhe, irwka he uhk(farhez.myaayrf, ihkjyr):
> oxk[kmxhe] = irwka
> cdr mhey he dkye(fwf.xrzb[1]):
> krhea "".ldhe([oxk.zya(ij,ij) cdr ij he mhey])[:-1]
OK. something like
def decrypt(yourstring):
dedict = {'F': 'S', 'I': 'C', 'H': 'I', 'a': 't', 'c': 'f', 'b': 'v', 'e': 'n',
'd': 'o', 'f': 's', 'i': 'c', 'h': 'i', 'k': 'p', 'j': 'h', 'm': 'l',
'l': 'j', 'o': 'm', 'q': 'u', 'p': 'w', 's': 'b', 'u': 'z', 't': 'd',
'w': 'y', 'v': 'x', 'y': 'e', 'x': 'a', 'z': 'g', 'g': 'k'}
return "".join([dedict.get(i,i) for i in yourstring])
returns
"""
It's time to test your brainpower! I will give
six months of free web hosting to the first person
to solve this cryptogram. Can you figure it out?
Since you have taken my challenge and decrypted
the secret message, I will even give you the
cryptogram-making source code to amaze your
friends!
"""
import sys, string, random
cipher = list(string.letters[:26])
random.shuffle(cipher)
cipher = "".join(cipher)
cipher += cipher.upper()
map = {}
for plain, crypt in zip(string.letters, cipher):
map[plain] = crypt
for line in open(sys.argv[1]):
print "".join([map.get(ch,ch) for ch in line])[:-1]
but i don't know if i need free webhosting :-)
regards,
holger
More information about the Python-list
mailing list