private void Calc(int secretKey) { const double scale_f = 1e50; BigInteger p = BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671663"); float scale_p = (float)((double)p / scale_f); // Elliptic curve: y^2 = x^3 + a*x + b (mod p): y^2 = x^3 + 7 BigInteger a = 0; BigInteger b = 7; // P = G var G = new EcModPoint { x = BigInteger.Parse("55066263022277343669578718895168534326250603453777594175500187360389116729240"), y = BigInteger.Parse("32670510020758816978083085130507043184471273380659243275938904335757337482424") }; var lstPoints = BigIntegerExtensions.EcSlowPointListByAddition(p, a, G, secretKey); var g = pbEcDescrete.CreateGraphics(); g.FillRectangle(Brushes.White, new RectangleF(0, 0, pbEcDescrete.Width, pbEcDescrete.Height)); foreach (var ecPoint in lstPoints) { var x = (float)((double)ecPoint.x / scale_f); var y = (float)((double)ecPoint.y / scale_f); var scale_x = pbEcDescrete.Width / scale_p; var scale_y = pbEcDescrete.Height / scale_p; var x1 = scale_x * x; var y1 = scale_y * y; g.FillRectangle(Brushes.Blue, new RectangleF(x1, y1, 3F, 3F)); } }
static void Main(string[] args) { getWeirstrasseFormFromEdwards(); // Elliptic curve chosen var ecType = EllipticCurveType.E521; Console.WriteLine("Elliptic curve type: {0}", ecType.ToString()); Console.WriteLine(); // only Alice knows var aliceSecretKey = BigInteger.Parse("55179115824979878594564946684576670362812219109178118526265814188406326272077"); // only Bob knows var bobSecretKey = BigInteger.Parse("28186466892849679686038856807396267537577176687436853369"); // public keys // Alice's public key EcModPoint pa = null; // Bob's public key EcModPoint pb = null; switch (ecType) { case EllipticCurveType.SEC256K1: pa = EcCryptographyHelper.SecP256k1KeyPairGenerator(aliceSecretKey); pb = EcCryptographyHelper.SecP256k1KeyPairGenerator(bobSecretKey); break; case EllipticCurveType.M383: pa = EcCryptographyHelper.M383KeyPairGenerator(aliceSecretKey); pb = EcCryptographyHelper.M383KeyPairGenerator(bobSecretKey); break; case EllipticCurveType.E521: pa = EcCryptographyHelper.E521KeyPairGenerator(aliceSecretKey); pb = EcCryptographyHelper.E521KeyPairGenerator(bobSecretKey); break; default: break; } // Alice sends a message to Bob string message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Error, assumenda beatae ipsum similique dignissimos odit officia dolores laudantium quis dicta."; Console.WriteLine("Alice writes to Bob: {0}", message); // Alice encrypts the message using Bob's public key var encryptStr = EcCryptographyHelper.EcEncryptJson(message, pb, ecType); // Bob decrypts the message using his private key var decryptedMsg = EcCryptographyHelper.EcDecryptJson(encryptStr, bobSecretKey, ecType); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Bob reads: {0}", decryptedMsg); Console.WriteLine(); Console.WriteLine(); // Bob sends a message to Alice message = "Deleniti illum quaerat vel ullam tempore! Animi, deserunt, rerum, illum harum veniam exercitationem cupiditate perspiciatis corporis eveniet quae ipsum sunt nam vel est neque omnis repellat magnam debitis sequi laboriosam blanditiis."; Console.WriteLine("Bob writes to Alice: {0}", message); // Bob encrypts the message using Alice's public key encryptStr = EcCryptographyHelper.EcEncryptJson(message, pa, ecType); // Alice decrypts the message using her private key decryptedMsg = EcCryptographyHelper.EcDecryptJson(encryptStr, aliceSecretKey, ecType); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Alice reads: {0}", decryptedMsg); Console.WriteLine("Finished...."); Console.ReadKey(); }