Import random,string
# Print (Random.randint (1,199)) #1-199 randomly take an integer
# print (string.digits) #所有的数字0-9
# print (string.ascii_lowercase) #所有的小写字母
# print (string.ascii_uppercase) #所有的大写字母
# print (string.ascii_letters) #所有的小写字母 + ALL caps
# print (string.punctuation) #所有的特殊字符
# s = Random.choice ([' Ybq ', ' mpp ', ' zhx ', ' DF ']) #随机取一个元素
# s = Random.choice () #随机取一个元素
# res = random.sample (string.digits,3) #随机取N个元素
# print (". Join (RES)")
# res = random.uniform (1,9) #取随机小数??
# Print (RES)
# Print (round (res,2)) # Keep a few decimals, if after rounding, the last decimal number is 0, then do not display
#print (Random.random ()) #取0-1 random decimals
s = [' A ', ' B ', ' C ', ' d ', ' e ']
Random.shuffle (s) #洗牌, scramble order, only list
Print (s)
Import Time
# Time.sleep (2) #等待几秒
# 1, Format good time 2018-1-14-16:42
# 2, timestamp is the number of seconds from UNIX to now
# 3, Time tuple
#想时间戳和格式化好的时间互相转换的话, you have to turn it into a time tuple before you can go
# print (int (time.time ())) #当前时间戳
# cur_time = Time.strftime ('%y-%m-%d%h:%m:%s ')
# cur_time = time.strftime ('%h%m%s ') #取当前时间的格式化时间
# Print (Time.gmtime ()) #默认取标准时区的时间元组, if a timestamp is passed, the timestamp is converted to a time tuple.
# print (Time.timezone) #和标准时间相差了几个小时
# Print (Time.gmtime (1516005840)) #标准时区.
Cur_time= time.localtime (1516005840) #默认取当前时区的时间元组, if a timestamp is passed, the timestamp is converted to a time tuple.
res = Time.strftime ('%y-%m-%d%h:%m:%s ', cur_time)
def timestamptostr (time_strmp,format= '%y%m%d%h%m%s '):
#时间戳转格式化好的时间
Cur_time = Time.localtime (TIME_STRMP) #时间戳转成时间元组
res = time.strftime (format, cur_time) #再把时间元组转成格式化好的时间
return res
def strtotimestamp (time_st,format= '%y%m%d%h%m%s '):
#20181128113859
#这个函数是格式化好的时间, turn the time stamp
T=time.strptime (Time_st,format) #把格式化好的时间转成时间元组
res = time.mktime (t) #时间元组转成时间戳
return res
# 86400 * 3
# 32342-86400 * 3
Import Hashlib
# MD5
ybm_pwd= ' [email protected] ' #
m = Hashlib.md5 () #
BYTES_YBQ = Ybm_pwd.encode () #把字符串转成bytes类型
M.update (BYTES_YBQ) #加密, cannot string, only bytes type, binary
# Print (M.hexdigest ()) #加密后的结果
def md5_password (ST:STR): #限定了入参的类型, only String type
Bytes_st = St.encode () #转成二进制类型
m = hashlib.md5 (Bytes_st) #加密
Return M.hexdigest () #返回加密后的结果
#
# sha_256 =hashlib.sha256 (BYTES_YBQ)
# sha512 =hashlib.sha512 (BYTES_YBQ)
# Print (Sha512.hexdigest ())
# Print (dir (m))
#md5加密是不可逆的, cannot be decrypted.
# MD5 MD5AF
# 123456 f0dfb4c958c67903e542e31c729c629b
#撞库
Import Base64
s= ' hahaha '
byte_s = S.encode () #字符串变成二进制
res = Base64.b64encode (byte_s) #base64编码
Print (Res.decode ()) #把bytes转成字符串.
Jie_mi_res = Base64.b64decode (Res.decode ()) #base64编码
Print (Jie_mi_res.decode ())
Day5-python Learning Note (11) Random module, time module, encryption module