900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 基于python实现暴力破解凯撒密码

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

时间:2023-01-04 13:50:45

相关推荐

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

一、凯撒密码

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

/weixin_52351575/article/details/12074

二、暴力破解凯撒加密

原理是使用密码轮和凯撒加密的本质进行爆破

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。