0

Decrypting and encrypting string in python using module in lib . easiest way to do it

import hashlib
a="abcd"
a = hashlib.sha224(a)
z=a.hexdigest()

print  p

now I want to decrypt that string which I entered before..

2 Answers2

4

You don't encrypt the string, you hash it. Therefore, it can't be "decrypted" - hashes are meant to be one way functions, i.e. there is no simple way to "calculate" the input from the output.

See e.g. here for more detailed definitions of encrypting and hashing: Difference between Hashing a Password and Encrypting it

Community
  • 1
  • 1
codeling
  • 11,056
  • 4
  • 42
  • 71
  • Oh !! thanks...is there any way of encrypting and decrypting a string – ibrahim haleem khan Jan 13 '14 at 11:10
  • hm searching for that ("python encryption" or similar) on the search engine of your choice should give plenty results... what about this: http://stackoverflow.com/a/16761459/671366 or this: http://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/ ? – codeling Jan 13 '14 at 11:13
3

You are creating a hash of the input string. You can use this hash to check if another input string is the same as the original input string.

You are not supposed to be able to decrypt a hash. That would defeat the whole purpose.

jr-be
  • 128
  • 6