栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

基于python实现暴力破解凯撒密码

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于python实现暴力破解凯撒密码

一、凯撒密码

        关于凯撒密码请参考之前的文章,链接如下:

        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))

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/460898.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号