-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcurvy-p.py
58 lines (45 loc) · 1.43 KB
/
curvy-p.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# craig for MCH2022 CTF
# first part only, we do a binary search for P
# second part: calculate a + b (https://github.com/jvdsn/crypto-attacks/blob/master/attacks/ecc/parameter_recovery.py ??)
# third part, smart attack (https://github.com/jvdsn/crypto-attacks/blob/master/attacks/ecc/smart_attack.py)
import argparse
import socket
import time
import random
import _thread
import datetime
import os
import sys
def sendstuff(host,port,sendstring):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
answer = sock.recv(1024)
sock.send(sendstring.encode())
answer = sock.recv(1024)
sock.close()
return(answer)
def binary_search(start, end):
low = start
high = end
mid = 0
while low <= high:
mid = (high + low) // 2
os.system("clear")
print("Hacking the gibson.")
print("high: %s" % high)
print(" low: %s" % low)
print(" mid: %s" % mid)
# If x is greater, ignore left half
result=sendstuff("curvy.ctf.zone",6011,str(mid))
if str(result).find("Nope")>0:
low = mid + 1
# If x is smaller, ignore right half
elif str(result).find("Sorry")>0:
high = mid - 1
# means x is present at mid
else:
return mid
# If we reach here, then the element was not present
return -1
binary_search(1,1000000000000000000000000000000000000)