Last active
May 8, 2019 18:32
-
-
Save tuxxy/b57c181751528b028295 to your computer and use it in GitHub Desktop.
Password Censor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
""" Takes any file with format: | |
<hash>:<password> | |
as an argument. Example: | |
`python pass.py list.txt` | |
Include a second argument for output. Example: | |
`python pass.py list.txt output.txt` | |
Alternatively, you can use stdout: | |
`python pass.py list.txt > newList.txt` | |
Author: John Pacific (Tux) | |
""" | |
# Read the file and grab contents and seperate the input by delimited colons | |
# and delete the newline char (\n) | |
with open(sys.argv[1]) as file: | |
contents = [line.rstrip().split(':') for line in file] | |
# Censor out everything but the first and last chars. | |
newContents = [] | |
for item in contents: | |
password = item[1] | |
password = password.replace(password[1:-1], '*'*len(password[1:-1])) | |
newContents.append("{}:{}\n".format(item[0], password)) | |
# If you included a second argument for output: | |
if len(sys.argv) > 2: | |
with open(sys.argv[2], 'w+') as file: | |
for line in newContents: | |
file.write(line) | |
else: | |
for line in newContents: | |
sys.stdout.write(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input (as file):
Output (as stdout or in file):