This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] : |