Add 'k-i-e-3-ja-pun.py'
This commit is contained in:
parent
a8b9f63ebc
commit
d148501de0
1 changed files with 34 additions and 0 deletions
34
k-i-e-3-ja-pun.py
Normal file
34
k-i-e-3-ja-pun.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
#!/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()
|
Loading…
Reference in a new issue