Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a python puzzle

18 views
Skip to first unread message

Michal Wallace

unread,
Sep 25, 2002, 5:42:40 PM9/25/02
to


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]

Cheers,

- Michal http://www.sabren.net/ sab...@manifestation.com
------------------------------------------------------------
Switch to Cornerhost! http://www.cornerhost.com/
Low Priced, Reliable Blog Hosting, With a Human Touch. :)
------------------------------------------------------------


Brad Clements

unread,
Sep 25, 2002, 6:33:17 PM9/25/02
to
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]

--
Novell DeveloperNet Sysop #5

_
"Michal Wallace" <sab...@manifestation.com> wrote in message
news:mailman.1032989974...@python.org...


-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----

Erik Max Francis

unread,
Sep 25, 2002, 6:43:06 PM9/25/02
to
Michal Wallace wrote:

> Here's a python puzzle. Solve it and you win a prize. :)

tr hokdrafwfezxtculyjqmbipsvHIFg importsysngadfzjehulvcwbxICSk

I started by decoding the (obvious) Python source, which made the job
considerably easier.

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ Seriousness is the only refuge of the shallow.
\__/ Oscar Wilde
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.

holger krekel

unread,
Sep 25, 2002, 6:03:15 PM9/25/02
to
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

Gary Herron

unread,
Sep 25, 2002, 6:20:19 PM9/25/02
to
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


Michal Wallace

unread,
Sep 25, 2002, 6:21:56 PM9/25/02
to
On Thu, 26 Sep 2002, holger krekel wrote:

> 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?


Hi Holger,

Yep, that's it! I figured it would be easy to solve -
especially given the python code, but I didn't expect a
solution THAT quick. Next time I'm using RSA!

> but i don't know if i need free webhosting :-)

Hahaha. Well, if you change your mind, just let me know. :)

Andy Salnikov

unread,
Sep 25, 2002, 7:26:01 PM9/25/02
to

"Gary Herron" <ghe...@islandtraining.com> wrote in message
news:mailman.103299249...@python.org...

> On Wednesday 25 September 2002 02:42 pm, Michal Wallace wrote:
> > Here's a python puzzle. Solve it and you win a prize. :)
> >
>
> I decrypted (building the strings up character by character) with:
>
> tr hokdrawfezxmylqcubijHpvsIFgt importysngalejufzvchIwxbCSkd < puzzle
>
> and got:
>
>
> 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!
>

C'mon, "the fact that this puzzle was easy to decrypt says" that
"encription" was really trivial. Indeed the most "important" spaces,
and non-alpha characters were not encripted at all. With such
simple encription you'll be able as easily decrypt C and Perl (or
any English text of suffitient length)

Cheers,
Andy.


holger krekel

unread,
Sep 25, 2002, 7:15:34 PM9/25/02
to
Michal Wallace wrote:
> On Thu, 26 Sep 2002, holger krekel wrote:
>
> > 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?
>
>
> Hi Holger,
>
> Yep, that's it! I figured it would be easy to solve -
> especially given the python code, but I didn't expect a
> solution THAT quick. Next time I'm using RSA!

No problem :-)

Just letting out the python code would make it a bit harder.
One might even have to start to seriously program ...

> > but i don't know if i need free webhosting :-)
>
> Hahaha. Well, if you change your mind, just let me know. :)

cheers,

holger

Chad Netzer

unread,
Sep 25, 2002, 7:58:01 PM9/25/02
to
On Wednesday 25 September 2002 16:26, Andy Salnikov wrote:
> "Gary Herron" <ghe...@islandtraining.com> wrote in message

> > The fact that this puzzle was easy to decrypt says something (good)
> > about Python:
>


> C'mon, "the fact that this puzzle was easy to decrypt says" that
> "encription" was really trivial.

Yes, it was meant to be easy, because it is basically a slightly
disguised SPAM message. There was nothing "pythonic" about this puzzle
at all, except a rather routine piece of code. If I has bothered to
'decrypt' it, I would be pissed. (Reminds me of little Ralphie, in "A
Christmas Story", waiting weeks to get his secret decoder wheel, only
to find the secret message is 'Be sure to drink your Ovaltine')

--

Chad Netzer
cne...@mail.arc.nasa.gov

Delaney, Timothy

unread,
Sep 25, 2002, 8:09:52 PM9/25/02
to
> From: Erik Max Francis [mailto:m...@alcyone.com]

>
> Michal Wallace wrote:
>
> > Here's a python puzzle. Solve it and you win a prize. :)
>
> tr hokdrafwfezxtculyjqmbipsvHIFg importsysngadfzjehulvcwbxICSk
>
> I started by decoding the (obvious) Python source, which made the job
> considerably easier.

Trivially easy in fact - since it's just a substitution cypher, you've
already got a lot of information just from the first line of python code -
the first line obviously starts as

import sys

and

cdr kmxhe, irwka he uhk(farhez.myaayrf, ihkjyr):

^^^ ^^

is trivially

for kmxhe, irwka in uhk(farhez.myaayrf, ihkjyr):
^^^ ^^

which gives you a few more letters. In fact, by that stage you already have
12 out of 26 characters.

I suspect it took Holger somewhat less than half an hour to solve ... 5
minutes at most, and most of that is writing the decryption code ;)

Tim Delaney

Lulu of the Lotus-Eaters

