-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaint_RobCo.py
275 lines (219 loc) · 9.01 KB
/
maint_RobCo.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import random
import time
import sys
import os
import cmd_RobCo
import var_RobCo
import sys_RobCo
import termS_RobCo
import mainCode_RobCo
def t_inquire_code():
cmd_RobCo.char("ROBCO INDUSTRIES (TM) TERMLINK PROTOCOL \nENTER PASSWORD NOW")
with open('system/sevenletterwords.txt') as wordListFile:
WORDS = wordListFile.readlines()
for i in range(len(WORDS)):
WORDS[i] = WORDS[i].strip().upper()
def main():
input('\nPress enter to begin protocol...')
termS_RobCo.empty()
gameWords = getWords()
computerMemory = getComputerMemoryString(gameWords)
secretPassword = random.choice(gameWords)
cmd_RobCo.char(computerMemory)
for triesRemaining in range(4, 0, -1):
playerMove = askForPlayerGuess(gameWords, triesRemaining)
if playerMove == secretPassword:
cmd_RobCo.char("\nACCESS GRANTED")
sys_RobCo.log(3, 102, '')
mainCode_RobCo.main_code()
return
else:
numMatches = numMatchingLetters(secretPassword, playerMove)
cmd_RobCo.char('\nAccess Denied ({}/7 correct)'.format(numMatches))
cmd_RobCo.char('Out of tries.')
time.sleep(1)
cmd_RobCo.clear()
sys_RobCo.log(3, 83, '')
print("\n" * 14)
cmd_RobCo.char("TERMINAL LOCKED".center(var_RobCo.centre, " "))
termS_RobCo.empty()
cmd_RobCo.char("PLEASE CONTACT AN ADMINISTRATOR".center(var_RobCo.centre))
termS_RobCo.empty()
time.sleep(10)
cmd_RobCo.char("RESTARTING OS_SYSTEM")
sys_RobCo.log(3, 84, '')
os.system("sudo shutdown -h now")
def getWords():
secretPassword = random.choice(WORDS)
words = [secretPassword]
while len(words) < 3:
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) == 0:
words.append(randomWord)
for b in range(500):
if len(words) == 5:
break
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) == 3:
words.append(randomWord)
for b in range(500):
if len(words) == 12:
break
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) != 0:
words.append(randomWord)
while len(words) < 12:
randomWord = getOneWordExcept(words)
words.append(randomWord)
assert len(words) == 12
return words
def getOneWordExcept(blocklist=None):
if blocklist is None:
blocklist = []
while True:
randomWord = random.choice(WORDS)
if randomWord not in blocklist:
return randomWord
def numMatchingLetters(word1, word2):
matches = 0
for a in range(len(word1)):
if word1[a] == word2[a]:
matches += 1
return matches
def getComputerMemoryString(words):
linesWithWords = random.sample(range(16 * 2), len(words))
memoryAddress = 16 * random.randint(0, 4000)
computerMemory = []
nextWord = 0
for lineNum in range(16):
leftHalf = ''
rightHalf = ''
for j in range(16):
leftHalf += random.choice(var_RobCo.GARBAGE_CHARS)
rightHalf += random.choice(var_RobCo.GARBAGE_CHARS)
if lineNum in linesWithWords:
insertionIndex = random.randint(0, 9)
leftHalf = (leftHalf[:insertionIndex] + words[nextWord] + leftHalf[insertionIndex + 7:])
nextWord += 1
if lineNum + 16 in linesWithWords:
insertionIndex = random.randint(0, 9)
rightHalf = (rightHalf[:insertionIndex] + words[nextWord] + rightHalf[insertionIndex + 7:])
nextWord += 1
computerMemory.append('0x' + hex(memoryAddress)[2:].zfill(4)
+ ' ' + leftHalf + ' '
+ '0x' + hex(memoryAddress + (16 * 16))[2:].zfill(4)
+ ' ' + rightHalf)
memoryAddress += 16
return '\n'.join(computerMemory)
def askForPlayerGuess(words, tries):
while True:
cmd_RobCo.char('\nEnter password: ({} tries remaining)'.format(tries))
guess = input('> ').upper()
if guess in words:
return guess
cmd_RobCo.char('That is not one of the possible passwords listed above')
cmd_RobCo.char('Try entering "{}" or "{}".'.format(words[0], words[1]))
try:
main()
except KeyboardInterrupt:
sys.exit()
def t_inquire_sim(simulationText):
termS_RobCo.slide_up()
cmd_RobCo.char("ROBCO INDUSTRIES (TM) TERMLINK PROTOCOL \nENTER PASSWORD NOW")
with open(simulationText) as wordListFile:
WORDS = wordListFile.readlines()
for i in range(len(WORDS)):
WORDS[i] = WORDS[i].strip().upper()
def main():
input('\nPress enter to begin protocol...')
termS_RobCo.empty()
gameWords = getWords()
computerMemory = getComputerMemoryString(gameWords)
secretPassword = random.choice(gameWords)
cmd_RobCo.char(computerMemory)
for triesRemaining in range(4, 0, -1):
playerMove = askForPlayerGuess(gameWords, triesRemaining)
if playerMove == secretPassword:
cmd_RobCo.char("ACCESS GRANTED")
termS_RobCo.slide_up()
return
else:
numMatches = numMatchingLetters(secretPassword, playerMove)
cmd_RobCo.char('Access Denied ({}/7 correct)'.format(numMatches))
cmd_RobCo.char('Out of tries. Secret password was {}.'.format(secretPassword))
time.sleep(1)
def getWords():
secretPassword = random.choice(WORDS)
words = [secretPassword]
while len(words) < 3:
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) == 0:
words.append(randomWord)
for b in range(500):
if len(words) == 5:
break
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) == 3:
words.append(randomWord)
for b in range(500):
if len(words) == 12:
break
randomWord = getOneWordExcept(words)
if numMatchingLetters(secretPassword, randomWord) != 0:
words.append(randomWord)
while len(words) < 12:
randomWord = getOneWordExcept(words)
words.append(randomWord)
assert len(words) == 12
return words
def getOneWordExcept(blocklist=None):
if blocklist is None:
blocklist = []
while True:
randomWord = random.choice(WORDS)
if randomWord not in blocklist:
return randomWord
def numMatchingLetters(word1, word2):
matches = 0
for a in range(len(word1)):
if word1[a] == word2[a]:
matches += 1
return matches
def getComputerMemoryString(words):
linesWithWords = random.sample(range(16 * 2), len(words))
memoryAddress = 16 * random.randint(0, 4000)
computerMemory = []
nextWord = 0
for lineNum in range(16):
leftHalf = ''
rightHalf = ''
for j in range(16):
leftHalf += random.choice(var_RobCo.GARBAGE_CHARS)
rightHalf += random.choice(var_RobCo.GARBAGE_CHARS)
if lineNum in linesWithWords:
insertionIndex = random.randint(0, 9)
leftHalf = (leftHalf[:insertionIndex] + words[nextWord] + leftHalf[insertionIndex + 7:])
nextWord += 1
if lineNum + 16 in linesWithWords:
insertionIndex = random.randint(0, 9)
rightHalf = (rightHalf[:insertionIndex] + words[nextWord] + rightHalf[insertionIndex + 7:])
nextWord += 1
computerMemory.append('0x' + hex(memoryAddress)[2:].zfill(4)
+ ' ' + leftHalf + ' '
+ '0x' + hex(memoryAddress + (16 * 16))[2:].zfill(4)
+ ' ' + rightHalf)
memoryAddress += 16
return '\n'.join(computerMemory)
def askForPlayerGuess(words, tries):
while True:
cmd_RobCo.char('\nEnter password: ({} tries remaining)'.format(tries))
guess = input('> ').upper()
if guess in words:
return guess
cmd_RobCo.char('That is not one of the possible passwords listed above')
cmd_RobCo.char('Try entering "{}" or "{}".'.format(words[0], words[1]))
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit()