[英]How to append the first item of list to the end of all permutations of that list?
[英]Password strengthening script - how to capitalise first letter and append list of integers to end of text in file and list it repeatedly
我目前正在编写一个基本的python脚本,旨在执行以下操作:
反转它(例如密码变成drowssap)
用'0'代替'o',用'4'代替'a',用'5'代替's'(例如密码变成p455w0rd
使第一个字符大写(例如密码变为密码)
将 1900 年到 2014 年的所有年份附加到密码中,例如 password1900、password1901、...、password2014
我的示例中的“passwordlist.txt”包含一行文本“password”。
到目前为止我的代码是:
reading_file = open("passwordlist.txt", "r")
new_file_content = ""
for line in reading_file:
stripped_line = line.strip()
new_line = stripped_line.replace("a", "4").replace("o", "0").replace("s", "5").replace("d", "D")
new_file_content += "\n" + new_line
reading_file.close()
writing_file = open("hashedpasslist.txt", "w")
years = map(str, range(1900, 2014))
writing_file.write(new_file_content[::-1])
writing_file.close()
我需要帮助使输出文件的第一个字符大写,您是否可以看到我只设法将 'd' 交换为 'D'。 最后,我想将 1900 年到 2014 年的所有年份附加到密码中,因此输出应该是例如 Dr0w554p1900、Dr0w554p、...、Dr0w554p2014,最好采用列出的格式。
您可以使用以下代码段将第一个字符大写
string[0].upper() + string[1:]
在您的代码中将是:
reading_file = open("passwordlist.txt", "r")
new_file_content = ""
for line in reading_file:
stripped_line = line.strip()
new_line = stripped_line.replace("a", "4").replace("o", "0").replace("s", "5")
new_line = new_line[0].upper() + new_line[1:]
new_file_content += "\n" + new_line
reading_file.close()
writing_file = open("hashedpasslist.txt", "w")
years = map(str, range(1900, 2014))
writing_file.write(new_file_content[::-1])
writing_file.close()
至于年份,您需要遍历每一年,将其附加到字符串并将其输出到列表中。
例如。
output = []
for year in range(1900, 2015):
appended_line = new_line + str(year)
output.append(appended_line)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.