unread,
Sep 25, 2002, 8:57:06 PM9/25/02
to
I think the various responders did this "by hand." Probably having the
Python source code made it even easier to just eyeball. In a more
general sense (just in case anyone doesn't know), the way to solve a
Caesar cipher like this is to start counting letter frequencies.
Comparing the frequencies to well-known English letter frequencies like:

http://gnosis.cx/download/letterfrequency.gif

lets you start matching letters pretty quickly. Of course, if you don't
know it's English, the frequency table isn't as accurate.

I was thinking of writing a little solver script to actually assign
likely permutations based on the frequencies. But a dozen people had
already solved it before I saw the problem... so I gave up on that :-).

Yours, Lulu...

--
Keeping medicines from the bloodstreams of the sick; food from the bellies of
the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.

Erik Max Francis

unread,
Sep 25, 2002, 11:50:37 PM9/25/02
to
"Delaney, Timothy" wrote:

> I suspect it took Holger somewhat less than half an hour to solve ...
> 5
> minutes at most, and most of that is writing the decryption code ;)

It only took two or three minutes for me to solve with an emacs window
open and tr on an interactive shell.

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE

/ \ Gods are born and die, but the atom endures.
\__/ Alexander Chase
Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
A new, virtual planet, every day.

Erik Max Francis

unread,
Sep 25, 2002, 11:53:51 PM9/25/02
to
Lulu of the Lotus-Eaters wrote:

> I think the various responders did this "by hand." Probably having
> the
> Python source code made it even easier to just eyeball. In a more
> general sense (just in case anyone doesn't know), the way to solve a
> Caesar cipher like this is to start counting letter frequencies.
> Comparing the frequencies to well-known English letter frequencies
> like:
>
> http://gnosis.cx/download/letterfrequency.gif
>
> lets you start matching letters pretty quickly. Of course, if you
> don't
> know it's English, the frequency table isn't as accurate.

This wouldn't have worked as well here, since the encrypted text was so
short; furthermore, the fact that it was mostly Python code would have
likely skewed the letter frequencies, since Python keywords, modules,
and builtin names appear more frequently in Python code than general
user-chosen identifiers; the letter frequency of the code would be
biased against the letter frequency of the common "words" in Python,
which is likely to be somewhat different from English as a whole.

Lulu of the Lotus-Eaters

unread,
Sep 26, 2002, 12:20:33 AM9/26/02
to
|the fact that it was mostly Python code would have
|likely skewed the letter frequencies, since Python keywords, modules,
|and builtin names appear more frequently in Python code than general
|user-chosen identifiers; the letter frequency of the code would be
|biased against the letter frequency of the common "words" in Python,
|which is likely to be somewhat different from English as a whole.

I wonder about that. Python reserved words (and pseudo-reserved names)
are all rather ordinary English words. I have a hunch that their letter
distribution falls pretty close to that of English prose.

Of course, you'd have to decide how to weight things. If you merely did
a histogram on a list of keywords, you might get a somewhat different
pattern than if you checked actual scripts (with the comments and
variable names removed). For example, most scripts have just a few
'import's at the top, but a whole bunch of 'if's 'for's and 'in's
scattered throughout the body.

Maybe I'll try an experiment.

Yours, Lulu...

--
---[ to our friends at TLAs (spread the word) ]--------------------------
Echelon North Korea Nazi cracking spy smuggle Columbia fissionable Stego
White Water strategic Clinton Delta Force militia TEMPEST Libya Mossad
---[ Postmodern Enterprises <me...@gnosis.cx> ]--------------------------


Matt Gerrans

unread,
Sep 26, 2002, 1:31:01 AM9/26/02
to
> Keeping medicines from the bloodstreams of the sick; food from the bellies
of
> the hungry; books from the hands of the uneducated; technology from the
> underdeveloped; and putting advocates of freedom in prisons. Intellectual
> property is to the 21st century what the slave trade was to the 16th.

Good quote! (Although, unfortunately -- and perhaps more so, if it's a
predictor for "intellectual property" -- slave trade persisted long past the
16th century).


Brad Clements

unread,
Sep 26, 2002, 5:32:30 PM9/26/02
to
_
"Chad Netzer" <cne...@mail.arc.nasa.gov> wrote in message > at all, except
a rather

> routine piece of code. If I has bothered to
> 'decrypt' it, I would be pissed. (Reminds me of little Ralphie, in "A
> Christmas Story", waiting weeks to get his secret decoder wheel, only
> to find the secret message is 'Be sure to drink your Ovaltine')

Ha ha ha, love that movie.

"You'll shoot your eye out kid!"

(and I did decrypt it.. not pissed, it was only a 3 minute job)

David Brown

unread,
Sep 27, 2002, 8:21:51 AM9/27/02
to
I'm not too interested in the crypogram puzzle, but your solution here has
just given me a solution to something that has been bugging me for some
time - finding an easy way to convert a list of characters into a string:

>>> a = "Hello"
>>> b = [x for x in a]
>>> b
['H', 'e', 'l', 'l', 'o']
>>> "".join(b)
'Hello'
>>>

Thanks !

Terry Reedy

unread,
Sep 27, 2002, 8:48:55 AM9/27/02
to

"David Brown" <da...@no.westcontrol.spam.com> wrote in message
news:an1i31$1r3$1...@news.netpower.no...

> I'm not too interested in the crypogram puzzle, but your solution
here has
> just given me a solution to something that has been bugging me for
some
> time - finding an easy way to convert a list of characters into a
string:
>
> >>> a = "Hello"
> >>> b = [x for x in a]

or
>>> list(a)


['H', 'e', 'l', 'l', 'o']

which is probably faster

> >>> "".join(b)
> 'Hello'


0 new messages