This repository has been archived by the owner on Nov 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
61 lines (56 loc) · 1.52 KB
/
server.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
import random, time
s = "1234567890"
timeout = 60
codes = 15
tries = 8
print('''GAVPHONE REMOTE UTILITY
Phone is locked with several 4-digit codes.
For each your try it says two numbers:
1) number of right digits at right place
2) number of right digits at wrong place
For example, if code is 1234 and you typed 3624, phone response will be 1 2
All digits are different. You have only {} tries for one code else it will send rescue signal and dogs will find us.
You have a minute for all codes'''.format(tries))
solved = 0
startTime = time.time()
for i in range(codes):
print("Key #{:>02d}".format(i+1))
code = ''.join(random.sample(s, 4))
guess = False
for _ in range(tries):
print(">>> ", end='')
idea = input().strip()
if len(idea) != 4:
print("Error: bad input")
break
corr = 0
coll = 0
bad = False
for i in range(4):
if not(idea[i]) in s:
bad = True
elif idea[i] == code[i]:
corr += 1
elif idea[i] in code:
coll += 1
if bad:
print("Error: bad input")
break
print(corr, coll)
if corr == 4:
guess = True
break
left = timeout - (time.time() - startTime)
if left < 0:
print("Time is out :( No flag for you")
break
elif guess:
solved += 1
print("Good work! You have {:.1f} seconds left".format(left))
else:
print("Failed :( The code was ", code)
break
if solved == codes:
print("Good job! Here's your flag: uctfimp0ssibletosolve")
else:
print("Sorry, you haven't completed the mission.")