forked from thepythonclub/answer-submissions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collaborative_solutions.py
128 lines (119 loc) · 3.24 KB
/
collaborative_solutions.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
from PythonClub.PythonClub import PythonClub
import base64
class challenge_one(PythonClub):
'''
Example challenge: I am Jack's base64 encoded string: "c2Zhb3psenJ0YmRxcmp2cW95c3Z2dXBweHNlY2hhcHo=" -> sfaozlzrtbdqrjvqoysvvuppxsechapz
'''
def __init__ (self, ):
PythonClub.__init__(self, 1)
def solution(self):
return base64.b64decode(self.getChallenge()[36:-1])
#verbose solution
'''
#get the string representation of the challenge
challenge = self.getChallenge()
#we only need character 36 to one minus the last character to decode the base64 string
_slice = challenge[36:-1]
#return the answer
return base64.b64decode(_slice)
'''
class challenge_two(PythonClub):
'''
I am Jack's unsolved equation: "one plus six plus ten equals ?"
'''
def __init__ (self):
PythonClub.__init__(self, 2)
self.num_words= '''Zero
One
Two
Three
Four
Five
Six
Seven
Eight
Nine
Ten
Eleven
Twelve
Thirteen
Fourteen
Fifteen
Sixteen
Seventeen
Eighteen
Nineteen
Twenty
Twenty-one
Twenty-two
Twenty-three
Twenty-four
Twenty-five
Twenty-six
Twenty-seven
Twenty-eight
Twenty-nine
Thirty
Thirty-one'''
self.operators = ['plus', 'minus']
self.total = 0
self.token = 'plus'
def textMath(self, li):
num2words = {}
words2num={}
ls = self.num_words.split()
for i in range(len(ls)):
#print ls[i]
num2words[i]=ls[i].lower()
words2num[ls[i].lower()]=i
for i in range(len(li)):
#even indcies are integers
if i % 2 == 0:
if self.token == 'plus':
self.total += words2num[li[i]]
else:
self.total -= words2num[li[i]]
#odd indicies are the operators
else:
self.token = li[i]
#print self.total
return num2words[self.total]
def solution(self):
return self.textMath(self.getChallenge()[32:-10].split())
#verbose solution
'''
challenge = self.getChallenge()
#print challenge
ls = challenge[32:-10]
print ls
result= self.textMath(ls.split())
#print result
return result
'''
import re
import requests
import json
import base64
class challenge_three(PythonClub):
'''
Example: I am Jack's desired password for: "Jonathan" -> GREATpirate4
'''
def __init__ (self, ):
PythonClub.__init__(self, 3)
def solution(self):
text = self.getChallenge()
user=re.search(r':\s+"(\w+)"', text).group(1)
users = "http://thepythonclub.org/tmp/"+re.search(r'(user\w+.json)', text).group(1)
users = json.loads(requests.get(users).text)
uid = None
for uuid in users:
if users[uuid]['Name']== user:
uid= uuid
continue
pwd = "http://thepythonclub.org/tmp/"+re.search(r'(pass\w+.json)', text).group(1)
pwds = json.loads(requests.get(pwd).text)
return base64.b64decode(pwds[uid])
if __name__ == "__main__":
print challenge_one().submit()
print challenge_two().submit()
print challenge_three().submit()