【问题标题】:How to decrypt a columnar transposition cipher如何解密柱状转置密码
【发布时间】:2019-01-15 07:33:44
【问题描述】:

我的问题不是每个人说的编码,而是理解算法。

从概念上讲,我了解列换位如何使用常量键值(例如 10)解密文本。

当键是排列时,我的困惑就出现了。例如key = [2,4,6,8,10,1,3,5,7,9] 和类似"XOV EK HLYR NUCO HEEEWADCRETL CEEOACT KD" 的消息。我感到困惑的部分是将密文写入行,然后根据密钥排列行。

有人可以澄清一下吗?

【问题讨论】:

    标签: python encryption cryptography


    【解决方案1】:

    我想通了。一旦知道行数和列数,就可以将密文写入行,然后根据密钥对行进行置换。如果我的解释有误,请指正。纯文本是“你已经破解密码的出色工作”

    【讨论】:

      【解决方案2】:

      本质上,密钥成为密码中每个x 字母的排序,x 是密钥的长度。在您的示例中,密钥的长度为 10,因此您可以按照对应的订单号排列前 10 个字母。

      这就是解释,这是我编写的一些代码,用于使用密钥以正确的顺序排列密码:

      import math
      
      moves = [2,4,6,8,10,1,3,5,7,9]
      msg = "XOV EK HLYR NUCO HEEEWADCRETL CEEOACT KD"
      
      decrypted = list(msg)
      
      for i, letter in enumerate(msg):
          moves_index = i % len(moves)
      
          index = (math.floor(i / len(moves)) * len(moves)) + moves[moves_index]
      
          decrypted[index - 1] = letter
      
          print(str.format('{}, at index {}, goes in destination index {} (letter number {})', letter, i, index - 1, index))
      
      print(''.join(decrypted))
      

      这会打印出每个步骤,以便您可以手动验证它:

      X, at index 0, goes in destination index 1 (letter number 2)
      O, at index 1, goes in destination index 3 (letter number 4)
      V, at index 2, goes in destination index 5 (letter number 6)
       , at index 3, goes in destination index 7 (letter number 8)
      E, at index 4, goes in destination index 9 (letter number 10)
      K, at index 5, goes in destination index 0 (letter number 1)
       , at index 6, goes in destination index 2 (letter number 3)
      H, at index 7, goes in destination index 4 (letter number 5)
      L, at index 8, goes in destination index 6 (letter number 7)
      Y, at index 9, goes in destination index 8 (letter number 9)
      R, at index 10, goes in destination index 11 (letter number 12)
       , at index 11, goes in destination index 13 (letter number 14)
      N, at index 12, goes in destination index 15 (letter number 16)
      U, at index 13, goes in destination index 17 (letter number 18)
      C, at index 14, goes in destination index 19 (letter number 20)
      O, at index 15, goes in destination index 10 (letter number 11)
       , at index 16, goes in destination index 12 (letter number 13)
      H, at index 17, goes in destination index 14 (letter number 15)
      E, at index 18, goes in destination index 16 (letter number 17)
      E, at index 19, goes in destination index 18 (letter number 19)
      E, at index 20, goes in destination index 21 (letter number 22)
      W, at index 21, goes in destination index 23 (letter number 24)
      A, at index 22, goes in destination index 25 (letter number 26)
      D, at index 23, goes in destination index 27 (letter number 28)
      C, at index 24, goes in destination index 29 (letter number 30)
      R, at index 25, goes in destination index 20 (letter number 21)
      E, at index 26, goes in destination index 22 (letter number 23)
      T, at index 27, goes in destination index 24 (letter number 25)
      L, at index 28, goes in destination index 26 (letter number 27)
       , at index 29, goes in destination index 28 (letter number 29)
      C, at index 30, goes in destination index 31 (letter number 32)
      E, at index 31, goes in destination index 33 (letter number 34)
      E, at index 32, goes in destination index 35 (letter number 36)
      O, at index 33, goes in destination index 37 (letter number 38)
      A, at index 34, goes in destination index 39 (letter number 40)
      C, at index 35, goes in destination index 30 (letter number 31)
      T, at index 36, goes in destination index 32 (letter number 33)
       , at index 37, goes in destination index 34 (letter number 35)
      K, at index 38, goes in destination index 36 (letter number 37)
      D, at index 39, goes in destination index 38 (letter number 39)
      

      但是,最后打印出来的是:KX OHVL YEOR HNEUECREEWTALD CCCTE EKODA,这与您提出的解决方案不匹配:execlent work you have cracked the code(显然忽略了大小写)。不确定是什么差异...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-19
        • 2011-07-30
        • 2015-07-14
        • 2011-07-14
        • 1970-01-01
        相关资源
        最近更新 更多