Skip to content

Instantly share code, notes, and snippets.

@tuxxy
Last active May 8, 2019 18:32
Show Gist options
  • Save tuxxy/b57c181751528b028295 to your computer and use it in GitHub Desktop.
Save tuxxy/b57c181751528b028295 to your computer and use it in GitHub Desktop.
Password Censor
#!/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)
@tuxxy
Copy link
Author

tuxxy commented May 22, 2015

Input (as file):

8846f7eaee8fb117ad06bdd830b7586c:password
57d583aa46d571502aad4bb7aea09c70:user
938df8b296dd15d0dce8eaa37be593e0:backup
a25b2710ba9de114396adc7dfb0a7235:Admin

Output (as stdout or in file):

8846f7eaee8fb117ad06bdd830b7586c:p******d
57d583aa46d571502aad4bb7aea09c70:u**r
938df8b296dd15d0dce8eaa37be593e0:b****p
a25b2710ba9de114396adc7dfb0a7235:A****n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment