Python旋转密码脚本ISU

2024-04-24 08:34:45 发布

您现在位置:Python中文网/ 问答频道 /正文

所以基本上我在写一个工具,对字母旋转密码的所有可能答案进行暴力破解,然后将它们全部打印到屏幕上。我如何防止特殊字符和空格旋转,让它们保持原样

#!/usr/bin/env python3

# alphabeth and key variables

import sys

alpha_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alpha_lower = "abcdefghijklmnopqrstuvwxyz"
cipher_text = sys.argv[1]

def crack_rotation():

    for key in range(len(alpha_lower)):
        plain_text = ''

        for character in cipher_text:
            if character == character.lower():
                index = alpha_lower.find(character)
                index = (index-key)%len(alpha_lower)
                plain_text += alpha_lower[index]
            else:
                index = alpha_upper.find(character)
                index = (index-key)%len(alpha_upper)
                plain_text += alpha_upper[index]

        print('Trying with key %s. Result = %s' %(key, plain_text))

crack_rotation()

Tags: keytextinalphaforindexlensys
1条回答
网友
1楼 · 发布于 2024-04-24 08:34:45

在最里面的循环中,检查字符是否不在字母表中,如果不在字母表中,则跳过循环的其余部分

if character not in alpha_upper + alpha_lower:
    plaintext += character
    continue

相关问题 更多 >