目录

简单替换密码的测试(Testing of Simple Substitution Cipher)

在本章中,我们将重点介绍使用各种方法测试替换密码,这有助于生成随机字符串,如下所示 -

import random, string, substitution
def main():
   for i in range(1000):
      key = substitution.getRandomKey()
      message = random_string()
      print('Test %s: String: "%s.."' % (i + 1, message[:50]))
      print("Key: " + key)
      encrypted = substitution.translateMessage(message, key, 'E')
      decrypted = substitution.translateMessage(encrypted, key, 'D')
      if decrypted != message:
         print('ERROR: Decrypted: "%s" Key: %s' % (decrypted, key))
         sys.exit()
      print('Substutition test passed!')
def random_string(size = 5000, chars = string.ascii_letters + string.digits):
   return ''.join(random.choice(chars) for _ in range(size))
if __name__ == '__main__':
   main()

输出 (Output)

您可以将输出视为随机生成的字符串,这有助于生成随机纯文本消息,如下所示 -

字符串

测试成功完成后,我们可以观察输出消息Substitution test passed!.

代换

因此,您可以系统地破解替换密码。

↑回到顶部↑
WIKI教程 @2018