一、凱撒密碼
關于凱撒密碼請參考之前的文章,鏈接如下:
https://blog.csdn.net/weixin_52351575/article/details/120742012
二、暴力破解凱撒加密
原理是使用密碼輪和凱撒加密的本質進行爆破
message = 'oknqdbqmoq{kag_tmhq_xqmdzqp_omqemd_qzodkbfuaz}' SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.' # Loop through every possible key:回圈遍歷所有可能的關鍵字 for key in range(len(SYMBOLS)): # It is important to set translated to the blank string so that the將translated定義成空字符很重要,這樣可以清除上一個迭代中 # previous iteration's value for translated is cleared. translated的值 translated = '' # The rest of the program is almost the same as the original program:程式的其余部分與凱撒程式基本相同 # Loop through each symbol in `message`:回圈遍歷message中的每一個字符 for symbol in message: if symbol in SYMBOLS: symbolIndex = SYMBOLS.find(symbol) translatedIndex = symbolIndex - key # Handle the wrap-around:執行回環 if translatedIndex < 0: translatedIndex = translatedIndex + len(SYMBOLS) # Append the decrypted symbol:添加解密的字符 translated = translated + SYMBOLS[translatedIndex] else: # Append the symbol without encrypting/decrypting:添加未解密/加密的字符 translated = translated + symbol # Display every possible decryption:顯示每一個可能的值 print('Key #%s: %s' % (key, translated))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/353264.html
標籤:其他
上一篇:滲透測驗學習之靶機DC-2
下一篇:java版Spring Cloud+SpringBoot+mybatis+uniapp b2b2c 多商戶入駐商城 直播 電子商務云架構&設計思想
