repl.it
@heyitsmarcus/

Final Project (Hack)

Python

No description

fork
loading
Files
  • main.py
main.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import random
import time
import colorama
from colorama import init, Fore, Back, Style
init(autoreset=True)
#Player Variables
stage = 0
failures = 0
cash = 99999
inv = []
#Shop Variables
RevealerStock = 1
BoosterStock = 1
SentryStock = 1
#Guesser Variables
words1 = ['cat','pass','dog','yes','word','car']
words2 = ['river','friend','hello','garbage','kitty']
words3 = ['everest','cambodia','lynx','vixen','classroom']

#Name: Guesser
#Purpose: play minigame to hack node 
#Inputs: difficulty
#Returns: either 1 for a success or 0 for a failure
def guesser(difficulty):
  global words1, words2, words3 
  if 'sentry' in inv:
    if difficulty > 1:
      difficulty -= 1
  print(difficulty)
  if difficulty == 1:
    target = random.choice(words1)
    maxtries = 7
  elif difficulty == 2:
    target = random.choice(words2)
    maxtries = 6
  elif difficulty == 3:
    target = random.choice(words3)
    maxtries = 5
  print(Fore.RED + 'THE PASSWORD IS {} LETTERS LONG'.format(len(target)))
  if 'booster' in inv:
    maxtries += 3
  if 'revealer' in inv:
    print(Fore.RED + 'REVEALER HAS FOUND THE FIRST LETTER TO BE {}'.format(target[0]))
  tries = 0
  while True:
    while True:
      guess = input(Fore.RED + 'BREAK PASSWORD: ').lower()
      if len(guess) == len(target):
        break
      else:
        print('INVALID LENGTH')
    green = 0
    blue = 0
    for i in range(len(target)):
      if tries == maxtries:
        return 0
      if guess == target:
        return 1
      elif guess[i] == target[i]:
        green += 1
      elif guess[i] in target:
        blue += 1
      if tries == maxtries:
        print(Fore.RED + 'ACCESS DENIED, FIREWALL ACTIVATED')
        return 0
    tries += 1
    print(Fore.GREEN + 'GREEN: ' + str(green))
    print(Fore.BLUE + 'BLUE: ' + str(blue))
    print(Fore.RED + 'YOU HAVE {} ATTEMPTS REMAINING'.format(maxtries - tries))
#Name: shop
#Purpose: sells items to user
#Inputs: none
#Returns: none
def shop():
  global BoosterStock
  global RevealerStock
  global SentryStock
  print('[1] REVEALER:\n   REVEAL THE FIRST LETTER OF EACH NODE')
  if RevealerStock == 0:
    print(Fore.RED + '  OUT OF STOCK')
  print('[2] BOOSTER:\n   GIVES MORE ATTEMPTS BEFORE LOCKOUT')
  if BoosterStock == 0:
    print(Fore.RED + '  OUT OF STOCK')
  print('[3] SENTRY:\n   LOWERS DIFFICULTY')
  if SentryStock == 0:
    print(Fore.RED + 'OUT OF STOCK')
  print('[4] BACK')
  print('CASH: {}'.format(cash))
  sel = str(input())
  if sel == '1':
    if RevealerStock != 0 and cash >= 150:
      print('SALE SUCCESSFUL')
      inv.append('revealer')
    else:
      print('INVALID, EITHER OUT OF STOCK OR NOT ENOUGH CASH')
  elif sel == '2':
    if BoosterStock != 0 and cash >= 200:
      print('SALE SUCCESSFUL')
      inv.append('booster')
      BoosterStock = 0
    else:
      print('INVALID, EITHER OUT OF STOCK OR NOT ENOUGH CASH')
  elif sel == '3':
    if SentryStock != 0 and cash >= 350:
      print('SALE SUCCESSFUL')
      inv.append('sentry')
    else:
      print('INVALID, EITHER OUT OF STOCK OR NOT ENOUGH CASH')
  elif sel == '4':
    pass
