Python learning Experience (v) random generation of CAPTCHA, MD5 encryption, pickle and JSON serialization and deserialization

Source: Internet
Author: User
Tags md5 encryption

Tag:load    Verification Code    utf-8   pytho   int     Default     data     memory    and   

#-*-Coding:utf-8-*-import Random as Rd #验证码import Hashlib as HSL #MD5加密import pickle,json #pickle与json序列化 #print Rd.rand        int (1,5) #print Help (range) #print Help (Rd.randint) #随机生成6位验证码: code = []for i in Range (1,7): if i = = Rd.randint (1,6): Code.append (str (i)) Else:code.append (Chr (Rd.randint (65,90)) print '. Join (code) #MD5加密, cannot be reversed, real  MD5 () positive solution matches Hashtest = HSL.MD5 () hashtest.update (' admin ') print hashtest.hexdigest () when verifying that the user is logged in () #pickle序列化与反序列化  And the difference between the JSON and the "" "Pickle and Json1.pickle is dedicated to Python, JSON is supported in almost all programming languages, and data memory interactions between different languages are the same for JSON-based 2.pickle and JSON in Python, pickle basically all data types in Python can be serialized JSON can only serialize regular lists, dictionaries, etc. 3.pickle serialized data is not readable by default (artificially indistinguishable), but JSON serialization can be visualized (readable) "" "Dict_pick = {' name ': ' Binguo ', ' age ': 27, ' Blogurl ': ' http://blog.csdn.net/binguo168 '}dict_json = {' Company ': ' China ', ' hobby ': ' study '} #序列化result1 = Pickle.dumps (dict_pick) result2 = Json.dumps (dict_json) Print result1print Result2with open (' E:/pickleresult.txt ', ' W ' ) as File_pickle:pickle.dump (Dict_pick, File_picKle) #序列化到文件with file (' E:/pickleresult.txt ', ' R ') as Read_pickle:print pickle.load (read_pickle) #从文件反序列化回来 #反序列化prin T pickle.loads (RESULT1) print json.loads (RESULT2)

  

Python learning Experience (v) random generation of CAPTCHA, MD5 encryption, pickle and JSON serialization and deserialization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.