Example Analysis of Custom function, hashlib and base64 in python
This article mainly introduces the custom function in python, hashlib, base64 example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
I. Custom function
1.1 Code
File: abc.py
#! / usr/bin/env pythondef add (Xero4): return x+xprint add () print add (3.6) print add ("hello")
II. Md5 encryption, base64 encryption / decryption
2.1 introduction to hashlib
Hashlib is a library that specializes in hashing algorithms, which now includes md5, sha1, sha224, sha256, sha384, sha512, which is very easy to use and convenient for you.
Md5 is often used to store users' passwords.
Sha1 is often used as a digital signature.
2.2 Code
File: test.py
#! / usr/bin/env python#md5, sha1, sha224, sha256, sha384 Sha512import hashlibstr= "abcde" m=hashlib.md5 () m.update (str) print m.hexdigest () print hashlib.md5 (str). Hexdigest () print hashlib.sha1 (str). Hexdigest () print hashlib.sha224 (str). Hexdigest () print hashlib.sha256 (str). Hexdigest () print hashlib.sha384 (str). Hexdigest () print hashlib.sha512 (str). Hexdigest () print "# base64import base64str=" abcde "encoded = base64.b64encode (str) decoded = base64.b64decode (encoded) print encodedprint decoded thank you for reading this article carefully. I hope the article "Custom functions in python, sample Analysis of hashlib and base64" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!