Encryption with Python?

  • Thread starter Blake T. Garretson
  • Start date
A

Anthra Norell

---- Original Message -----
From: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Tuesday, May 10, 2005 12:59 AM
Subject: Re: Encryption with Python?
......
Since good encryption schemes that don't have significant performance
penalties are widely available, why mess with a crap scheme EVER? Why
use a solution that "might or might not be adequate" when you can use
one that's definitely ok?
......

Why indeed?---Why run a marathon? Why have kids? Why shave? Why play chess?
Why sprinkle the lawn? Or as my friend Sergio's favorite line went: Why you
jerks cook your own muck when there are so many good restaurants in town?

His was definitely the best when it went out of business.

Regards

Frederic
 
P

Peter Hansen

Anthra said:
Why indeed?---Why run a marathon?

To demonstrate your physical supremacy over your inferiors.
Why have kids?

Because you forgot to wear protection.
Why shave?

Your wife insists? Mine does...
> Why play chess?

To demonstrate your intellectual supremacy over your inferiors.
Why sprinkle the lawn?

Too much beer and there's a line-up to use the john?
Or as my friend Sergio's favorite line went: Why you
jerks cook your own muck when there are so many good restaurants in town?

To demonstrate your culinary supremacy over your inferiors?
His was definitely the best when it went out of business.

(Hmm... so is my business doing merely "well" if it's losing money?)

Back to Paul's question then: why use an unreliable and
probably-useless-for-all-but-spawning-lengthy-but-educational-threads
encryption method when there are relatively reliable and, uh, less
discussed and non-edifying, uh... well, you get the picture. ;-)

-Peter
 
R

Robert Kern

Peter said:
Back to Paul's question then: why use an unreliable and
probably-useless-for-all-but-spawning-lengthy-but-educational-threads
encryption method when there are relatively reliable and, uh, less
discussed and non-edifying, uh... well, you get the picture. ;-)

Well, I'd say ARCFOUR has been discussed a hell of a lot more than what
this thread ever mustered up. I also submit that implementing ARCFOUR or
studying p3.py would be a hell of a lot more educational than posting a
lousy algorithm, calling it unbreakable, and responding to criticisms
with "I don't understand so you must be wrong."

Education is a process one must engage in. You don't just step in it.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

Peter Hansen

Robert said:
Well, I'd say ARCFOUR has been discussed a hell of a lot more than what
this thread ever mustered up. I also submit that implementing ARCFOUR or
studying p3.py would be a hell of a lot more educational than posting a
lousy algorithm, calling it unbreakable, and responding to criticisms
with "I don't understand so you must be wrong."

Education is a process one must engage in. You don't just step in it.

The education to which I was referring was that which _most_ of us just
received by reading Paul's and your replies, not from anything in the
OP's postings. ;-)

-Peter
 
R

Robert Kern

Peter said:
The education to which I was referring was that which _most_ of us just
received by reading Paul's and your replies, not from anything in the
OP's postings. ;-)

Okay, I'll buy that. :)

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
C

Christos TZOTZIOY Georgiou

Here's the challenge. Prove this breakable

'\x10\x88d\x1d\xba\xa1\xdcK\x05w\x02/s\xa7Q0\xeb8\xb6Gx\xef\xcb\x1e=\xf5\x7f
\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\xf
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?
 
H

hemanth

Anthra said:
Thanks a lot for the feedback. This is certainly a great learning
experience. It's a fascinating topic too. Without wishing to annoy, I'd be
interested in knowing more. I insert questions below.

You can google your questions and you will find them out answered in
many
cryptography FAQs. For a less mathematical, but entertaining treatise
on
cryptography, read Simon Singh's "The Code Book". You will definitely
appreciate how the various crypto algorithms through the history of
mankind
were broken and what is the state of the art in the field.
 
A

Anthra Norell

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 ) + 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" <[email protected]>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Friday, May 13, 2005 11:06 AM
Subject: Re: Encryption with Python?
 
J

James Stroud

For your own good, please change your credit card number now! You have
obviously lost your mind. Please read Applied Cryptography if you are
wondering why I would say this. I am not trying to be mean.

For example:

I have access to 80 Pentium 3 cpus (at ~1.8 GHz) and have engineered a simple
brute force on this (in pure python) that can check 2**31 integers overnight.
I timed it. I used absolutely NO optimization. Also, beyond these 2**31
integers, I stopped trying because I have other things to do--I had no
incentive. Now your credit card info is on the line. I'm a rank ammy and I'm
sure a skilled programmer could speed it up 100 to 1000 fold (1000 ~ 2**10).
Also, this was for your first message about which I knew positively nothing.
You have made the job now several times easier (lets say 10 ~ 2**3) by
disclosing the nature of the plain text. If you think that there are lots of
"keys" that map some part of your cipher text to a set of 16 numbers (+/-)
separators, you are right. But they would be some small fraction of the total
keyspace. 10**6 such keys could be stored easily and so second and later
rounds of analysis would be trivial.

So lets do some math. Say someone had the same computing power as I do. Say,
we could start with 2**32 keys in 24 hours or 1 day. Now lets say they are a
good programmer: 2**32 * 2**10 keys/day. Now lets say they take full
advantage of knowing the nature of the plain text: 3**32 * 2**10 * 2**3. Lets
say they put 2 weeks of computing time into it: 14 days ~ 2**4 days.

