Skip to content
Snippets Groups Projects
Commit 67534b81 authored by Silas Dohm's avatar Silas Dohm
Browse files

parser added

parent 22dbd24c
No related branches found
No related tags found
No related merge requests found
#%%
import json
import requests
# %%
from Cryptodome import Random
from Cryptodome.Cipher import AES
import base64
from hashlib import md5
BLOCK_SIZE = 16
def pad(data):
length = BLOCK_SIZE - (len(data) % BLOCK_SIZE)
return data + (chr(length)*length).encode()
def unpad(data):
return data[:-(data[-1] if type(data[-1]) == int else ord(data[-1]))]
def bytes_to_key(data, salt, output=48):
# extended from https://gist.github.com/gsakkis/4546068
assert len(salt) == 8, len(salt)
data += salt
key = md5(data).digest()
final_key = key
while len(final_key) < output:
key = md5(key + data).digest()
final_key += key
return final_key[:output]
def encrypt(message, passphrase):
salt = Random.new().read(8)
key_iv = bytes_to_key(passphrase, salt, 32+16)
key = key_iv[:32]
iv = key_iv[32:]
aes = AES.new(key, AES.MODE_CBC, iv)
return base64.b64encode(b"Salted__" + salt + aes.encrypt(pad(message)))
def decrypt(encrypted, passphrase):
encrypted = base64.b64decode(encrypted)
assert encrypted[0:8] == b"Salted__"
salt = encrypted[8:16]
key_iv = bytes_to_key(passphrase, salt, 32+16)
key = key_iv[:32]
iv = key_iv[32:]
aes = AES.new(key, AES.MODE_CBC, iv)
return unpad(aes.decrypt(encrypted[16:]))
password = "9pSEhMHY8jOkTrSl46YgFWGIneUU".encode()
#%%
for month in range(12):
for day in range(1,32):
try:
url = "https://dutyfarm.welt.de/kreuzwortraetsel-html5-new/data/"+str(day)+"_"+str(month)+".cwr"
t = requests.get(url)
newDictionary=json.loads(t.text)
for i in range(len(newDictionary)-1): #decrypt answers
newDictionary[i]["answer"] = decrypt(newDictionary[i]["answer"],password).decode("utf-8")
newDictionary[-1]["solution"] = decrypt(newDictionary[-1]["solution"],password).decode("utf-8")
newDictionary[-1]["solutiondate"] = decrypt(newDictionary[-1]["solutiondate"],password).decode("utf-8")
newDictionary[-1]["solutionname"] = decrypt(newDictionary[-1]["solutionname"],password).decode("utf-8")
with open("archive_welt/"+str(month+1)+"_"+str(day)+".json", "w") as outfile:
json.dump(newDictionary, outfile)
except:
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment