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和结果文件名。


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

相关推荐
Rose sait1 分钟前
【环境配置】Linux配置虚拟环境pytorch
linux·人工智能·python
原来是好奇心8 分钟前
深入Spring Boot源码(六):Actuator端点与监控机制深度解析
java·开发语言·源码·springboot
过期动态32 分钟前
JDBC高级篇:优化、封装与事务全流程指南
android·java·开发语言·数据库·python·mysql
WizLC33 分钟前
【Java】各种IO流知识详解
java·开发语言·后端·spring·intellij idea
傻啦嘿哟42 分钟前
实战:用Splash搞定JavaScript密集型网页渲染
开发语言·javascript·ecmascript
Knight_AL1 小时前
Java 线程池预热(Warm-up)实战:开启与不开启到底差多少?
java·开发语言
一世琉璃白_Y1 小时前
pg配置国内数据源安装
linux·python·postgresql·centos
liwulin05061 小时前
【PYTHON】COCO数据集中的物品ID
开发语言·python
小鸡吃米…1 小时前
Python - XML 处理
xml·开发语言·python·开源
我赵帅的飞起1 小时前
python国密SM4加解密
python·sm4加解密·国密sm4加解密