Simple encryption proposal. Comments ?
Paul Rubin
phr-n2002b at NOSPAMnightsong.com
Thu Jan 2 09:53:45 EST 2003
> ># _test2() # depends on secrand.py module, not included
> ^^^^^^^^^^^^
> We seem to a chain going ;-) Google doesn't ... Um, where might one ...
Secrand is used only by one of the testing functions, so it's not
needed to use that base52 module. It's *nix-specific since it reads
bytes from /dev/urandom. But here it is:
# ===== secrand.py ========================================================
# Secure random number generator
# Copyright 2001 Paul Rubin, Fort GNOX Cryptography
# Copying permissions: GNU General Public License version 2.
# $Id: secrand.py,v 1.1 2002/12/20 19:42:02 phr Exp phr $
class _secrand:
def __init__(self):
self.__f = open("/dev/urandom")
def getbytes(self,nbytes):
return self.__f.read(nbytes)
def gethex(self,nbytes):
import binascii
return binascii.hexlify(self.getbytes(nbytes))
def getlong(self,nbytes):
return long(self.gethex(nbytes), 16)
def getstring(self,nbytes):
import base64
x = base64.encodestring(self.getbytes(nbytes))
# chop newline and trailing '=' signs
x = x[:-(-nbytes%3)-1]
return x
secrand = _secrand()
More information about the Python-list
mailing list