Encryption with Python?
Anthra Norell
anthra.norell at tiscalinet.ch
Sat May 7 04:07:50 EDT 2005
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.
Frederic
###
def crypt (sequence, key):
import random
sign = (key > 0) * 2 - 1
random.seed (abs (key * sign))
s = ''
for i in xrange (len (sequence)):
r = random.randint (0, 255)
s += chr ((ord (sequence [i]) + r * sign) % 256)
return s
###
If unauthrorized use of the machine is a concern, crypt might not be an
appropriate name for the function. To help an intruder understand it, a doc
string such as the following one might be useful:
def cyrep (sequence, key):
"""
Cyclic Redundancy Preprocessor
Cyclic redundancy checks often fail to differentiate relatively
short
sequences that contain sequences of binary zeroes of different
length.
This preporcessor applies a keyed randomizing filter to improve the
capability of the cyclic redundancy algorithm. Use the output of
this
function as input to a CRC routine.
Negative keys cannot be used. If passed they are positivized
rather
than rejected.
"""
###
----- Original Message -----
From: "Blake T. Garretson" <blake.garretson at gmail.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, May 05, 2005 10:20 PM
Subject: Encryption with Python?
> I want to save some sensitive data (passwords, PIN numbers, etc.) to
> disk in a secure manner in one of my programs. What is the
> easiest/best way to accomplish strong file encryption in Python? Any
> modern block cipher will do: AES, Blowfish, etc. I'm not looking for
> public key stuff; I just want to provide a pass-phrase.
>
> I found a few modules out there, but they seem to be all but abandoned.
> Most seem to have died several years ago. The most promising package
> is A.M. Kuchling's Python Cryptography Toolkit
> (http://www.amk.ca/python/code/crypto.html).
>
> Is this the defacto Python encryption solution? What does everyone
> else use? Any other suggestions? The SSLCrypto package
> (http://www.freenet.org.nz/python/SSLCrypto/) may be a good alternative
> too, but I am not sure if it is actively maintained.
>
> Thanks,
> Blake
>
> --
> http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list