#Name: bar
#Purpose: get new missions
#Returns: none
#Inputs: none
def bar():
  if failures == 5:
    print('You are approached by soldiers of the High Justiciar. You are captured and executed for treason.' + Fore.RED + ' GAME OVER')
    quit()
  if stage == 0:
    print('Check your e-mail first')
    return 1
  print("[1] RANDOM MISSION\n [2] STORY MISSION")
  inp = input()
  if inp == '1':
    dif = int(input('CHOOSE DIFFICULTY (1-3): '))
    random_mission(dif)
  if inp == '2':
    if stage == 1:
      print(Fore.RED + 'You are approached by the rebel leader ' + Style.RESET_ALL + 'Hey, we   have a mission for you. Small one, but important.\n[1] ACCEPT\n[2] BACK')
      inp = input()
      if inp == '1':
        terracorp()
      elif inp == '2':
        pass
    elif stage == 2:
      print(Fore.RED + 'The Rebel Leader approaches you.' + Style.RESET_ALL + 'Good job on   that last mission. We uncovered a major weakness in the main security company of the   Justiciar\nBreach it and sabotage the system\n[1] ACCEPT\n[2] BACK')
      inp = input()
      if inp == '1':
        aegis()
      elif inp == '2':
        pass
    elif stage == 3:
      print(Fore.RED + 'You are approached by an unknown man' + Style.RESET_ALL + 'I have   heard a lot about you. Jezebel was killed. But it does not matter. We cant let her   sacrifice be in vein. The time is now, the systems of Justiciar Command are open. This is up to you now.\n[1] ACCEPT\n[2] BACK')
      inp = input()
      if inp == '1':
        justiciar()
      elif inp == '2':
        pass
#Name: nodemap
#Purpose: generate hacking targets for missions
#Inputs: size, which determines size of the map, and difficulty, which determines the difficulty of the nodes
#returns: 1 for success and 0 for failure
def nodemap(size,difficulty):
  w = 0
  f = 0
  nmap = []
  nodes = 0
  breach_targets = []
  for i in range(size):
    nappend = random.randint(1,2)
    if nappend == 1 and nodes < size/4:
      nmap.append('X')
      nodes += 1
    else:
      nmap.append('-')
  for i in range(len(nmap)):
    if nmap[i] == 'X':
      breach_targets.append(nmap[i])
  for x in range(len(breach_targets)):
    print(nmap)
    print(Fore.RED + 'ATTEMPTING TO BREACH NODE NUMBER {}'.format(x))
    hack = guesser(difficulty)
    if guesser == 1:
      breach_targets[x] = 'W'
      print(Fore.RED + 'NODE {} BREACHED SUCCESSFULLY'.format(x))
    elif hack == 0:
      breach_targets[x] = 'F'
      print(Fore.RED + 'FAILED TO BREACH NODE, FIREWALL PROGRESS INCREASED'.format(x))
    for x in range(len(breach_targets)):
     if breach_targets[x] == 'W':
      w += 1
     elif breach_targets[x] == 'F':
      f += 1
  if max(w,f) == w:
    return 1
  else:
    return 0
#name: email
#purpose: read story emails
#inputs: None
#returns: none
def email():
  global stage
  print('[0] BACK')
  print('[1] SENDER: [email protected]\nSUBJECT: Welcome, Initiate')
  if stage >= 1:
    print('[2] SENDER: [email protected]\nSUBJECT: TerraCorp')
  if stage >= 2:
    print('[3] SENDER: [email protected]\nSUBJECT: Systems Vulerability')
  if stage >= 3:
    print('[4] SENDER: [email protected]\n SUBJECT: Fate of the Resistance')
  inp = input('')
  if inp == 0:
    return 1
  elif inp == '1':
    print('Welcome to the Resistance, Initiate. First of all, when you breach a node you will have to crack a password. Our program will tell you what letters are correct and in the right position - greens - and letters that are correct in the WRONG position - blues. Secondly, you can go to the shop in between missions to purchase things that will help you breach networks more effectively. Make sure to check your e-mail often. Good luck.\n-Jezebel Hawkins')
    if stage == 0:
      stage += 1
  elif inp == '2' and stage >= 1:
    print("We have a mission for you: small environmental agency. We've discovered that it's actually a front for the Justiciar Intelligence. We need you to breach the systems. More information will be delivered upon starting. Good luck")
  elif inp == '3' and stage >= 2:
    print('Congratulations on your promotion! You are now officially a Knight of the Resistance! In celebration, we have a more difficult mission to give you. A major vulnerability in the defense systems of Justiciar Command has been discovered. Breach it, and we might have a chance at central command. Good luck')
  elif inp == '4' and stage >= 3:
    print('Hello, Knight. I have some bad news - Jezebel was captured by Justiciar soldiers yesterday. I can only assume she was executed. But, we must continue. We finally gained access to central command. This is up to you. Good luck, and glory to the Resistance')

