-
Notifications
You must be signed in to change notification settings - Fork 18
/
get_answer.py
125 lines (96 loc) · 2.83 KB
/
get_answer.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
#!/usr/bin/env python
# encoding: utf-8
import os
import magic
import base64
import lzma
from datetime import datetime
import re
import uu
import sys
import gzip
"""
gist: https://gist.github.com/zealic/38510fd8ecd1be75924a
zhihu: https://www.zhihu.com/question/28582088
"""
def get_content(fname):
# import requests
# gist_url = 'https://gist.github.com/zealic/38510fd8ecd1be75924a/raw/87260ec7f785bd869289387640a8b0356c59b9f5/Roman%2520Hitman'
# data = requests.get(gist_url).content
with open(fname) as f:
data = f.read()
return data
def b64decode(data):
return base64.b64decode(data)
def save_to_file(fname, data):
with open(fname, 'w') as f:
f.write(data)
def check_file_type(data):
return magic.from_buffer(data)
def lzop_decompress(fname):
# lzo.decompress(data)
os.popen('lzop -fd %s' % fname)
de_fname = os.path.splitext(fname)[0]
# data = open(de_fname).read()
data = ''.join(open(de_fname).readlines()[2:]).strip()
os.remove(de_fname)
os.remove(fname)
return data
def lzma_decompress(data):
return lzma.decompress(data)
def caesar_decode(data, num=47):
res = ''
for x in data:
if x in (' ', '\n'):
tmp = x
elif 32 <= (ord(x) + num) <= 126:
tmp = chr(ord(x) + num)
else:
tmp = chr(ord(x) - num)
res += tmp
return res
def get_group_number(data):
text = re.findall(r'Group number.*\((.*)\).*', data)[0].split()
group_number = ''
for x in text:
if x[0] == 'D':
group_number += str(int(x[1:]))
elif x[0] == 'O':
group_number += str(int(x[1:], 8))
elif x[0] == 'B':
group_number += str(int(x[1:], 2))
return group_number
def fib(n):
if n == 0:
return 0
if n <= 2:
return 1
return fib(n - 1) + fib(n - 2)
def get_q1_answer():
"""The answer to life, the universe, and everything?
"""
return 42
def get_q2_answer():
return fib(10)
def get_q3_answer():
"""XXX sensitive day and datetime now format
"""
return datetime(1989, 6, 4).strftime('%m%d') + \
datetime.now().strftime('%d%M')
if __name__ == '__main__':
in_file = 'Question.txt'
out_file = 'questions.bin'
uu.decode(in_file, out_file=out_file, mode='wb')
data = open(out_file).read()
data = lzma_decompress(data)
data = base64.b64decode(''.join(data.split('\n')[2:]))
save_to_file(out_file, data)
data = gzip.open(out_file).read()
os.remove(out_file)
question = caesar_decode(data)
group_number = get_group_number(question)
verify_code = 'Z%s%s%s' % (get_q1_answer(), get_q2_answer(), get_q3_answer())
print(question)
print('QQ group number: %s' % group_number)
print('QQ verify code: %s' % verify_code)
# print('抱歉,群主不让说。。')