密文设置

来源:互联网 发布:gson解析json list对象 编辑:程序博客网 时间:2024/05/23 20:50

简介

只能在命令行输入运行

import msvcrt, sysdef getpass(prompt='Password: '):    count = 0    chars = []    for x in prompt:        msvcrt.putch(bytes(x, encoding='utf8'))    while True:        new_char = msvcrt.getch()        if new_char in b'\r\n':            break        elif new_char == b'\0x3':  # ctrl + c            raise KeyboardInterrupt        elif new_char == b'\b':            if chars and count >= 0:                count -= 1                chars = chars[:-1]                msvcrt.putch(b'\b')                msvcrt.putch(b'\x20')  # space                msvcrt.putch(b'\b')        else:            if count < 0:                count = 0            count += 1            chars.append(new_char.decode('utf8'))            msvcrt.putch(b'*')    return ''.join(chars)pwd = getpass()print('\r\nThe password is: ', pwd)

这里写图片描述