#Name: terracorp
#Purpose: initiate the first mission (these are mainly for story)
#Inputs: none
#Returns: none
def terracorp():
  global cash
  global stage
  global failures
  print(Fore.BLUE + "TerraCorp is a small environmental company. Our espionage suggests that it is actually a front company for the Justiciar Secret Service. Breach it, and acquire any documents that may help us prove this. Shut down their network while you're in there, would you?")
  time.sleep(2)
  print(Fore.RED + 'TERRACORP SYSTEMS BREACHED, INITIATING PASSWORD CRACKER')
  mission = nodemap(8,1)
  if mission == 1:
    print(Fore.GREEN + 'Mission Successful. Congratulations.')
    cash += 75 
    stage += 1
  elif mission == 0:
    print(Fore.RED + 'They caught us. We can try again, but this will be a huge setback')
    failures += 1
  time.sleep(1)
#name: aegis
#purpose: initiate the second mission
#inputs: none
#returns: none
def aegis():
  global cash
  global stage
  global failures
  print(Fore.BLUE + "AEGIS is the cybersecurity company of High Command. We've discovered a severe vulnerability in their firewall. Exploit this, and bring them down for good.")
  time.sleep(2)
  print(Fore.RED + "AEGIS DEFENSE SYSTEM OFFLINE, PASSWORD CRACKER INITIATED")
  mission = nodemap(16,2)
  if mission == 1:
    print(Fore.GREEN + 'Mission Successful. Congratulations, Knight')
    stage += 1
  elif mission == 0:
    print(Fore.RED + "We're locked out of the systems. It'll take some time to get back in.")
    failures += 1
  time.sleep(1)
#name: justiciar
#purpose: initiate the last mission
#inputs: none
#returns: none
def justiciar():
  global cash
  global stage
  global failures
  print(Fore.BLUE + 'This is it. Breach the system of Justiciar Command and free us all from her tyrrany once and for all. Glory to the resistance')
  time.sleep(2)
  print(Fore.RED + 'JUSTICIAR COMMAND BREACHED, ACTIVATING PASSWORD CRACKER')
  mission = nodemap(32,3)
  if mission == 1:
    print('We did it! The people are finally free of this nightmare. ' + Fore.GREEN + 'GLORY TO THE RESISTANCE')
  elif mission == 0:
    print(Fore.RED + 'We got locked out. This will be a huge setback')
    failures += 1
def random_mission(difficulty):
  global cash
  global failures
  mission = nodemap(random.randint(4,32),difficulty)
  if mission == 1:
    print(Fore.GREEN + 'Mission Success')
    if difficulty == 1:
      cash += 50
    elif difficulty == 2:
      cash += 100
    elif difficulty == 3:
      cash += 170
  elif mission == 0:
    print(Fore.RED + 'Mission Failed')
    failures += 1
#Name: main_menu
#Purpose: navigate the main menu and call functions
#Returns: none
#Inputs: none
def main_menu():
  print(Fore.RED + '[1] E-MAIL\n[2] SHOP\n[3] BAR\n[4] ITEMS')
  inp = input('')
  if inp == '1':
    email()
  elif inp == '2':
    shop()
  elif inp == '3':
    bar()
  elif inp == '4':
    print(inv)
while True:
  main_menu()