首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cipher python未返回权限

cipher python未返回权限
EN

Stack Overflow用户
提问于 2019-05-01 00:47:16
回答 1查看 34关注 0票数 0

没有得到正确的结果,需要解密代码的帮助

代码语言:javascript
复制
# need help with code
cipher = ''
decipher = ''
choice = ''
while choice != 0:
    choice = input('Press 1 to encrypt your text \nPress 2 to decrypt your 
    cipher text \n:')
    if choice == '1':
        cipher = input('Enter text to encrypt').lower()
        for letter in cipher:
            if(letter != ''):
                cipher += the_bacon[letter]
        print(cipher)
    break
代码语言:javascript
复制
>>> Press 1 to encrypt your text 
>>> Press 2 to decrypt your cipher text 
:1
>>> Enter text to encrypt
hello world
hello worldaabbb
hello worldaabbbaabaa
hello worldaabbbaabaaababb
hello worldaabbbaabaaababbababb
hello worldaabbbaabaaababbababbabbba

需要创建替代培根密码和它不能正常工作,也需要帮助与解密代码

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-01 01:39:37

假设您的the_bacon是一个具有1对1字母交换的适当字典,那么您的问题在于您是附加在输入上,而不是创建一个新的输出对象,然后将其打印出来。

您还可以使用while not choice:来表示循环,直到它们响应为止。除非你打算先把它转换成int类型,否则!= 0永远不会发生。

代码语言:javascript
复制
cipher = ''
decipher = ''
choice = ''
while not choice:
    choice = input('Press 1 to encrypt your text \nPress 2 to decrypt your 
    cipher text \n:')
    if choice == '1':
        in_cipher = input('Enter text to encrypt').lower()
        out_cipher = ''
        for letter in in_cipher:
            if(letter != ' '):
                out_cipher += the_bacon[letter]
                print(out_cipher) # print output letter by letter as it builds
        print(out_cipher) # print the output
    else:
        # you need to decipher here and handle choices not 1 or 2
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55925461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档