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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

༄༊ξ陈丞(网安圈花瓶)࿐

点个关注呗。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值