a python puzzle

Gary Herron gherron at islandtraining.com
Wed Sep 25 18:20:19 EDT 2002


On Wednesday 25 September 2002 02:42 pm, 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]
>

I decrypted (building the strings up character by character) with:

   tr hokdrawfezxmylqcubijHpvsIFgt importysngalejufzvchIwxbCSkd < puzzle

and got:

"""
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]



The fact that this puzzle was easy to decrypt says something (good)
about Python: It is so readable, that even encrypted, one can
recognize significant portions.  Imagine decrypting a similar puzzle
in C or, worse yet, Perl!

Dr. Gary Herron





More information about the Python-list mailing list