Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Custom function, hashlib and base64 in python

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report