import base64,hmac,hashlib,json
from flask import Flask,request,logging
app = Flask(__name__)

secret_key='NotASecret'
def sha256hex(data):
    sha256 = hashlib.sha256()
    sha256.update(data)
    res = sha256.digest()
    return res
def gd_loadgen_compute(msg):
    try:
        smsg=base64.b64decode(msg)
    except Exception:
        smsg=''.encode()
    for i in range(5):
        smsg = sha256hex(smsg)
        temp = bytearray(smsg)
        smsg = bytes(temp[:31])
    return base64.b64encode(smsg)
def hmac_compute(msg):
    return base64.b64encode(hmac.new(secret_key.encode(), msg.encode(), digestmod="SHA256").digest())
@app.route('/calc',methods = ['POST', 'GET'])
def calc_page():
    return gd_loadgen_compute(request.args.get('input')),'{text/plain; charset=utf-8}'
@app.route('/',methods = ['POST', 'GET'])
def main_page():
    return "TODO: Create a nice looking homepage."

if __name__ == '__main__':
   app.run(host="0.0.0.0",port=80)