CopunCodeGenerator/k-i-e-3-ja-pun.py

35 lines
797 B
Python

#!/shebang
import json
import random
from base64 import b64decode, b64encode
from hashlib import sha512
from getch import getch, getche
def printf(*args, **kwargs):
print(*args, **kwargs, end='', flush=True)
def sign(msg, iv):
if type(msg) == str:
msg = msg.encode()
elif type(msg) != bytearray or type(msg) != bytes:
raise ValueError("Byte! m8!")
return b64encode(sha512(msg).digest() + sha512(iv).digest()).decode()
def main():
printf("Press any key to generate one.")
getch()
print()
ivb = getche().encode()
iv = ivb + random.randbytes(31)
msg = 'Pv!'
test = sign(msg, iv)
print(msg)
print(test)
print(json.dumps({'iv': sha512(iv).hexdigest(), 'msg' : msg, 'msg_hash': test}))
if __name__ == '__main__':
main()