0

当我从 IDLE 运行这段代码时,它运行良好。当我从命令行运行 py 文件时,我插入文件名并按enter,程序关闭。为什么会这样?我是否需要在代码中编写某种暂停功能,还是其他?

def encrypt(file,key):
    count=0
    encrypt=[]
    tmp=[]        
    openfile=open(file,"rb")        
    msg=openfile.read()        
    openfile.close()

    for i in msg:
        if count>=len(key):
              count=0     
        encrypt.append(i^ord(key[count]))
        count+=1

    for i in range(len(encrypt)):
        tmp.append(encrypt[len(encrypt)-1-i])

    count=0
    encrypt[:]=[]

    for i in tmp:
        if count>=len(key):
              count=0

        encrypt.append(i^ord(key[count]))
        count+=1

    encryptmsg=''.join(chr(e) for e in encrypt)
    ext=input('Saving...File Name (with extension)? ')
    file= open(ext, "wb")
    file.write(str.encode(encryptmsg))
    file.close()

    input("Press Enter to Continue...")

ans = input("""
 1- Encrypt/Decrypt
 0-Exit
-:""")

file_to_encrypt = input("File? ")
key = input("Key? ")
if ans=='1':
    encrypt(file_to_encrypt,key)
else:
    quit()
4

0 回答 0