Skip to content

Instantly share code, notes, and snippets.

View daemoncub's full-sized avatar

Raneem Almanon daemoncub

View GitHub Profile
@daemoncub
daemoncub / decrypt.py
Last active August 8, 2025 12:10
Efficient Exchange
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import hashlib
import my_EC_calculation as EC_shared_secret
def is_pkcs7_padded(message):
padding = message[-message[-1]:]
return all(padding[i] == len(padding) for i in range(0, len(padding)))
import hashlib
def P_at_O(P):
x, y = P
s=s_double(x,y)
x3,y3=point(s,x,x,y)
n=2
while(x3 != x):
def scalar_mul(n, P):
Q = P
R = [8045, 2803] # when prev calculated P = O for the same equation mod p --> E(Fp)
while(n > 0):
if pow(n,1,2) == 1 :
R = add(R, Q)
Q = double(Q)
n //= 2
return R
def equation_satisfy(x, y):
rh = (pow(x, 3)+ (x*a) + b) % p
lh = y**2 % p
return lh,rh
def point_add(P,Q):
if P[0]==PO[0] and P[1] != PO[1] : # well thankfully the prev chall (a quick reminder:) we had to calaculate P=O and i setup a loop that adds P to itself n times (all points mod Fp) basically until an error (logical) would accure i knew it would be right at the order of P (O) modulo p (O the point at infinity yeah? unsolvable) and guess what the error is that no modular inverse of x1-x2 when calculating the slope between the two added points, why? cz x1 = x2 (while y1 != y2) , this at the 3243th P addition.. at first i thought i abt doing this so then i would compare but that just contradict with the `efficient point addition algorithm` anyways this x2 the 3243P point is second solution of three for the cubic x , the third? is that point at infinity
return Q
if Q[0]==PO[0] and Q[1] != PO[1] :