Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit 09ab24a

Browse files
committed
initial commit
0 parents  commit 09ab24a

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# crc32Cracker
2+
> 反查B站弹幕发送者
3+
4+
## 使用
5+
```shell
6+
python main.py [crc32hash]
7+
```
8+
9+
### 示例
10+
```shell
11+
python main.py 76B81C71
12+
```
13+
#### 结果
14+
```
15+
160148624 0.7555286884307861
16+
```
17+
第一个数为发送者mid,第二个数为用时。
18+
19+
20+
## 鸣谢
21+
算法作者:[MoePus](https://github.com/MoePus)
22+
文章:https://moepus.oicp.net/2016/11/27/crccrack/

main.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
POLY = 0xEDB88320
2+
3+
4+
class crc32Cracker:
5+
def __init__(self):
6+
self.table = self.table()
7+
8+
def crc32(self, string: str) -> (int, int):
9+
INIT = 0xFFFFFFFF
10+
index = None
11+
for i in string:
12+
index = (INIT ^ ord(i)) & 0xFF
13+
INIT = INIT >> 8 ^ self.table[index]
14+
return INIT, index
15+
16+
def lastIndex(self, crc: int) -> int:
17+
for i in range(256):
18+
if crc == self.table[i] >> 24:
19+
return i
20+
21+
def check(self, high: int, indexes: list) -> (bool, str):
22+
crc, index = self.crc32(str(high))
23+
if index != indexes[3]:
24+
return False
25+
low = ''
26+
for i in range(2, -1, -1):
27+
num = crc & 0xFF ^ indexes[i]
28+
if num not in range(48, 58):
29+
return False
30+
low += str(num - 48)
31+
crc = self.table[indexes[i]] ^ crc >> 8
32+
return low
33+
34+
@staticmethod
35+
def table():
36+
table = []
37+
for i in range(256):
38+
value = i
39+
for _ in range(8):
40+
if value & 1:
41+
value = value >> 1 ^ POLY
42+
else:
43+
value >>= 1
44+
table.append(value)
45+
return table
46+
47+
def main(self, crc):
48+
indexes = [0 for _ in range(4)]
49+
crc = int(crc, 16) ^ 0xFFFFFFFF
50+
for i in range(1, 1000):
51+
if crc == self.crc32(str(i))[0]:
52+
return i
53+
for i in range(3, -1, -1):
54+
index = indexes[3 - i] = self.lastIndex(crc >> (i << 3))
55+
value = self.table[index]
56+
crc ^= value >> ((3 - i) << 3)
57+
i = 0
58+
while True:
59+
i += 1
60+
low = self.check(i, indexes)
61+
if low:
62+
return int(str(i) + low)
63+
64+
def __call__(self, crc):
65+
return self.main(crc)
66+
67+
68+
if __name__ == '__main__':
69+
from time import time
70+
from sys import argv
71+
72+
cracker = crc32Cracker()
73+
t = time()
74+
print(cracker(argv[1]), time() - t)

0 commit comments

Comments
 (0)