<p><strong>多亏了那些给我想法的人,我自己找到了答案</strong></p>
<p>虽然我无法找到将Fernet字节数据直接转换为密码的方法,但我对密码学做了更深入的研究,了解了什么是真正随机的还是伪随机的</p>
<p>下面的代码是我为将来遇到与我相同问题的人确定的</p>
<p><strong>它的作用:</strong></p>
<ul>
<li>接受用户的输入</li>
<li>检查输入是否为整数</li>
<li>然后将数字向下舍入到可被4整除的最近整数</li>
<li>最后,它按顺序生成一个上/下/数字/标点符号</李>
</ul>
<p>这是一个有趣的项目,我一定会很快重新审视它,使它更简单、更有效,如果你有任何想法,请不要不好意思给我留言</p>
<pre><code> # Cryptographically generated random password
import random
import string
# Start Passgen
print("Please input a max-character limit for required password")
size = input()
try:
val = int(size)
except ValueError:
print("That's not an int!")
else:
print("Input accepted, Now generating password...")
# Generate the Password
def pass_gen():
uletters = string.ascii_uppercase
lletters = string.ascii_lowercase
digits = string.digits
punctuation = string.punctuation
chars = (uletters, lletters, digits, punctuation)
p = ''
for i in range(int(size)//4):
p += ''.join(random.SystemRandom().choices(uletters, k=1))
p += ''.join(random.SystemRandom().choices(lletters, k=1))
p += ''.join(random.SystemRandom().choices(digits, k=1))
p += ''.join(random.SystemRandom().choices(punctuation, k=1))
print("Your randomly generated password is: " + p)
#Run the function
pass_gen()
</code></pre>