[Tutor] Password Program

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Thu Jul 24 19:13:03 2003


On Thu, 24 Jul 2003, R. Alan Monroe wrote:

> > I was wondering if it was possible to have a program in Python ask
> > someone for a user name/password and then encrypt the password, save
> > it to the harddrive, and later, when asked, decrypt the password and
> > tell u what the un/pw is.
>
> I had never looked into this until recently, and I felt really stupid
> for it not having occurred to me. Most sytems encrypt the password in a
> way to where you purposely CAN'T decrypt it. Later, when the user logs
> in, they encrypt whatever the user typed for the password, and compare
> that to the stored encrypted password.
>
> I don't know if there's anything in the stock library that will do
> reversible encryption. Anyone know?


Hi Alan,


There are some trivial ones.  For example, ROT13 --- "rotating" a
character by thirteen places --- is a standard 'encoding' in Python:

###
>>> msg = "This is a test of the emergency broadcast system."
>>> secret = msg.encode('rot13')
>>>
>>> secret
'Guvf vf n grfg bs gur rzretrapl oebnqpnfg flfgrz.'
>>>
>>> secret.encode('rot13')
'This is a test of the emergency broadcast system.'
###


However, I think the Python implementors added it only because it's cute.
Anyone who seriously uses ROT13 to secure secrets should be hung upside
down for a few minutes to bring them to their senses.  *grin*


For doing real encryption, you may want to look at the Python Cryptography
Toolkit:

    http://www.amk.ca/python/code/crypto.html


Hope this helps!