views:

440

answers:

3

Ofcourse similar questions have been asked in stackoverflow but I dont want to use any third party library like Crypto or something. So I need to generate a code based on user email and decrypt the code to generate the email back. Can I do it in python?

+2  A: 

Yes, you can. Read http://www.amk.ca/python/code/crypto.html You'll find an answer there ;)

You're question is not concrete enough to say more. You may want to read http://en.wikipedia.org/wiki/Cryptography#Modern_cryptography

Cheers, Tuergeist

Update: No, you cannot. (with build in functionality due to export restrictions, see http://docs.python.org/library/crypto.html) But you can, if you're implementing you own algorithm (bad idea). So, the BEST solution is, to use the extension recommended by python core developers. See post above.

Cheers again.

tuergeist
I dont want to use any third party library. PyCrypto is one such thing right!
Maddy
I added some new facts.
tuergeist
+2  A: 

A third-party system is your best bet.
If you really can't/don't want to use a third-party, maybe something simple would suffice.

One of the simpler algorithms is the Tiny Encryption Algorithm (TEA). Here's an example of a Python implementation that you could start with.

jcoon
A: 

If what you mean is that you want to roll your own encryption system, you could try using the built-in hmac and hashlib modules. (hashlib is new for 2.5, so if you must use an earlier Python, your hash choices are the older md5 and sha modules.)

If you are opposed to installing a third-party library but are OK with using third-party algorithms or even "lightweight" third-party implementations of algorithms (e.g. published Python source code which resides in a single .py file that you can incorporate or import yourself without using setup.py or other formal installation), then I highly recommend you do so.

The smallest and user-friendliest of these that I am aware of is p3.py by Paul Rubin. You could also try using rijndael.py, which is an implementation of the AES algorithm.

John Y