密码管理工具一只

密码百八十个,又不便明文记录在手机或本子上,只记提示符时间一长看着一堆简略的提示符也傻眼,市场上的密码管理app虽然界面好看但也不敢用,安卓开发又不hui,索性鼓捣一个命令行工具

效果图:

mypass

加密/解密:

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class MyPass(object):
def __init__(self, file_passwd='./passwd'):
self.encrypt_head = bytes('MYPASSWD_HEAD', encoding="utf8")
self.secret = ''

def decrypt(self, content, encode=False, decode=True):
""" bytes -> str
"""
if len(self.secret) == 0:
print("Warning: the secret is empty")
elif decode and not content.startswith(self.encrypt_head):
print("The content has already been decrypt")
return content

content = content[len(self.encrypt_head):]

from itertools import cycle
result = bytes()
temp = cycle(self.secret)
for ch in content:
result += bytes(chr(ch ^ ord(next(temp))), encoding="utf8")

return result.decode(encoding="utf8")

def encrypt(self, content, encode=True, decode=False):
""" bytes -> bytes
"""
if len(self.secret) == 0:
print("Warning: the secret is empty")
elif encode and content.startswith(self.encrypt_head):
print("The content has already been encrypt")
return content

from itertools import cycle
result = self.encrypt_head
temp = cycle(self.secret)

for bt in content:
result += bytes(chr(bt ^ ord(next(temp))), encoding="utf8")

return result

附件:mypass.py

0%