Created
January 12, 2016 08:26
-
-
Save emelent/795443d1f4f7f9160799 to your computer and use it in GitHub Desktop.
Password Obfuscator
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
#!/bin/python2 | |
""" | |
Simply takes a simple, insecure alphabetic phrase | |
and turns it into a useable password. | |
Use a friendly phrase you can easily remember to generate | |
a password no one can ever guess. | |
""" | |
import sys | |
import hashlib | |
sha256 = hashlib.sha256() | |
dict = {'a':'@', 'e': '3', 'i': '1', 'o':'0', 's':'$', 'z': '2', 'c': '<', 'd' : '<|', 'h': '#', 'p' : '%'} | |
splice_len = 3 | |
min_len = 6 | |
def obfuscate(phrase): | |
""" | |
Obfuscate the given phrase | |
@param phrase string to obfuscate | |
@ret string | |
""" | |
new_phrase ='' | |
phrase = phrase.lower() | |
# add a little pseudo random uppercasing | |
n = len(phrase) | |
phrase = phrase[:n//2] + phrase[n//2].upper() + phrase[(n//2)+1:] | |
phrase = phrase[:n//3] + phrase[0].upper() + phrase[(n//3)+1:] | |
for c in phrase: | |
new_phrase += dict[c] if c in dict else c | |
sha256.update(new_phrase) | |
h = sha256.hexdigest() | |
return simple_splice(new_phrase, h, splice_len) | |
def simple_splice(str1, str2, splice_len): | |
""" | |
splice 2 strings together | |
@param str1 first string | |
@param str2 second string | |
@splice_len splice_len length of the splicing | |
@ret string | |
e.g str1 = '135791113' | |
str2 = '246810' | |
splice_len = 3 | |
returns '123456791113' | |
""" | |
splice_str = '' | |
for i in range(splice_len): | |
splice_str += str1[i] + str2[i] | |
splice_str += str1[splice_len:] | |
return splice_str | |
if __name__ == '__main__': | |
if len(sys.argv) > 1: | |
phrase = sys.argv[1] | |
if len(phrase) < min_len: | |
print("Phrase must be at least %i characters long" % min_len) | |
sys.exit(2) | |
print(obfuscate(phrase)) | |
else: | |
print("0 arguments given") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment