python破解字母已知但大小写未知密码

python穷举已知字符串中某个或多个字符为大写的所有情况

可以使用递归函数来实现这个功能。以下是一个示例代码:

python 复制代码
def generate_uppercase_combinations(s, index=0, current=''):
    if index == len(s):
        print(current)
        return
    
    generate_uppercase_combinations(s, index + 1, current + s[index])
    
    if s[index].isalpha() and s[index].islower():
        generate_uppercase_combinations(s, index + 1, current + s[index].upper())

# 测试代码
s = "abc"
generate_uppercase_combinations(s)

generate_uppercase_combinations函数接受一个字符串s和两个可选参数index和current。index表示当前处理的字符的索引,current表示当前生成的字符串。函数首先将不改变当前字符大小写继续进行递归调用,然后将当前字符转为大写后进行递归调用。最终会打印出所有可能的情况。

在示例中,给定字符串为"abc",会依次输出:"abc"、"abC"、"aBc"、"aBC"、"Abc"、"AbC"、"ABc"、"ABC"。

把生成的所有结果写入result.txt

python 复制代码
def generate_uppercase_combinations(s, index=0, current='', output_file='result.txt'):
    if index == len(s):
        with open(output_file, 'a') as file:
            file.write(current + '\n')
        return
    
    generate_uppercase_combinations(s, index + 1, current + s[index], output_file)
    
    if s[index].isalpha() and s[index].islower():
        generate_uppercase_combinations(s, index + 1, current + s[index].upper(), output_file)

# 测试代码
s = "abc"
with open('result.txt', 'w') as file:
    file.write('')
generate_uppercase_combinations(s)

output_file参数用于指定结果输出的文件名result.txt

在递归函数中,当生成完一组结果后,将结果写入到文件中。

在测试代码中,先创建或清空result.txt文件,然后调用函数生成结果并写入文件。

最终结果会保存在result.txt文件中。

可以根据需求修改输入字符串s和结果文件名。


我的密码什么时候才能找回来啊😿

相关推荐
Rust语言中文社区25 分钟前
【Rust日报】 丰田“先锋”选择了 Rust
开发语言·后端·rust
邹小邹-AI27 分钟前
Rust + 前端:下一个十年的“王炸组合”
开发语言·前端·rust
ECT-OS-JiuHuaShan29 分钟前
否定之否定的辩证法,谁会不承认?但又有多少人说的透?
开发语言·人工智能·数学建模·生活·学习方法·量子计算·拓扑学
東雪木31 分钟前
变量与数据类型
java·开发语言
Lisonseekpan34 分钟前
Java分词器深度评测与实战指南
java·开发语言·后端
c***871938 分钟前
Flask:后端框架使用
后端·python·flask
百***35481 小时前
JavaScript在Node.js中的集群部署
开发语言·javascript·node.js
光影少年1 小时前
node.js和nest.js做智能体开发需要会哪些东西
开发语言·javascript·人工智能·node.js
xu_yule1 小时前
Linux_14(多线程)线程控制+C++多线程
java·开发语言·jvm
c***97982 小时前
PHP在内容管理中的模板引擎
开发语言·php