fixed phew

This commit is contained in:
lightningitoid
2025-10-26 22:25:05 +07:00
parent 6b96a097c3
commit e0d2de93f2
3 changed files with 117 additions and 62 deletions
+39 -14
View File
@@ -1,31 +1,56 @@
#!/usr/bin/env python3
import signal
import os
from Pailier import *
from Crypto.Util.number import *
signal.alarm(50)
with open("/flag.txt", "rb") as f:
flag = f.read()
flag = bytes_to_long(flag)
flag_bytes = f.read()
key = os.urandom(66)
key_int = bytes_to_long(key)
cipher = pailier()
while True:
print("1. encrypt")
print("2. bingo")
print("3. decrypt")
print("4. exit")
print("4. key?")
inp = int(input("> "))
if inp==1:
if inp == 1:
print("pt (hex)")
inp = input("> ")
ct = cipher.encrypt(int(inp,16))
print('ct : ','{0:x}'.format(ct))
elif inp==2:
ct = cipher.encrypt(flag)
print('ct : ','{0:x}'.format(ct))
elif inp==3:
ct = cipher.encrypt(int(inp, 16))
print('ct : ', '{0:x}'.format(ct))
elif inp == 2:
print("key (hex)")
user_hex = input("> ").strip()
try:
user_key = bytes.fromhex(user_hex)
except Exception:
print("nope")
continue
if len(user_key) == 66 and user_key == key:
try:
print(flag_bytes.decode())
except Exception:
print(flag_bytes.hex())
else:
print("nope")
elif inp == 3:
print("ct (hex)")
inp = input("> ")
pt = cipher.decrypt(int(inp,16))
print('pt : ','{0:x}'.format(pt))
pt = cipher.decrypt(int(inp, 16))
print('pt : ', '{0:x}'.format(pt))
elif inp == 4:
ct = cipher.encrypt(key_int)
print('ct : ', '{0:x}'.format(ct))
else:
exit()
+39 -14
View File
@@ -1,31 +1,56 @@
#!/usr/bin/env python3
import signal
import os
from Pailier import *
from Crypto.Util.number import *
signal.alarm(50)
with open("/flag.txt", "rb") as f:
flag = f.read()
flag = bytes_to_long(flag)
flag_bytes = f.read()
key = os.urandom(66)
key_int = bytes_to_long(key)
cipher = pailier()
while True:
print("1. encrypt")
print("2. bingo")
print("3. decrypt")
print("4. exit")
print("4. key?")
inp = int(input("> "))
if inp==1:
if inp == 1:
print("pt (hex)")
inp = input("> ")
ct = cipher.encrypt(int(inp,16))
print('ct : ','{0:x}'.format(ct))
elif inp==2:
ct = cipher.encrypt(flag)
print('ct : ','{0:x}'.format(ct))
elif inp==3:
ct = cipher.encrypt(int(inp, 16))
print('ct : ', '{0:x}'.format(ct))
elif inp == 2:
print("key (hex)")
user_hex = input("> ").strip()
try:
user_key = bytes.fromhex(user_hex)
except Exception:
print("nope")
continue
if len(user_key) == 66 and user_key == key:
try:
print(flag_bytes.decode())
except Exception:
print(flag_bytes.hex())
else:
print("nope")
elif inp == 3:
print("ct (hex)")
inp = input("> ")
pt = cipher.decrypt(int(inp,16))
print('pt : ','{0:x}'.format(pt))
pt = cipher.decrypt(int(inp, 16))
print('pt : ', '{0:x}'.format(pt))
elif inp == 4:
ct = cipher.encrypt(key_int)
print('ct : ', '{0:x}'.format(ct))
else:
exit()