Challenges
Scalar multiplication: double-and-add
Cryptography
Medium
Scalar multiplication
Solves: 5
Scalar multiplication: double-and-add
Author: CyberSamSU
Points
30
k·P means adding P to itself k times. But if k is a 15-digit number, adding k times will take a lifetime. The solution is the double-and-add algorithm: we use the binary representation of k.
def mul(k, P):
R = None # cheksizlikdagi nuqta O
Q = P
while k:
if k & 1:
R = add(R, Q)
Q = add(Q, Q) # ikkilantirish
k >>= 1
return R
This algorithm works proportionally to the number of bits of k: ~50 operations for a 15-digit number, ~380 operations for a 256-bit number. This is exactly what makes ECC practical.
Curve parameters:
p = 1098468064591
a = 769028742397
b = 244606442593
G = (494479121669, 79857172577)
k = 824859232408359
Calculate the point Q = k·G.
Test values to check your code:
2G = (1003950165171, 134579601300)
3G = (580092589564, 420105781590)
10G = (562678552088, 53852536727)
Answer: the coordinates of the point in the format x,y — first x, then a comma, then y (e.g. 1234,5678).
To submit a flag, log in.