Showing posts with label random curve. Show all posts
Showing posts with label random curve. Show all posts

Sunday, July 04, 2010

Huge cryptographically secure random numbers

Just a tiny implementation example on how to use .NET crypto-package to create really huge pseudo random numbers.
Add approprite controls and rock.
(in my example I just kicked out the number on a webpage - feel free to do it where ever you like)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Numerics;
using System.Security.Cryptography;

namespace numbers
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

private static BigInteger GetRandom()
{
RandomNumberGenerator ran = RNGCryptoServiceProvider.Create();
byte[] ranbytes = new Byte[256];
//ex: Byte[20] gives 8 bit * 20 = 160 bit ~ 50 digits
//ex: Byte[2] gives 8 bit * 2 = 16 bit = +- 32768
//ex: Byte[128] gives 8 bit * 128 = 1024 bit ~ 300 digits

//fill the byte array with cryptographically strong random bytes
ran.GetBytes(ranbytes);

//put the random bytes into a bigInteger
BigInteger mynum = new BigInteger(ranbytes);
return mynum;
}

protected void Button1_Click(object sender, EventArgs e)
{

//Roll the really really big dice :)
BigInteger roll = GetRandom();
result.Text= roll.ToString();

}
}
}

Saturday, June 06, 2009

random curve with point

If you just need any short form weierstrass curve at random with a random point the easiest way is to create the point first, then the curve.
suitable for lenstra.
Given a composite you would like to factor.
toy example:
given N= 1289
random point P=(x,y)=(235,156)
random A= 21
calculate B as
B=y^2 -x^3 - A*x mod N
156^2-235^3-21*235 mod 1289 gives B=-157
then you got your random curve:
Y^2=X^3 + 21X-157 with a point P that by construction is on the curve.

the solution for B ofcourse can be plus/minus any multiplication of N. equivalence class: B + Z/ZN
More about lenstra later