8.10.18 learning Summary

Source: Internet
Author: User

1 """
Hash lib
Hash is an algorithm used to obtain a fixed-length signature based on the calculation of any long data.
Feature: different inputs may have a very low probability of the same result
The same input must get the same result.
Due to the nature of Hash (feature), it is impossible to reverse solve the problem from the principle.

Used to verify whether the two inputs are consistent
Use Cases
1. Password Verification
123321 jahsajshajhsjahjas

After the client is encrypted, The result server obtains the encrypted

2. verify whether the data has been tampered with, for example, whether the game installation package has been modified.


To prevent other users from hitting the database, increase the complexity of the password, and add salt to the password (add some content)
"""


Import hashlib

M = hashlib. MD5 ("AAA". encode ("UTF-8 "))
Print (LEN (M. hexdigest ()))

# How database hit cracking works someone saves the common plaintext and ciphertext mappings to the database in advance
# If you are lucky, you will be able to query
PWDs = {"AAA": "47bce5c74f589f4867dbd57e9ca9f808 "}


H1 = hashlib. sha512 ("123". encode ("UTF-8 "))
H2 = hashlib. sha3_512 ("123". encode ("UTF-8 "))

# Print (LEN (H. hexdigest ()))
Print (h1.hexdigest ())
Print (h2.hexdigest ())

#2b70683ef3fa64572aa50775acc84855

# Adding salt
M = hashlib. MD5 ("321". encode ("UTF-8 "))
# Add
M. Update ("abcdefplkjoujhh". encode ("UTF-8 "))

Print (M. hexdigest ())

Import HMAC
# No difference. Only salt must be added during creation.
H = HMAC. New ("abcdefjjjj". encode ("UTF-8 "))

H. Update ("123". encode ("UTF-8 "))

Print (H. hexdigest ())

2. Check the file Package content in the logging module.
Import Logging

#1. Log Level
# Logging. debug ("this is a debugging information") #10
# Logging.info ("general information") #20
# Logging. Warning ("warning information") #30 # It can be printed directly to the terminal, but the default value is 30.
# Logging. Error ("error message") #40
# Logging. Critical ("severe error") #50
# There are corresponding constants in the logging module used to identify the level
# By default, the default level 30 warning log output location is Console

#2. Custom log Configuration
# Logging. basicconfig (# create a. Log File
# Filename = "A. log ",
# Filemode = "",
# Level = 10,
# Format = "% (asctime) S % (levelname) S % (funcname) S % (lineno) S % (Message) s ",
# Datefmt = "% Y-% m-% d % x % P"
#
#)
# Logging. debug ("this is debugging information again") # files will be written


# Four core roles of the Log Module
"""
1. Logger log Generator
2. Filter
3. Handler Processor
4. formatter format Processor
"""

#1. Create a log Generator
# Mylog = logging. getlogger ("mylog ")
# Set the generator level
# Mylog. setlevel (logging. Debug)
#
#2. Create a log Processor
# FH = logging. filehandler ("B. log", encoding = "UTF-8 ")
#
#3. Create a format Processor
# Fm = logging. formatter (
# "% (Asctime) S % (levelname) S % (funcname) S % (lineno) S % (Message) s ",
# Datefmt = "% Y-% m-% d % x % P ")
#
#4. Associate three objects
# Mylog. addhandler (FH)
# FH. setformatter (FM)
# Test
# Mylog. debug ("mylog test! ")


# Log1 = logging. getlogger ("father ")
# Log2 = logging. getlogger ("father. Son ")
# Log3 = logging. getlogger ("father. Son. Grandson") # If father is removed, only one message is printed if the parent set is not found.
#
# The default value is true, indicating that there is an inheritance relationship. When a sub-log generates a log, it sends a copy to its parent and above.
# Set false if no inheritance relationship is required
# Log3.propagate = false
#
# FH = logging. filehandler ("C. log", encoding = "UTF-8 ")

# Fm = logging. formatter (
# "% (Asctime) S % (levelname) S % (funcname) S % (lineno) S % (Message) s ",
# Datefmt = "% Y-% m-% d % x % P ")

# Log1.addhandler (FH)
# Log2.addhandler (FH)
# Log3.addhandler (FH)

# FH. setformatter (FM)
#
# Log1.warning ("Father log ")
# Log2.warning ("father. Son log ")
# Log3.warning ("father. Son. Grandson log") # If you can find the parent level, 3 will be printed. Otherwise, one will be printed, or log3.propagate = false will not be inherited.

# Import logging. config
# Configuring the log to input a dictionary object using a dictionary does not need to write the above Code
# Logging. config. dictconfig ()

# Stream processor
Log1 = logging. getlogger ("")
# Output to file
FH = logging. filehandler ("C. log", encoding = "UTF-8 ")
# D = logging. filehandler (R "C: \ Users \ jtyaole \ pycharmprojects \ untitled \ logger10_25 \ conf \ e. log", encoding = "UTF-8 ")
# Log1.addhandler (d)

# Output to the console
# SH = logging. streamhandler ()

# Log1.addhandler (SH)
Log1.addhandler (FH)
Fm = logging. formatter (
"% (Asctime) S % (levelname) S % (funcname) S % (lineno) S % (Message) s ",
Datefmt = "% Y-% m-% d % x % P ")
# D. setformatter (FM)
# Sh. setformatter (FM)
FH. setformatter (FM)
Log1.warning ("Test 2! ")

 

# Logger = Lib. Common. get_logger ()
#
# Def login ():
# Logger. debug ("test! ")
#
# Login ()

3 """
Re Module
Major Regular Expressions
What is a regular expression? A bunch of symbols with special meanings
It is used to process (match, search, and replace) strings.
1.
A large number of crawlers use a framework to encapsulate these complex regular expressions.
2.
The registration function of websites and mobile apps is widely used, for example, checking whether your email address is correct.


"""

Import re

#================================ Single character matching ====== ====
Print (Re. findall ("\ n", "1 \ n") # match a line break
Print (Re. findall ("\ t", "1asas121 \ t") # match the tab

 

#=========================================================
Print (Re. findall ("\ W", "1AA _ *") # match numbers, letters, and underscores
Print (Re. findall ("\ W", "1AA _ *,") # match non-alphanumeric characters
Print (Re. findall ("\ s", "\ n \ r \ t \ f") # match any blank characters
Print (Re. findall ("\ s", "\ n \ r \ t \ f") # match any non-blank characters
Print (Re. findall ("\ D", "123abc1 *") # match any number, equivalent to [0-9]
Print (Re. findall ("\ D", "123abc1 *") # match any non-digit
# Print (Re. findall ("[ABC]", "aabbcc") # match a B c.
# Print (Re. findall ("[^ ABC]", "aabbcc") # All operations except a B c
# Print (Re. findall ("[0-9]", "aabbcc12349") # All operations except a B c
Print (Re. findall ("[A-Z]", "aabbcc12349") # A-Z English letter
Print (Re. findall ("[A-Z]", "aabbc: C ?? 2349 [] ") # The a-Z matching principle is based on the ASCII code table.


#===================================================
Print (Re. findall ("\ A \ D", "123abc1 *") # match only one string from the beginning and no output is blank
Print (Re. findall ("\ D \ Z", "123abc1*9 \ n") # write \ Z to the right of the expression from the end of string matching, and only match one with no output Blank
Print (Re. findall ("\ D $", "123abc1*9") # match from the end of the string. If there is a line break at the end of the string, it is not involved in the match.
Print (Re. findall ("^ \ D", "s1asasas121 \ t") # match only one number from the character

 

8.10.18 learning Summary

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.