Skip to content

Instantly share code, notes, and snippets.

@Lincest
Created March 24, 2021 04:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Lincest/4f59372764e9f6fd4bdaa4fd50869812 to your computer and use it in GitHub Desktop.
查找bilibili匿名弹幕
#include <bits/stdc++.h>
using namespace std;
#define CRCPOLYNOMIAL 0xEDB88320
vector<unsigned long> crc_table(255, 0);
string buffer;
void get_crc_table() {
unsigned long crc;
int i, j;
for (i = 0; i < 256; ++i) {
crc = i;
for (j = 0; j < 8; ++j) {
if ((crc & 1) != 0) {
crc = (crc >> 1) ^ CRCPOLYNOMIAL;
} else {
crc >>= 1;
}
}
crc_table[i] = crc;
}
}
unsigned long get_crc_index() {
unsigned long start = 0xffffffff, len = buffer.length(), index;
for (int i = 0; i < len; ++i) {
index = (start ^ buffer[i]) & 0xff;
start = (start >> 8) ^ crc_table[index];
}
return start ^ 0xffffffff;
}
unsigned long hex_char(const char &a) {
if (a >= 48 && a <= 57) {
return a - 48;
} else if (a >= 65 && a <= 70) {
return a - 55;
} else {
return a - 87;
}
}
unsigned long hex_str_to_unsigned(string hashid) {
unsigned long ans, len = hashid.size();
for (unsigned long i = 0; i < len; ++i) {
unsigned long x = hex_char(hashid[i]);
for (unsigned long j = 0; j < len - 1 - i; ++j) {
x *= 16;
}
ans += x;
}
return ans;
}
int main() {
get_crc_table();
while (true) {
cout << "please input the hash id: ";
string hashid;
cin >> hashid;
unsigned long target = hex_str_to_unsigned(hashid);
unsigned long i = 0;
cout << "start crack " << hashid << endl;
while (true) {
++i;
buffer = to_string(i);
if (get_crc_index() == target) {
cout << "find the uid: " << i << endl;
break;
}
if (i > 1000000000) {
printf("the uid doesn't exist\n");
}
}
string another;
cout << "another hash id? (y/n)" << endl;
cin >> another;
if (another == "y") continue;
else break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment