Skip to content

Instantly share code, notes, and snippets.

@AnimeshShaw
Last active August 29, 2015 13:56
Show Gist options
  • Save AnimeshShaw/52f931e572171b6e4a56 to your computer and use it in GitHub Desktop.
Save AnimeshShaw/52f931e572171b6e4a56 to your computer and use it in GitHub Desktop.
import hashlib
"""
Encrypts given string
Method: md5, sha1, sha224, sha256, sha384, sha512
Supports: Salts
How to use: encrypt('password', 'sha512', '04/16/2010')
"""
def encrypt(String, Method='md5', Salt=None):
if Method not in ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']:
print 'Unknown encryption'
else:
if Salt == None:
command = "print hashlib.%s('%s').hexdigest()" % (Method, String)
exec command
else:
command = "print hashlib.%s('%s' + '%s').hexdigest()" %(Method, String, Salt)
exec command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment