Skip to content
Snippets Groups Projects
Commit 7b36fd06 authored by Abhisha Nirmalathas's avatar Abhisha Nirmalathas
Browse files

commented supplementary program

parent 4f80d31c
Branches
No related tags found
No related merge requests found
from itertools import permutations from itertools import permutations
# common letter substitutions
common_substituions = { common_substituions = {
"a": ["A","@", "4"], "a": ["A","@", "4"],
"b": ["8", "B"], "b": ["8", "B"],
...@@ -54,6 +55,7 @@ common_substituions = { ...@@ -54,6 +55,7 @@ common_substituions = {
"Z": ["z", "5", "$"] "Z": ["z", "5", "$"]
} }
def create_substituions(word): def create_substituions(word):
#creates a file of substitutions which is all possibly permutations
f = open("substition.txt", "a") f = open("substition.txt", "a")
perms = [''.join(p) for p in permutations(word)] perms = [''.join(p) for p in permutations(word)]
perms = list(dict.fromkeys(perms)) perms = list(dict.fromkeys(perms))
...@@ -63,6 +65,7 @@ def create_substituions(word): ...@@ -63,6 +65,7 @@ def create_substituions(word):
f.close() f.close()
print(perms) print(perms)
def create_replacements(word, file): def create_replacements(word, file):
# replaces world and writes to file
for x in range(len(word)): for x in range(len(word)):
if (word[x] in common_substituions): if (word[x] in common_substituions):
for y in common_substituions[word[x]]: for y in common_substituions[word[x]]:
...@@ -71,6 +74,7 @@ def create_replacements(word, file): ...@@ -71,6 +74,7 @@ def create_replacements(word, file):
file.write("\n") file.write("\n")
def create_common_password_substitutions(): def create_common_password_substitutions():
# creates list of passwords with common replacements
f = open("test.txt", "r") f = open("test.txt", "r")
words = f.readlines() words = f.readlines()
replacements = open("replacements_test.txt", "a") replacements = open("replacements_test.txt", "a")
...@@ -82,6 +86,7 @@ def create_common_password_substitutions(): ...@@ -82,6 +86,7 @@ def create_common_password_substitutions():
f.close() f.close()
def get_character_frequencies(): def get_character_frequencies():
#gets the frequencies of characters and builds words
f = open("proj-2_common_passwords.txt", "r") f = open("proj-2_common_passwords.txt", "r")
words = f.readlines() words = f.readlines()
f.close() f.close()
...@@ -103,6 +108,7 @@ def get_character_frequencies(): ...@@ -103,6 +108,7 @@ def get_character_frequencies():
get_character_frequencies() get_character_frequencies()
def write_out_common_substitutions(): def write_out_common_substitutions():
# writes out common substituion words
f = open("common_subs.txt", "w") f = open("common_subs.txt", "w")
for char, subs in common_substituions.items(): for char, subs in common_substituions.items():
f.write(char) f.write(char)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment