【问题标题】:Trying to decrypt substitution using letter frequencies尝试使用字母频率解密替换
【发布时间】:2021-11-11 20:59:43
【问题描述】:

为了解密涉及替换和柱状转置的两步密码,我决定尝试通过比较密文中的字母频率与替换的英文频率并使用四元组适应度来解决这个问题。转置部分似乎工作正常,但代码似乎不能很好地与替换部分一起工作。有没有人对如何解决这个问题或完全不同的解决方案有任何想法?如果你想要完整的 repl 文件,链接是https://replit.com/@creeperthecat/substitution-then-columnar-transposition#main.py

def FrequencySubstitution(text):
    frequencies = LetterFrequencies(text) #this function gives a float between 0 and 1 for each letter in the alphabet based on its frequency
    newfrequencies = sorted(frequencies)

    indexes = []

    for i in frequencies:
        count = newfrequencies.count(i)
        if count == 1:
            index = newfrequencies.index(i)
            indexes.append(index)
        else:
            for j in range(count):
                index = newfrequencies.index(i)+j
                if index not in indexes:
                  indexes.append(index)
    indexes.reverse()
    substitutionkey = []
    for i in indexes:
        substitutionkey.append(mostcommonletters[I])#mostcommonletters is a list of English letters in order of the most frequent ones - I realise that this list can vary but it should give enough information to decrypt it properly

    newtext = DecryptSubstitution(text, substitutionkey)

    return (newtext,substitutionkey, indexes)

【问题讨论】:

    标签: python cryptography


    【解决方案1】:

    事实证明,这似乎是当前方法的所在。转置密钥必须足够短才能使用蛮力,或者您必须希望字母频率足够好以使用转置解密。

    【讨论】: