当前位置: 首页> 财经> 股票 > python破解字母已知但大小写未知密码

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

时间:2025/7/11 19:18:04来源:https://blog.csdn.net/weixin_45693567/article/details/140252348 浏览次数:0次

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

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

def generate_uppercase_combinations(s, index=0, current=''):if index == len(s):print(current)returngenerate_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

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

- - - -

我的密码什么时候才能找回来啊😿
在这里插入图片描述

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: