Skip to content

Instantly share code, notes, and snippets.

@ducnhse130201
Created April 28, 2019 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducnhse130201/4cabf6c4031d528e2aae5543c7e6d521 to your computer and use it in GitHub Desktop.
Save ducnhse130201/4cabf6c4031d528e2aae5543c7e6d521 to your computer and use it in GitHub Desktop.
crypto1_solve_matess3r4
from telnetlib import *
import json
from libnum import *
r = Telnet('125.235.240.166', 13338)
def get_pub():
r.read_until("Your choice: ")
r.write("4\n")
r.read_until("Pubkey: ")
pub = json.loads(r.read_until("\n").strip())
return int(pub["N"]),int(pub["e"])
def enc(data):
r.read_until("Your choice: ")
r.write("1\n")
r.read_until("Your message: ")
r.write(data + "\n")
r.read_until("Your cipher: ")
cipher = r.read_until("\n").strip()
r.read_until("Your cipher_flag: ")
flag_enc = r.read_until("\n").strip()
return int(cipher),int(flag_enc)
def dec(enc_data):
r.read_until("Your choice: ")
r.write("2\n")
r.read_until("Your cipher: ")
r.write(enc_data + "\n")
r.read_until("Decrypted message: ")
dec_mess = r.read_until("\n").strip()
return int(dec_mess)
c,c_flag = enc("ducbanhmihehekakapepejjjjj")
n,e = get_pub()
m = s2n("ducbanhmihehekakapepejjjjj")
k = pow(m,e*m,n)
enc_flag =int(c_flag * invmod(k,n) % n)
print n2s(dec(str(enc_flag)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment