Encryption with Python?

Anthra Norell anthra.norell at tiscalinet.ch
Tue May 24 04:16:15 EDT 2005


I wasn't going to pursue this any further. Actually, I am quite disappointed
about the belligerent style of some correspondents. It's not necessary. It
spoils the fun. It cloggs bandwidth.
   Why whack someone over the head who tries to develop an idea of his own.
Such an approach isn't uncommon to earn extra credit in educational
settings.
   True, I have also been offered good advice and being able to extract it
from between insuslts I have expressed my appreciation for it. In return of
the favor I offer a little anecdote about the nature of creativeness.
   The connection between candor and creativeness has always fascinated me.
At some point, almost thirty years ago, I came across an article in a hang
glider magazine by one Dr. Paul MacCready who had just won the Kremer Prize
with his human-powered Gossamer Condor, a prize that had been standing for
decades despite innumerable unsuccessful attempts to win it. In that article
MacCready explained that it was the advent of hang gliders that gave him the
idea to go for the Kremer prize. Namely, he immediately realized that hang
gliders dissipated less energy in stable flight than any other aircraft in
existence, not because the flew so well--they didn't--but because of their
low weight. He calculated that a twenty-kilogram hang glider with a wing
span of close to thirty meters would dissipate no more than one third of a
horse power or thereabout and that is an amount of energy a competition
cyclist generates over the course of a race.
    After winning the prize, MacCready challenged himself to fly across the
English channel and started building an improved second version of his
airplane. Passing through Los Angeles I went to see the project in a Long
Beach hangar and took the opportunity to pick MacCready's brain for the
benefit of our own magazine. Referring to his article I confessed my
surprise that a scientist of his caliber would be inspried by such crude
aeronautical engineering hacks as hang gliders unquestionably were. His
reply was this:
    "I also consider myself an amateur. I have a PhD in aeronautics, but not
in aeronautical engineering. But this just might have been my advantage. All
these many previous failed attempts had been made by people with better
engineering credentials. If their conception of possible solutions was
better defined, it was probably also more constrained by their knowledge of
what an airplane is supposed to be."
    We went on talking about creativeness and MacCready's conclusion still
rings in my ears: "Our education system encourages us to be critical. This
is a great pity. It reinforces our habit to focus on other people's
weaknesses and failures, when we could learn from observing their
strengths."

Frederic

(Robert Kern could have embarrassed me with a plain-text attack, although
his bounty wouldn't have been my credit card details. I tought about
plain-text attacks and found that in addition to changing the values of
bytes I also needed to shuffle them a little. So I added a few lines,
encoded my credit card details and here it is, program, credit card details,
everything but the key.)

1. The credit card details:

string =
'\x84ue\x8d\xec\x98\x02\xba<n\t\xc6\xa6\xd2\xcc\xe4O\x11\xd7\xf5\xe7\x9c\xed
*\x05\x1e\xb3h\x97V\xf8\x9a"%\xec\x14\x03r\xdd\xda\x18\xc0\x9fc\x04&J\xefF\x
cd\xbc\x81\xad\xfe\xb4SV\x1a7[l\x12\xfd\xc9w\xc3u\xf4\x83tK\x1e]{\xf5/\xbfJ\
x8a\xde\x18\xc2jj\xe8er\x10\x99\x1e\xeb\xa3\x86\xf0f\xb9\x95\xb5\xd8\xaaY\x0
8\xb8\xcdf.'

2. The decoding program

def cyrep (string, key):

   """To encrypt use a numeric value as the key. To decrypt use the negative
value of the same number."""

   import random

   CHUNK  = 32

   def process_sequence (sequence):
      s = ''
      for i in xrange (len (sequence)):
         r = random.randint (0, 255)
         s += chr ((ord (sequence [i]) + r * sign) % 256)
      return s

   def preprocess_sequence (sequence):
      random.shuffle (sequence)
      return sequence

   sign = (key > 0) * 2 - 1
   random.seed (abs (key * sign))

   i = 0
   s = ''

   if sign > 0:
      while i < len (string):
         chunk = random.randint (0, CHUNK)
         s_ = preprocess_sequence (list (string [i:i+chunk]))
         s += ''.join (process_sequence (s_))
         i += len (s_)

   else:
      while i < len (string):
         chunk = random.randint (0, CHUNK)
         s_ = list (string [i:i+chunk])
         l = len (s_)
         l_ = range (l)
         s__ = l * [None]
         o  = preprocess_sequence (l_)
         s_ = process_sequence (s_)
         for ii in l_:
            s__ [o[ii]] = s_ [ii]
         s += ''.join (s__)
         i += l

   return s



----- Original Message -----
From: "Christos TZOTZIOY Georgiou" <tzot at sil-tec.gr>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Friday, May 13, 2005 11:06 AM
Subject: Re: Encryption with Python?


> On Sat, 7 May 2005 13:51:40 +0200, rumours say that "Anthra Norell"
> <anthra.norell at tiscalinet.ch> might have written:
>
> >Here's the challenge. Prove this breakable
> >
>
>'\x10\x88d\x1d\xba\xa1\xdcK\x05w\x02/s\xa7Q0\xeb8\xb6Gx\xef\xcb\x1e=\xf5\x7
f
>
>\x9bI\xcb(\x87>\xa5\x04\xc1soF\xfd\xc6\xc6\xd9|\x971\xdb\xcdT\tw#\x86a\xdc\
x
>
>b8P\xfb=n\xda\x80\x9f\x84m\x12\x98\x98\xca=o\x0b\x8e\x08O\xb7\x0b\x04SC\x96
\
>
>xc7\xab*\x0b\x996\x06\x86\x83(\x8dQ\x9eG\x8f$\xb2x)\xa9fv\x0c1B\x9b\r\xde\x
f
> >fc\x08'
>
> and given that
>
> >I rolled my own for relatively short sequences, like passwords. The key
is
> >an integer. To decrypt use the negative encryption key. I consider the
> >encryption unbreakable, as it is indistinguishable from a random
sequence.
>
> can we suppose that the encrypted text above are the details of your
> credit card (number, name as written on it, expiry date, billing address
> and your first dog's name)?  Do you trust the 'unbreakability' of your
> algorithm that much?
> --
> TZOTZIOY, I speak England very best.
> "Be strict when sending and tolerant when receiving." (from RFC1958)
> I really should keep that in mind when talking with people, actually...
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list