#!/usr/bin/python3

from datetime import datetime

CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
KEY_SIZE = 32
FIRST_SEED = 1354320000
LAST_SEED = 1356998400
DAY_DURATION = 86400
BZ2_HEADER = b'\x42\x5a\x68'

def gen_key(seed):
	rand = seed
	key = [0]*KEY_SIZE
	for i in range(KEY_SIZE):
		rand = (rand * 214013 + 2531011) & 0xffffffff
		rand2 = (rand >> 16) & 0x7fff
		key[i] = CHARSET[rand2 % len(CHARSET)]
	return key

def decipher_bz2(data, key):
	out = bytearray()
	for i in range(len(data)):
		if i > 3 and out[0:3] != BZ2_HEADER:
			return None
		out.append(data[i] ^ ord(key[i % KEY_SIZE]))
	return out

f = open("oDjbNkIoLpaMo.bz2.crypt", mode="rb")
data = f.read()
f.close()
seed = FIRST_SEED
print(datetime.fromtimestamp(seed))
while seed <= LAST_SEED:
	out = decipher_bz2(data, gen_key(seed))
	if out:
		f = open(f"out-{seed}.bz2", mode="wb")
		f.write(out)
		f.close()
	seed += 1
	if (seed - FIRST_SEED) % DAY_DURATION == 0:
		print(datetime.fromtimestamp(seed))
