I have the following Elliptic Curve:
y^2 = x^3 + 9x + 17 mod 23 (a = 9, b = 17, p = 23) with a base point G = (16,5)
With this information and using the private key PA = 10, how can I calculate the private key nA?
I know the equation is PA = nA * G, but I am not sure how to actually perform the calculation.
Based on your title, you can use SageMath to find it.
Assuming that the private key is 10, yes it is an integer between 1 and the order of the curve E.order().
The public key is then calculated as [10]G. Here [10] means add the G itself 10 times G+G+G+G+G+G+G+G+G+G. Note that this is not an ordinary addition of tuples. It is an elliptic curve point addition based on the tangent and chord rule.
E = EllipticCurve(GF(23),[9,17])
print(E)
print(E.order())
G = E(16,5)
print(10*G)
prints
Elliptic Curve defined by y^2 = x^3 + 9*x + 17 over Finite Field of size 23
32
(3 : 18 : 1)
Try online at SageMathCell and learn SageMath if you going to study cryptography. SageMath uses Python3 syntax, therefore easy to learn. And, here SageMath reference for Elliptic curves over finite fields and the tutorial of SageMath.
Related
Suppose E:y^2=x^3+Ax+B mod p, I have two questions?
how can I draw the graph of E with pari-gp.
how can I get the list of all points over the E.
thank you for all.
To define an Elliptic Curve with SageMath use
E = EllipticCurve(GF(131),[0,1,0,1,0])
print(E)
and outputs
Elliptic Curve defined by y^2 = x^3 + x^2 + x over Finite Field of size 131
In your case ( simplified Weierstrass from)
E = EllipticCurve(GF(p),[A,B])
will be enough.
To plot a curve
E.plot()
is enough
To iterate the points
for T in E.points():
print(T)
is enough.
Try online on SageMathCell.
And notice the symmetry!
Pari-GP
From a tutorial
a=ffgen(P,βa)
Es = ellinit([a^4,a^6],a);
The analysis with wavelets seems to be carried out as a discrete transform via matrix multiplication. So it is not surprising, I guess, that when plotting, for example, D4, the R package wmtsa returns the plot:
require(wmtsa)
filters <- wavDaubechies("d4")
plot(filters)
The question is how to go from this discretized plot to the plot in the Wikipedia entry:
Please note that I'm not interested in generating these curves precisely with wmtsa. Any other package will do - I don't have Matlab or Mathematica. But I wonder if the way to go is to start with translating this Mathematica chunk of code in this paper into R, rather than using built-in functions:
Wave1etTransform.m
c[k-1 := c[k] = Daubechies[4][[k+l]];
phi[l] = (l+Sqrt[3])/2 // N;
phi[2] = (l-Sqrt[3])/2 // N;
phi[xJ; xc=0 II x>=3] : = 0
phi[x-?NumberQ] := phi[x] =
N[Sqrt[2]] Sum[c[k] phi[2x-k],{k,0,3}];
In order to plot the wavelet and scaling function all you need are the four numbers shown in the first two plots. I'll focus on plotting the scaling function.
Integer shifts of the scaling function, π, form an orthonormal basis of the subspace V0 of the multiresolution analysis. We also have that V-1 β V0 and that π(x/2) β V-1. Using this gives us the identity
π(x/2) = βk β β€ hkπ(x-k)
Now we just need the values of hk. For the Daubechies wavelet these are the values show in the discrete plot you gave (and zero for every other value of k). For an exact value of the hk, first let π = (1+sqrt(3))/2. Then we have that
h0 = π/4
h1 = (1+π)/4
h2 = (2-π)/4
h3 = (1-π)/4
and hk = 0 otherwise.
Using these two things we are able to plot the function using what is known as the cascade algorithm. First notice that π(0) = π(0/2) = h0π(0) + h1π(0-1) + h2π(0-2) + h3π(0-3). The only way this equation can hold is if π(0) = π(-1) = π(-2) = π(-3) = 0. Extending this will show that for x β¦ 0 we have that π(x) = 0. Furthermore, a similar argument can show that π(x) = 0 for x β₯ 3.
Thus, we only need to worry about x = 1 and x = 2 to find non-zero values of π for integer values of x. If we put x = 2 into the identity for π(x/2) we get that π(1) = h0π(2) + h1π(1). Putting x = 4 into the identity gives us that π(2) = h2π(2) + h3π(1).
We can rewrite the above two equations as a matrix multiplied by a vector equals a vector. In fact, it will be in the form v = Av (v is the same vector on both sides). This means that v is an eigenvector of the matrix A with eigenvalue 1. But v = (π(1), π(2)) and so by finding this eigenvector using the standard methods we will be able to find the values of π(1) and π(2).
In fact, this gives us that π(1) = (1+sqrt(3))/2 and π(2) = (1-sqrt(3))/2 (this is where those values in the Mathematica code sample come from). Also note that we need to specifically chose the eigenvector of magnitude 2 for this algorithm to work so you must use those values for π(1) and π(2) even though you could rescale the eigenvector.
Now we can find the values of π(1/2), π(3/2), and π(5/2). For example, π(1/2) = h0π(1) and π(3/2) = h1π(2) + h2π(1).
With these values, you can then find the values of π(1/4), π(3/4), and so on. Continuing this process will give you the value of π for all dyadic rationals (rational numbers in the form k/2j.
The same process can be used to find the wavelet function. You only need to use the four different values shown in the first plot rather than the four shown in the second plot.
I recently implemented this Python. An R implementation will be fairly similar.
import numpy as np
import matplotlib.pyplot as plt
def cascade_algorithm(j: int):
mu = (1 + np.sqrt(3))/2
h_k = np.array([mu/4, (1+mu)/4, (2-mu)/4, (1-mu)/4])
# Array to store all the value of phi.
phi_vals = np.zeros((2, 3*2**j+1), dtype=np.float64)
for i in range(3*2**j+1):
phi_vals[0][i] = i/(2**j)
calced_vals = np.zeros((3*2**j+1), dtype=np.bool)
# Input values for 1 and 2.
phi_vals[1][1*2**j] = (1+np.sqrt(3))/2
phi_vals[1][2*2**j] = (1-np.sqrt(3))/2
# We now know the values for 0, 1, 2, and 3.
calced_vals[0] = True
calced_vals[1*2**j] = True
calced_vals[2*2**j] = True
calced_vals[3*2**j] = True
# Now calculate for all the dyadic rationals.
for k in range(1, j+1):
for l in range(1, 3*2**k):
x = l/(2**k)
if calced_vals[int(x*2**j)] != True:
calced_vals[int(x*2**j)] = True
two_x = 2*x
which_k = np.array([0, 1, 2, 3], dtype=np.int)
which_k = ((two_x - which_k > 0) & (two_x - which_k < 3))
phi = 0
for n, _ in enumerate(which_k):
if which_k[n] == True:
phi += h_k[n]*phi_vals[1][int((two_x-n)*2**j)]
phi_vals[1][int(x*2**j)] = 2*phi
return phi_vals
phi_vals = cascade_algorithm(10)
plt.plot(phi_vals[0], phi_vals[1])
plt.show()
If you just want to plot the graphs, then you can use the package "wavethresh" to plot for example the D4 with the following commands:
draw.default(filter.number=4, family="DaubExPhase", enhance=FALSE, main="D4 Mother", scaling.function = F) # mother wavelet
draw.default(filter.number=4, family="DaubExPhase", enhance=FALSE, main="D4 Father", scaling.function = T) # father wavelet
Notice that the mother wavelet and the father wavelets will be plotted depending on the variable "scaling.function". If true, then it plots the father wavelet (scaling), else it plots the mother wavelet.
If you want to generate it by yourself, without packages, I'd suggest you follow Daubechies-Lagarias algorithm, in this paper. It is not hard to implement.
I am using this octave code for solving differential equation.
# Define the right-hand side of the equation:
xvall= -11 ;#xvall
xvalu= 10 ;#xvalu
range=5000;
function ret=f(x,t);ret= t ;end;
# ywill be the values of the function at these moments of time.
t=linspace(xvall,xvalu,range);
y=lsode ('f', 2, linspace(xvall,xvalu,range));
y
plot(t,y);
i got the graph like this .
But when the same conditions are passed to wolfram alpha
I am getting the graph from 60 to 0 for y value
graph is
why is the graph behaving differently in two situations.
https://www.wolframalpha.com/input/?i=Runge-Kutta+method%2C+dy%2Fdx+%3D+x%2C+y%280%29+%3D+2%2C+from+-11+to+10%2C+h+%3D+0.25
To specify an initial value problem for an ordinary differential equation you need to define the initial condition. Here for Octave you have specified x(-11) = 2 since xvall = -11 and for Wolfram Alpha you have specified y(0) = 2. That is why you have two different solutions.
Octave
Octave's lsode (f,x_0,ts) solves the following initial value problem
dx/dt = t
x(t_0) = x_0
t in ts
Here ts is specified as a set of points in the interval [t_0,t_1]. You have specified t_0 = -11, t_1 = 10.
In closed form the solution to this problem is x = (t^2 - 117) / 2
Wolfram
For Wolfram you have used the semi-formal syntax:
Runge-Kutta method, dy/dx = x, y(0) = 2, from -11 to 10, h = 0.25
In closed form the solution to this problem would be y = (x^2 + 4) /2
The corresponding initial value problem is clearly different. Hence different results.
I need to interpolate a 3D surface given it's points and normal vectors.
Given a point on it's surface, I need to find where that point would be in space once the interpolation has been accounted for. I need to be able to do this for each triangle in isolation.
Here's what I'm trying to describe. I need the position of the point once the curve / surface has been interpolated.
If I was working in 2D:
3D:
I've come across this paper "Simple local interpolation of surfaces using normal vectors - Takashi Nagata" which I think demonstrates exactly what I'm looking for (section 2.2. Interpolation of a patch using normals), but the math is just beyond me.
What I'm trying to extract from it is a set of equations where the position and normals of the points comprising the triangle go in, as well as the point on the triangle, and the adjusted point comes out (like magic).
The paper looks like its trying to fit a quadratic surface so that it matches the points and normals you have. The resulting surface is given by
p(s,t) = c00 + c10 s + c01 t + c11 s t + c20 s^2 + c02 t^2
where s,t are the two variables, c00 etc are all vectors with three coordinates. s,t are chosen so at s=0,t=0 its your first point, s=1, t=0 is your second point and s=1,t=1 is your third point. Assuming we can find the various c00's you can pick some values of s,t in the triangle to give a middle point, s=2/3, t=1/3 might be a find candidate.
Find c00 etc will take some work. You probably need to implement eqn 15, which gives a curvature, as a function
vec3 c(vec3 D,vec3 n0,vec3 n1) {
vec3 v = (n0 + n1)/2; // 12a
vec3 dv = (n0 - n1)/2; // 12b
double d = D.dot(v); // 13a
double dd = D.dot(dv); // 13b
double c = n0.dot(n0 - 2*dv); // 14a
double dc = n0.dot(dv); // 14b
vec3 res;
if( c == -1 || c==1 )
res = vec3.zeroVector;
else
res = dd / (1-dc) * v + d / dc * dv;
return res;
}
assuming you have a vec3 class which can do basic vector operators.
With that defined, use 35, 36 to define the starting vectors and normals. Use 39 to define differences between pairs of points d1, d2, d3 and curvatures c1, c2, c3. The use eq 44
x(Ξ·, ΞΆ ) = x00(1 β Ξ·) + x10(Ξ· β ΞΆ ) + x11ΞΆ
β c1(1 β Ξ·)(Ξ· β ΞΆ ) β c2(Ξ· β ΞΆ )ΞΆ β c3(1 β Ξ·)ΞΆ
and your done.
For the records, and because I wanted to have this information somewhere on the web.
This is the 2d interpolation using the paper posted by the OP.
Where 1a and 1b are the boundary conditions, and the equations 4a and 4b are the x and y components of the vector c needed for the interpolation.
I have a value, for example 2.8. I want to find 10 numbers which are on an exponential curve, which sum to this value.
That is, I want to end up with 10 numbers which sum to 2.8, and which, when plotted, look like the curve below (exponential decay). These 10 numbers should be equally spaced along the curve - that is, the 'x-step' between the values should be constant.
This value of 2.8 will be entered by the user, and therefore the way I calculate this needs to be some kind of algorithm that I can program (hence asking this on SO not Math.SE).
I have no idea where to start with this at all - any ideas?
You want to have 10 x values equally distributed, i.e. x_k = a + k * b. They shall fulfill sum(exp(-x_k)) = v with v being your target value (the 2.8). This means exp(-a) * sum(exp(-b)^k) = v.
Obviously, there is a solution for each choice of b if v is positive. Set b to an arbitrary value, and calculate a from it.
E.g. for v = 2.8 and b = 0.1, you get a = -log(v / sum(exp(-b)^k)) = -log(2.8/sum(0.90484^k)) = -log(2.8/6.6425) = -log(0.421526) = 0.86387.
So for this example, the x values would be 0.86387, 0.96387, ..., 1.76387 and the y values 0.421526, 0.381412, 0.345116, 0.312274, 0.282557, 0.255668, 0.231338, 0.209324, 0.189404, 0.171380.
Update:
As it has been clarified that the curve can be scaled arbitrarily and the xs are preferred to be 1, 2, 3 ... 9, this is much more simple.
Assuming the curve function is r*exp(-x), the 10 values would be r*exp(-1) ... r*exp(-9). Their sum is r*sum(exp(-x)) = r*0.58190489. So to reach a certain value (2.8) you just have to adjust the r accordingly:
r = 2.8/sum(exp(-x)) = 4.81178294
And you get the 10 values: 1.770156, 0.651204, 0.239565, 0.088131, 0.032422, 0.011927, 0.004388, 0.001614, 0.000594.
If I understand your question correctly then you want to find x which solves the equation
It can be solved as
(just sum numbers as geometric progression)
The equation under RootOf will always have 1 real square different from 1 for 2.8 or any other positive number. You can solve it using some root-finding algorithm (1 is always a root but it does not solve original task). For constant a you can choose any number you like.
After computing the x you can easily calculate 10 numbers as .
I'm going to generalize and assume you want N numbers summing to V.
Since your numbers are equally spaced on an exponential you can write your sum as
a + a*x + a*x^2 + ... + a*x^(N-1) = V
Where the first point has value a, and the second a*x etc.
You can take out a factor of a and get:
a ( 1 + x + x^2 + ... + x^(N-1) ) = V
If we're free to pick x then we can solve for a easily
a = V / ( 1 + x + x^2 + .. x^(N-1) )
= V*(x+1)/(x^N-1)
Substituting that back into
a, a*x, a*x^2, ..., a*x^(N-1)
gives the required sequence