Of course both + and - integers are possible, so we'll divide our final answer
by 2 later.

So, say you had a highly motivated, reasonably adept programmer whose lack of
cryptanalysis knowledge limited himself to brute force--but he had a lot of
computers and 2 weeks to work with--and was checking both + and - integers:

2**(32+10+3+4-1) = 281474976710656

That's 15 digits. That is a telephone number (with area code) and a 5 digit
zip. That's 2 birthdays, easy. That is easily the hash of any hashable python
object (only 2**32 possibilities for these). Do you get the point? Basically,
these 15 digits are about the limit of any managable key.

Now, lets say you have someone skilled at cryptanalysis. Well, they are
probably already trying to figure out what they want to buy first. Normally I
wouldn't warn you of this, but I am positively certain that someone smarter
than me will be spending on your credit card and I want to spoil their
holiday.

James


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\xe
d
*\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\x
0 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 ) + 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" <[email protected]>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Friday, May 13, 2005 11:06 AM
Subject: Re: Encryption with Python?
f


x


\


f


and given that

is

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?


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
D

Dennis Lee Bieber

Also, this was for your first message about which I knew positively nothing.
You have made the job now several times easier (lets say 10 ~ 2**3) by
disclosing the nature of the plain text. If you think that there are lots of
"keys" that map some part of your cipher text to a set of 16 numbers (+/-)
separators, you are right. But they would be some small fraction of the total
keyspace. 10**6 such keys could be stored easily and so second and later
rounds of analysis would be trivial.
Don't forget that the first digit of a credit card number
identifies the type of the card -- VISA begins with a 4, MasterCard with
a 5, etc.; and also, as I recall, the last digit is computed as a
checksum of the others.

--
 
C

Christos TZOTZIOY Georgiou

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.

I would never whack someone over the head (WSOTH) who tries to develop
an idea of his own, and never will (intentionally at least --I myself
like reinventing the wheel once in a while just to make sure my synapses
still work). However I do WSOTH for

So, to be clear, my reason was your declaring that "I consider the
encryption unbreakable, as it...", and that is why I actually challenged
you to either support the unbreakability of your algorithm by supplying
sensitive data for you, or back off and simply say "ok guys, my words
were a *little* over the top".

That's all. I see you took up the challenge and indirectly replied to
my last question, and in good spirit I say you earned a little respect
from me, at least for standing up to your words. Now I hope no-one
gives a try to your data (for your own sake :)
 
P

Paul Rubin

Christos "TZOTZIOY" Georgiou said:
That's all. I see you took up the challenge and indirectly replied to
my last question, and in good spirit I say you earned a little respect
from me, at least for standing up to your words. Now I hope no-one
gives a try to your data (for your own sake :)

I don't think the challenge was really accepted. The algorithm
changed between when you issued the challenge, and when the sensitive
data went up. A good algorithm doesn't need to change depending on
the data. I agree with the poster who said that the strength of
either one of the algorithms is irrelevant, if the keyspace is just 32
bits.
 
C

Christos TZOTZIOY Georgiou

I don't think the challenge was really accepted. The algorithm
changed between when you issued the challenge, and when the sensitive
data went up. A good algorithm doesn't need to change depending on
the data. I agree with the poster who said that the strength of
either one of the algorithms is irrelevant, if the keyspace is just 32
bits.

You are correct; the algorithm changed, and the OP admitted it himself
in the post with the encrypted credit card data.

However, on a practical level: before posting, I did a quick comparison,
and the only effective change to OP's algorithm was a the addition of a
`random.shuffle(sequence)', which AFAIU has no practical consequences as
to whether his algorithm is unbreakable or not.

I could say that "hey, you changed the algorithm, and that means your
previous declaration of unbreakability wasn't." but honestly I was
overwhelmed by the audacity (and foolishness, if these are truly his
credit card data) of Frederic.



ObSF: DNA; The Restaurant At The End Of The Universe; Marvin the
paranoid android faces a gigantic black tank in the H2G2 HQ.
 
A

Anthra Norell

Thank you all, James, Dennis, Christos, Paul,

Isn't it remarkable that it takes "foolishness" to earn "a little
respect".
Anyway, even as I write this, my account balance stands unchanged at
.... no, come to think of it, the account balance is definitely not a part of
the problem. I will volunteer the information, though, that the credit card
is a debit card and is good for up to the balance of the account. In
addition, I did contemplate a brute force attack. I also contemplated my
belief that it takes no more than a few lines of code to keep a teraflop
machine busy for a few billion years. So I would not discourage decoding
attempts but will state that the game as I understand it does not have any
implicit rules.

Regards

Frederic

(I am not the OP. The OP was Blake T. Garretson who never returned, but
whose problem I still consider the standard by which I wish my idea to be
judged. I never intended to dabble in commercial cryptography.)


----- Original Message -----
From: "Christos TZOTZIOY Georgiou" <[email protected]>
Newsgroups: comp.lang.python
To: <[email protected]>
Sent: Friday, May 27, 2005 11:52 AM
Subject: Re: Encryption with Python?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top