Created
January 23, 2019 12:43
-
-
Save rugo/67985e1b158933f0a9501e1c2f65e30f to your computer and use it in GitHub Desktop.
Insomnihack Drinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import base64 | |
import requests | |
import string | |
SEARCHSP = list("_" + string.printable[:-6]) | |
PAD = string.ascii_lowercase + "!§$%&()=?-:;#'+*<>|" | |
MAX_LEN = 40 | |
for c in PAD: | |
if c in SEARCHSP: | |
SEARCHSP.remove(c) | |
def gen_pad(l): | |
a = random.randint(0, len(PAD)-l) | |
return PAD[a:a+l] | |
def convert_to_hex(p): | |
return base64.b64decode("".join(p.split("\n")[2:-3])).hex() | |
def get_enc(recipient, drink): | |
r=requests.post('http://localhost:5000/generateEncryptedVoucher',json={'recipientName': recipient, 'drink': drink}) | |
return r.text | |
def get_uncompressed_len(PREFIX): | |
while True: | |
l_high_ent = [] | |
for i in range(20): | |
l_high_ent.append(convert_to_hex(get_enc(PREFIX + gen_pad(MAX_LEN - len(PREFIX)), "beer"))) | |
len_ct = len(l_high_ent[0]) | |
for p in l_high_ent: | |
if len(p) != len_ct: | |
break | |
else: | |
break | |
return len_ct | |
KNOWN = "||G1MME_B33R_" | |
len_ct = get_uncompressed_len(KNOWN) | |
print("Ciphertext len without compression: ", len_ct) | |
num = 0 | |
for _ in range(26): | |
for c in string.ascii_uppercase + "_0123456789": | |
pw = KNOWN + c + PAD[:MAX_LEN - len(KNOWN) - 1] | |
test = convert_to_hex(get_enc(pw, "beer")) | |
num += 1 | |
if len(test) < len_ct: | |
len_ct = len(test) | |
print(len(test)) | |
KNOWN += c | |
print(KNOWN) | |
continue | |
print(len(test)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment