Skip to content

Instantly share code, notes, and snippets.

@17
Created July 9, 2016 19:55
Show Gist options
  • Save 17/7f3f8e0d4f564d03f6a626cf6491c540 to your computer and use it in GitHub Desktop.
Save 17/7f3f8e0d4f564d03f6a626cf6491c540 to your computer and use it in GitHub Desktop.
Generate CRC32B UID Rainbow Tables
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
try:
xrange
except NameError:
xrange = range
from peewee import *
import zlib
import time
db = SqliteDatabase('rainbow_table.db')
class Crc32b(Model):
key = IntegerField(primary_key=True)
hash = CharField()
class Meta:
database = db
def create_tables():
db.connect()
db.create_tables([Crc32b], safe=True)
def mhash_crc32b(data):
return format(zlib.crc32(str(data).encode('ascii')) & 0xFFFFFFFF, 'x').rjust(8, '0')
if __name__ == '__main__':
create_tables()
build_num = 40000001
list = []
for x in xrange(1, build_num):
list.append({
'key': x,
'hash': mhash_crc32b(x)
})
if len(list) == 10000:
# t = time.time()
with db.atomic():
for i in xrange(0, len(list), 100):
Crc32b.insert_many(list[i: i + 100]).execute()
# print(time.time() - t)
list = []
print('{0:%} - {1}'.format(x / build_num, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment