-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.py
162 lines (104 loc) · 2.9 KB
/
core.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import secrets, string
numbers = string.digits
letters = string.ascii_letters
punctuations = string.punctuation
all_characters = numbers + letters + punctuations
my_dict = {
'abc' : 0,
'def' : 1,
'ghi' : 2,
'jkl' : 3,
'mno' : 4,
'pqr' : 5,
'stu' : 6,
'vwx' : 7,
'yz' : 8,
'.' : 9
}
def generate_pass_card() :
'''
returns a list conaining lists of rows which contain
lists with values(future password parts)
'''
pass_card = []
for row in range(10) :
my_row = []
for col in range(10) :
my_value = []
cell_value = secrets.choice(all_characters) + secrets.choice(all_characters) + secrets.choice(all_characters)
my_value.append(cell_value)
my_row.append(my_value)
pass_card.append(my_row)
return pass_card
def write_to_file(card_list, file_name = 'pass_card.txt'):
'''
(first creates if file does not exist)
overwrites to a txt file a string of all possible conbinations
'''
with open(file_name, 'w') as file:
for rows in card_list:
for data in rows :
for values in data :
file.write(values + ' ')
file.write('\n')
def create_new_pass_card():
'''
OUTPUT creates a new pass card and write it to a file
(if file not specified writes to pass_card.txt)
'''
write_to_file(generate_pass_card())
def read_pass_card(file_name = 'pass_card.txt') :
'''
INPUT name of the file containing password card
OUTPUT list containing password card
'''
password_card = []
row = []
value = []
with open(file_name, 'r') as file :
for line in file :
line = line.replace(' ', '')
for i in range(10) :
cell_value = line[:3]
line = line[3:]
value.append(cell_value)
row.append(value.copy())
value.clear()
password_card.append(row.copy())
row.clear()
return password_card
def find_column(letter) :
'''
INPUT a letter
OUTPUT index of the letter's column
'''
for key in my_dict.keys() :
if letter.lower() in key :
return my_dict[key]
def user_input():
'''
INPUT a word
check if it is a word with letters or .
OUTPUT lowered word
'''
word = input('word :')
if word.isalpha() or word == '.' :
return word.lower()
else :
user_input()
def get_password(word,list) :
'''
INPUT word, list of password pieces
OUTPUT password
'''
word = word.lower()
password = ''
line = 0
for letter in word :
column = find_column(letter)
password += list[line][column][0]
if line >= 9 :
line = 0
else :
line += 1
return password