encryption with python

James Stroud jstroud at mbi.ucla.edu
Thu Sep 8 00:35:07 CEST 2005

On Wednesday 07 September 2005 14:31, jlocc at fau.edu wrote:
> Basically I will like to combine a social security number (9 digits)
> and a birth date (8 digits, could be padded to be 9) and obtain a new
> 'student number'. It would be better if the original numbers can't be
> traced back, they will be kept in a database anyways. Hope this is a
> bit more specific, thanks!!!

Then your best bet is to take a reasonable number of bits from an sha hash. 
But you do not need pycrypto for this. The previous answer by "ncf" is good, 
but use the standard library and take 9 digits to lessen probability for 

import sha
def encrypt(x,y):
    def _dosha(v): return sha.new(str(v)).hexdigest()
    return int(_dosha(_dosha(x)+_dosha(y))[5:13],16)


py> encrypt(843921299,20050906)

Each student ID should be unique until you get a really big class. If your 
class might grow to several million, consider taking more bits of the hash.

Also, as long as you remember the function, you can get back the student ID 
from the birthday and SS, in case they drop out and re-enroll next year.


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


More information about the Python-list mailing list