简体   繁体   English

如何替换字典中输入的文本中的单词

[英]How to replace words a inputted text from dictionary

Well, after reading Digital Fortress by Dan Brown l really wanted to make a cypher maker and decrypter.好吧,在阅读了 Dan Brown 的 Digital Fortress 之后,我真的很想制作一个 cypher 制造商和解密器。 To make this i had to make a cypher language.为此,我必须制作 cypher 语言。 I made it at first but when the user inputs the text i am confused how can i convert the input to a cypher?我一开始就做到了,但是当用户输入文本时,我很困惑如何将输入转换为 cypher?

 `#cypher by GDD

cyp = {
    1 : '',
    0 : ' ',
    2.1 : 'a',
    2.2 : 'b',
    2.3 : 'c',
    2.4 : '2',
    3.1 : 'd',
    3.2 : 'e',
    3.3 : 'f',
    3.4 : '3',
    4.1 : 'g',
    4.2 : 'h',
    4.3 : 'i',
    4.4 : '4',
    5.1 : 'j',
    5.2 : 'k',
    5.3 : 'l',
    5.4 : '4',
    6.1 : 'm',
    6.2 : 'n',
    6.3 : 'o',
    6.4 : '6',
    7.1 : 'p',
    7.2 : 'q',
    7.3 : 'r',
    7.4 : 's',
    7.5 : '7',
    8.1 : 't',
    8.2 : 'u',
    8.3 : 'v',
    8.4 : '8',
    9.1 : 'w',
    9.2 : 'x',
    9.3 : 'y',
    9.4 : 'z',
    0.1 : '0'
}


inpu  = input("To encrypt text press \'E\'\n To decrypt text press press \'D\' : ")
ch = inpu.upper()

if ch == "E":
    txt = input('Please input text to encrypt it : ')
    var = txt.len()
    for i in range(var):

#I am really confused after this` #这之后我真的很困惑`

You are almost there.你快到了。 It's an interesting one, so I'm going to help.这是一个有趣的,所以我要帮忙。 Here's an example:这是一个例子:

inpu  = input("To encrypt text press \'E\'\n To decrypt text press press \'D\' : ")
ch = inpu.upper()
encryptedtext = []
decryptedtext = []
if ch == "E":
    txt = input('Please input text to encrypt it : ')
    for letter in txt:
        for code, character in cyp.items():
            if character == letter:
                encryptedtext.append(code)
if ch == "D":
    txt = input('Please input code to decrypt it : ')
    floats = [float(x) for x in txt.split()]
    for code in floats:
        decryptedtext.append(cyp[code])
print(*encryptedtext)
print(*decryptedtext)

If you input "abc" for encrypting text, your output will be:如果您输入“abc”来加密文本,您的 output 将是:

2.1 2.2 2.3

If you input "8.1 8.2" (Make sure it's spaced, this is just an example, I can't fine tune everything), your output will be:如果您输入“8.1 8.2”(确保它是间隔的,这只是一个示例,我无法微调所有内容),您的 output 将是:

t u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM