繁体   English   中英

用密码字符代替单词(已解决,可能对其他人有用)

[英]Substitute cipher characters for words (solved, maybe useful for others)

我开始在这里写下我的一些问题,但我找到了一些答案并找出了 rest。 将其留在这里以备将来参考,以防对其他人有所帮助。

假设使用一次性密码器加密的“数字站”广播消息让我深受启发。 因此,在为 D&D 游戏做准备时,我想将一条消息编码成一个单词列表,其中使用的单词每隔一次使用一个字符就会交替出现。

使用一次性密码本,我开始手动加密消息,输入 7 个字符。然后意识到我已经犯了至少一个错误。 然后开始编写 python 程序来实际编码它。

我知道我可能没有找到优雅的解决方案,但它确实可以在不使用 numpy 的情况下工作。

matrix = [["A", "treatment", "snails", 1],  # massive 2d array. 
          ["B", "two", "texture", 1],  # Saner people would just do lower caps.
          ["C", "induce", "knotty", 1],
          ["D", "lowly", "unused", 1],
          ["E", "income", "grip", 1],
          ["F", "talented", "squeak", 1],
          ["G", "intelligent", "dependent", 1],
          ["H", "nest", "border", 1],
          ["I", "excuse", "delay", 1],
          ["J", "sudden", "gigantic", 1],
          ["K", "stew", "tooth", 1],
          ["L", "quack", "hole", 1],
          ["M", "eggs", "married", 1],
          ["N", "vessel", "punch", 1],
          ["O", "embarrass", "scatter", 1],
          ["P", "lace", "draconian", 1],
          ["Q", "lopsided", "attraction", 1],
          ["R", "blade", "average", 1],
          ["S", "workable", "way", 1],
          ["T", "harmony", "waste", 1],
          ["U", "thick", "warlike", 1],
          ["V", "island", "drop", 1],
          ["W", "rail", "null", 1],
          ["X", "misty", "earth", 1],
          ["Y", "camp", "clip", 1],
          ["Z", "fax", "stop", 1],
          ["a", "crooked", "left", 1],
          ["b", "thick", "cook", 1],
          ["c", "sense", "top", 1],
          ["d", "auspicious", "title", 1],
          ["e", "few", "error", 1],
          ["f", "longing", "fearless", 1],
          ["g", "scarce", "bone", 1],
          ["h", "eyes", "hushed", 1],
          ["i", "doctor", "save", 1],
          ["j", "puncture", "dashing", 1],
          ["k", "snotty", "foregoing", 1],
          ["l", "callous", "dolls", 1],
          ["m", "town", "wind", 1],
          ["n", "thirsty", "fear", 1],
          ["o", "thoughtful", "actually", 1],
          ["p", "ticket", "rings", 1],
          ["q", "view", "ancient", 1],
          ["r", "different", "hot", 1],
          ["s", "abrasive", "bag", 1],
          ["t", "excellent", "care", 1],
          ["u", "testy", "curious", 1],
          ["v", "complex", "reflective", 1],
          ["w", "smash", "kick", 1],
          ["x", "office", "helpful", 1],
          ["y", "noiseless", "gainful", 1],
          ["z", "minister", "false", 1],
          [" ", "linen", "power", 1],
          ["0", "subtract", "pathetic", 1],
          ["1", "employ", "bumpy", 1],
          ["2", "substance", "tow", 1],
          ["3", "towering", "probable", 1],
          ["4", "lake", "eye", 1],
          ["5", "moon", "yielding", 1],
          ["6", "crazy", "representative", 1],
          ["7", "actor", "rice", 1],
          ["8", "unwieldy", "manage", 1],
          ["9", "wing", "cowardly", 1],
          [".", "driving", "simplistic", 1],
          [",", "comb", "one", 1],
          ["?", "provide", "part", 1]]

text = "What a lovely night to post on Stack overflow. I'd be interested in having this as a program that asks for input text. Maybe as an .exe file, so I wont have to run it from pycharm." #the input text.

result = ""
n = 0  #thought I'd also like to know how long the string was/how many words it generated.

for char in text:  # repeat all the stuff for each character in the original text.
    row = 0
    n += 1

    for row in range(66):  # for every character, go down through array until matching char found.
        if matrix[row][0] == char: 
            if matrix[row][3] % 2 == 0:
                alternate = 2
            else:
                alternate = 1
            matrix[row][3] += 1# the number at the end of each row is a counter for 
            # how many times the character has already been used.
            result += matrix[row][alternate] + " - "  # concatenate everything.
            # print(matrix[row][alternate])  # neatly list everything on single lines. Not needed. Currently off.
length = len(result)
result = result[:length - 3]
result += "." #removes the, now no longer needed ' - ' from the end of the string and add a'.'. Also not needed.
print(n) #List the length of the text/the number of words.
print(result)

我想知道如果我有一个业余无线电并开始使用它来广播消息,我会多快得到执法部门的访问。

边注。 在 D&D 游戏中,有人变得懒惰并重复使用同一个一次性垫。 玩家发现的每一条加密线索都需要一个新线索才能破译并花费很长时间。 但是我想要这个程序,作为一个编程练习,也是为了保持一致性。 我想他们确实想破译它。

output 通过收音机大声朗读会相当不祥,而且间隔看似随机。

Output 和我的示例字符串,如果有人好奇的话;

181
rail - eyes - crooked - excellent - linen - left - power - callous - thoughtful - complex - few - dolls - noiseless - linen - thirsty - doctor - scarce - hushed - care - power - excellent - actually - linen - ticket - thoughtful - abrasive - care - power - actually - fear - linen - workable - excellent - crooked - sense - snotty - power - thoughtful - reflective - error - different - longing - callous - actually - smash - driving - linen - excuse - auspicious - power - thick - few - linen - save - thirsty - care - error - hot - few - bag - excellent - error - title - power - doctor - fear - linen - eyes - left - complex - save - thirsty - bone - power - care - hushed - doctor - abrasive - linen - crooked - bag - power - left - linen - rings - different - thoughtful - scarce - hot - crooked - town - power - excellent - eyes - left - care - linen - crooked - abrasive - foregoing - bag - power - fearless - actually - different - linen - save - fear - ticket - testy - excellent - power - care - few - office - excellent - simplistic - linen - eggs - left - gainful - cook - error - power - crooked - abrasive - linen - left - thirsty - power - driving - few - helpful - error - linen - longing - doctor - dolls - few - comb - power - bag - thoughtful - linen - delay - power - kick - actually - fear - care - linen - hushed - crooked - reflective - error - power - excellent - thoughtful - linen - hot - curious - thirsty - power - save - care - linen - fearless - different - actually - wind - power - rings - noiseless - top - eyes - left - hot - town - simplistic - linen.

暂无
暂无

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

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