花密 Python 核心代码

花密简介

“花密”提供一种简单的密码管理方法,你只需要记住一个“记忆密码”,为不同的账号设置不同的“区分代号”,然后通过“花密”计算就可以得到不同的复杂密码。

Python 2.x 核心代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
import hmac

def generateFPCode(password, key, length = 16):
if (1 > len(password.strip())) or (1 > len(key.strip())) or (1 > length) or (length > 32):
return;

hmd5 = hmac.new(key, password).hexdigest();
rule = list(hmac.new("kise", hmd5).hexdigest());
source = list(hmac.new("snow", hmd5).hexdigest());

for i in range(0, 32):
if not(source[i].isdigit()):
if rule[i] in "sunlovesnow1990090127xykab":
source[i] = source[i].upper();

code = "".join(source[1:length]);
if not(source[0].isdigit()):
code = source[0] + code;
else:
code = "K" + code;

return code;

Python 3.x 核心代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
import hmac

def generateFPCode(password, key, length = 16):
if (1 > len(password.strip())) or (1 > len(key.strip())) or (1 > length) or (length > 32):
return;

password = password.encode(encoding="utf-8");
key = key.encode(encoding="utf-8");

hmd5 = hmac.new(key, password).hexdigest().encode(encoding="utf-8");
rule = list(hmac.new("kise".encode(encoding="utf-8"), hmd5).hexdigest());
source = list(hmac.new("snow".encode(encoding="utf-8"), hmd5).hexdigest());

for i in range(0, 32):
if not(source[i].isdigit()):
if rule[i] in "sunlovesnow1990090127xykab":
source[i] = source[i].upper();

code = "".join(source[1:length]);
if not(source[0].isdigit()):
code = source[0] + code;
else:
code = "K" + code;

return code;
坚持原创技术分享,您的支持将鼓励我继续创作!