Today, some classmates found me to say, can write a simple Python MD5 encryption module, as the server-side program response function. Information security issues like that. MD5 uses a one-way encryption mechanism.
Directly on the code:
(K1, K2 is the system automatically generated random integer, user_name is the user name)
def encrypt (a= "user_name", K1=1, k2=1): #get system time B = time.strftime ('%y%m%d%h%m ', Time.localtime ( Time.time ())) ka1 = k1; ka2 = K2 Str = List (a+b) len = Len (Str) array1 = [0]*len; array2 = [0]*len #re _STR1, MD5 Digest of array1 array1 = [Chr (Ord (str[i]) ^ ka1) for I in Range (0,len)] TMP1 = ". Join (Array1) RE_STR1 = Hashlib.md5 (Tmp1.encode (' Utf-8 ')). Hexdigest () re_str1 = List (RE_STR1) #re_str2, MD5 Digest of Array2 array2 = [Chr (Ord (str[i]) ^ ka2) for I in Range (0,len)] tmp2 = ". Join (array2) re_str2 = Hashlib. MD5 (Tmp2.encode (' Utf-8 ')). Hexdigest () re_str2 = List (re_str2) RESULTF = "" " value = [Ord (re_str1[i*4+3 ]) ^ord (re_str2[i*4+3]) for I in range (0,8) "For I in range (0,8): RESULTF + = '%d '% (value[i]%10) return res Ultfif __name__ = = "__main__": import string import hashlib import time print encrypt ("TE", 13,23)
Python MD5 encryption module