解密
def hex2string(hexstr):
lens = (len(hexstr) + 1) / 2
lens = int(lens)
j = 0
list_ = []
for i in range(lens):
oneLineTiaojian = ord(hexstr[j]) & ord('@')
oneLinebd1 = ord(hexstr[j]) + 9
oneLinebd2 = ord(hexstr[j])
oneValue = oneLinebd1 if oneLineTiaojian else oneLinebd2
tmp = (oneValue << 4) % 256 # << >> ??????????????0-7?8?
oneResValue = tmp if tmp < 128 else tmp - 256 # ?c++?tmp?char????????python??tmp?int??????
j += 1
towLinetiaojian = ord(hexstr[j]) & ord('@')
towLinebd1 = ord(hexstr[j]) + 9
towLinebd2 = ord(hexstr[j])
towValue = towLinebd1 if towLinetiaojian else towLinebd2
towResValue = towValue & 0xF
res = oneResValue | towResValue
j += 1
list_.append(str(res))
return list_
def decryptPassword(strEncrypedText):
res_list = hex2string(strEncrypedText)
pwd_list = []
for i in range(1, int(len(res_list)), 2):
r1 = int(res_list[i]) ^ 86
pwd_list.append(chr(r1))
res = ''.join(pwd_list)
return res
if __name__ == '__main__':
r = decryptPassword('E4676E645865D2620A63C060631660165A78847838675564')
print(r)
加密
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2020/5/8 11:28
# @Author : wn
# @File: jiami.py
# @SoftWare: PyCharm
# @Site:
# @Table:
# 。◕‿◕。。◕‿◕。。◕‿◕。
# python 表示最大正整数,c++ rand()无参数,返回一个从0到最大数的任意整数
import sys
import random as r
def encryptPassword(strPlainText):
temp_str = ''
for i in strPlainText:
# 1.第一次加密
rv = r.randint(0, sys.maxsize)
rv_str = chr(rv % 255)
# 1.2^:异或,相同为0,相异为1。
iv = ord(i) ^ 86
ivc = chr(iv)
# 1.3存入临时变量
temp_str += rv_str
temp_str += ivc
# print('第一次加密:',temp_str)
# 2.第二次加密,把原来的字符串temp_str变成十六进制
list_hex3 = str_to_hex3(temp_str)
# print(list_hex3,len(list_hex3))
for item in list_hex3:
if len(item) == 1:
index = list_hex3.index(item)
list_hex3[index] = '0'+item
str_hex = ''.join(list_hex3)
# print(str_hex,len(str_hex))
return str_hex
def str_to_hex3(s):
# return ' '.join([hex(ord(c)).replace('0x', '') for c in s])
return [hex(ord(c)).replace('0x', '') for c in s]
en = encryptPassword('qwer__8899')
MD5加密
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2020/4/27 11:26
# @Author : wn
# @File: md5加密.py
# @SoftWare: PyCharm
# @Site:
# @Table:
#。◕‿◕。。◕‿◕。。◕‿◕。
import hashlib
def gen_md5(origin):
"""
md5加密
:param origin:
:return:
"""
ha = hashlib.md5(b'fasdfsdf')
ha.update(origin.encode('utf-8'))
return ha.hexdigest()
g = gen_md5('123')
# 123
# e7b702f637182428b8f480305bc89cf5
print(g)