簡體   English   中英

密碼強化腳本 - 如何將首字母大寫並將整數列表附加到文件中的文本末尾並重復列出

[英]Password strengthening script - how to capitalise first letter and append list of integers to end of text in file and list it repeatedly

我目前正在編寫一個基本的python腳本,旨在執行以下操作:

  1. 將密碼文件作為輸入
  2. 對每個密碼執行以下轉換並寫入新文件:

反轉它(例如密碼變成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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM