Network security - java-me

How could I generate curve points for elliptic curve cryptography in Java?

You would be advised to consider using the bouncycastle java libary, which has support for elliptic curves and the Java ME. Look for the lcrypto-j2me links on their latest releases page.

From Wikipedia: Elliptic curve cryptography
For current cryptographic purposes, an elliptic curve is a plane curve which consists of the points satisfying the equation
y^2 = x^3 + ax + b
along with a distinguished point at infinity, denoted \infty. (The coordinates here are to be chosen from a fixed finite field of characteristic not equal to 2 or 3, or the curve equation will be somewhat more complicated.) This set together with the group operation of the elliptic group theory form an Abelian group, with the point at infinity as identity element. The structure of the group is inherited from the divisor group of the underlying algebraic variety.
Further on, we read:
Several discrete logarithm-based protocols have been adapted to elliptic curves, replacing the group (Zp)^x times with an elliptic curve:
the elliptic curve Diffie–Hellman key agreement scheme is based on the Diffie–Hellman scheme,
the Elliptic Curve Digital Signature Algorithm is based on the Digital Signature Algorithm,
the ECMQV key agreement scheme is based on the MQV key agreement scheme.
This should be enough information to get you started.

Related

Interpolation of Polyhedron

Given a polyhedron defined by a matrix of 3-Dimensional vertices and its faces(delaunay triangles), I want to be able to create a smooth 3-D object.
Is there any software that has built a built in function that would allow me to do this?
If not, I have found a paper that seems to describe what I want, but I am unable to fully understand the math. http://graphics.berkeley.edu/papers/Turk-MIS-2002-10/Turk-MIS-2002-10.pdf.
Here is an examples of what I am looking for.
Rabbit
One solution for "smoothing" geometry, if we state the problem a bit more formally, is to perform mean curvature flow on your mesh. Here are some search terms - "curve-shortening flow", "mean curvature flow", "willmore flow", "conformal curvature flow" ...
Image source: Keenan Crane. Context and permission
"Smoothness of a surface or curve is very hard to define. (For an empirical test on what people perceive as smooth see http://www.levien.com/phd/thesis.pdf#page=23).
If you only care about perceived smoothness, for example, smoother appearance while rendering in high resolution etc., an easier approach would be Catmull-Clark subdivision scheme.
The geometric intuition is quite simple. In the case of a 2D curve, in every instance, every point on a curve moves according to some function of the curvature at that point. If we let the curve or surface move like this for some time, it will start smoothing out areas with high curvature more and more, eventually becoming a circle (or a sphere in 3d) and then collapse to a point. So for smoothing usually we have to preserve areas or volumes.
One way to define it is in terms of some energy, and our goal is to minimise this energy on the mesh. For example willmore flow minimises the willmore energy. Sometimes this process is called fairing.
I am not aware of a prepackaged library or tool, that's freely available and open source for curvature flow.
Algorithms
2D only
K.Mikula, D.Sevcovic, "Tangentially stabilized Lagrangian algorithm for elastic curve evolution driven by intrinsic Laplacian of curvature",
pdf
2D and 3D
https://www.youtube.com/watch?v=Jhqlmcms04M.
Keenan Crane's page has more information on this and more examples too.
http://www.cs.cmu.edu/~kmcrane/Projects/ConformalWillmoreFlow/
2D and 3D (level set method)
https://math.berkeley.edu/~sethian/2006/level_set.html

Find the closest point on a curve to a given point

The curve is in fact the trajectory of a bus, the curve is represented by many (up to a few thousand) discrete points on the curve (the points were recorded by a GPS device installed on the bus).
Input a point P, I need to find the closest point on the curve to the point P. The point P is usually no more than 30m away from the trajectory of the bus. Note, the closest point isn't necessary a point recorded by the GPS device, it could be a point somewhere between two recorded points.
First I need an algorithm to recover the trajectory from those recorded points. It would be great if the interpolated curve could show sharp turns made by the bus. Which curve is best for such task ? Is Bezier curve good enough ? And finally I have to calculate the closest point on the curve, of course the algorithm completely depends on the kind of curve chosen.
I'm doing some research, and don't have much knowledge in curve interpolation, so any suggestions are welcome.
For computing the trajectory from recorded points, I recommended using the centripetal or chord-length Catmull-Rom splines. See link for more details. Catmll-Rom splines are in fact special cubic Hermite curves, which can be easily converted into cubic Bezier curves. Please note that the result from Catmull-Rom spline is a G1 curve only in general. If you want the trajectory to be with higher continuity (such as C2), you can go with natural cubic splines or general B-spline interpolation. Whatever approach you take, it is advised to keep the spline's degree no higher than 5. Degree 3 is a popular choice.
Once you have the mathematical representation for the trajectory, you can compute the minimum distance between a given point P and the trajectory. In general, the squared distance between point P and a curve C(t) is represented as D(t) = |P-C(t)|^2. The minimum of D will happen at where its first derivative is zero, which means we have to find the root for the following equation:
dD/dt = 2*(P-C(t)).C'(t) =0
When C(t) is of degree 3, dD/dt will be of degree 5. This is the reason why it is recommended to use a low degree curve earlier.
There are many literatures or online materials talking about how to find the root of a polynomial (of any degree) efficiently and robustly. Here is another SO post that might be useful.

Joining bezier curves

I have a problem. Suppose we have a single cubic bezier curve defined by four control points. Now suppose, the curve is cut from a point and each segment is again represented using cubic bezier curves. So, now if we are given two such beziers B1 and B2, is there a way to know if they can be joined to form another bezier curve B? This is to simplify the geometry by joining two curves and reduce the number of control points.
Some thoughts about this problem.
I suggest there was initial Bezier curve P0-P3 with control points P1 and P2
Let's make two subdivisions at parameters ta and tb.
We have now two subcurves (in yellow) - P0-PA3 and PB0-P3.
Blue interval is lost.
PA1 and PB2 - known control points. We have to find unknown P1 and P2.
Some equations
Initial curve:
C = P0*(1-t)^3+3*P1(1-t)^2*t+3*P2*(1-t)*t^2+P3*t^3
Endpoints:
PA3 = P0*(1-ta)^3+3*P1*(1-ta)^2*ta+3*P2*(1-ta)*ta^2+P3*ta^3
PB0 = P0*(1-tb)^3+3*P1*(1-tb)^2*tb+3*P2*(1-tb)*tb^2+P3*tb^3
Control points of small curves
PA1 = P0*(1-ta)+P1*ta => P1*ta = PA1 – P0*(1-ta)
PB2 = P2*(1-tb)+P3*tb => P2(1-tb) = PB2 – P3*tb
Now substitute unknown points in PA3 equation:
**PA3***(1-tb) = **P0***(1-ta)^3*(1-tb)+3*(1-ta)^2*(1-tb)*(**PA1** – **P0***(1-ta))+3*(1-ta)*ta^2*( **PB2** – **P3***tb)+**P3***ta^3*(1-tb)
(some multiplication signs have been lost due to SO formatting)
This is vector equation, it contains two scalar equations for two unknowns ta and tb
PA3X*(1-tb) = P0X*(1-ta)^3*(1-tb)+3*(1-ta)^2*(1-tb)*(PA1X – P0X*(1-ta))+3*(1-ta)*ta^2*( PB2X – P3X*tb)+P3X*ta^3*(1-tb)
PA3Y*(1-tb) = P0Y*(1-ta)^3*(1-tb)+3*(1-ta)^2*(1-tb)*(PA1Y – P0Y*(1-ta))+3*(1-ta)*ta^2*( PB2Y – P3Y*tb)+P3Y*ta^3*(1-tb)
This system might be solved both numerically and analytically (indeed Maple solves it with very-very big cubic formula :( )
If we have points with some error, that makes sense to build overdetermined equation system for some points (PA3, PB0, PA2, PB1) and solve it numerically to minimize deviations.
You will find a quite simple solution here: https://math.stackexchange.com/a/879213/65203.
When you split a Bezier, the vectors formed by the last two control points of the first section and the first two control points of the second section are collinear and the ratio of their lengths leads to the value of the parameter at the split. Verifying that the common control point matches that value of the parameter is an easy matter (to avoid the case of accidental collinearity).

How to calculate control points for cubic curve, which approximates an elliptic arc?

Almost all vector graphics applications (like Corel) approximate elliptic arcs with several cubic Bezier curves. I need to add similar functionality to my application. So my question is: how to calculate control points of that Bezier curve?
There are lots of pages explaining how to do this. This paper by Don Lancaster, for example, gives control parameters for divisions of an ellipse into between 2 and 8 cubic splines, with a detailed analysis of the 4-spline case.

How to offset a cubic bezier curve?

I'm trying to create a "parrallel" bezier curve. In my attempts I've gotten close but no cigar. I'm trying to keep a solid 1px offset between the 2 curves (red,blue).
My main goal is use a edge offseting algorythm to expand/shrink a svg path.
Solution
For anyone else who is looking for a solution, I've create a AS3 version.
http://seant23.wordpress.com/2010/11/12/offset-bezier-curves/
I hope you found my math paper useful
Quadratic bezier offsetting with selective subdivision
https://microbians.com/mathcode
From wikipedia: ( http://en.wikipedia.org/wiki/B%C3%A9zier_curve )
The curve at a fixed offset from a given Bézier curve, often called an offset curve (lying "parallel" to the original curve, like the offset between rails in a railroad track), cannot be exactly formed by a Bézier curve (except in some trivial cases). However, there are heuristic methods that usually give an adequate approximation for practical purposes.
You might also see the paper indicated here:
Outline of cubic bezier curve stroke
What you ask for is called a parallel or offset curve in mathematics. The Wikipedia article (quoted above by others) on Bezier curves failed to link to the right article for "offset curve", but I've fixed that a few seconds ago. In the world of vector graphics, that same notion is called stroking the path.
In general, for cubic/Bezier curve the offset curve is a 10th order polynomial! Source: Kilgard, p. 28
If all you want to do is rasterize such offset curves, rather than compute their analytic form, you can for example look at the sources of ghostscript. You could also look at this patent application to see how NV_path_rendering does it.
If you want to covert/approximate the offset curves, then the TUG paper on MetaFog for covering METAFONT to PostScript fonts is a good reading. The METAFONT system, which predated PostScript allowed fonts to be described by the (more mathematically complex) operation of stroking, but PostScript Type 1 fonts only allow filling to be used (unlike PostScript drawings in general) for reasons of speed.
Another algorithm for approximating the offsets as (just two) Beziers (one on each side), with code in PostScript, is given in section 7 of this paper by Gernot Hoffmann. (Hat tip to someone on the OpenGL forum for finding it.)
There are in fact a lot of such algorithms. I found a 1997 survey of various algorithms for approximating offset curves. They assume the progenitor curves are Beziers or NURBS.
It's not possible in general to represent the offset of a cubic Bezier curve as a cubic Bezier curve (specifically, this is problematic when you have cusps or radius of curvature close to the offset distance). However, you can approximate the offset to any level of accuracy.
Try this:
Offset the Beziers in question (what you have already seems pretty decent)
Measure the difference between each original curve and corresponding offset curves. I'd try something like 10 samples and see if it works well.
For any offset that's outside of tolerance, subdivide (using the deCastlejau algorithm for Beziers) and iterate.
I haven't implemented an offset (because the kernels I use already have one), but this seems like something to try.

Resources