0xff is 0b11111111 and since the most significant bit is set this number is negative.
It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
public static BigInteger inverse(BigInteger a, BigInteger m)
{
return BigInteger.ModPow(a, m - 2, m);
}
using System;
using System.Numerics;
public class Program
{
static BigInteger p = BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671663");
static BigInteger n = BigInteger.Parse("115792089237316195423570985008687907852837564279074904382605163141518161494337");
static BigInteger[] zero = {0,0};
static BigInteger[] g = {
BigInteger.Parse("55066263022277343669578718895168534326250603453777594175500187360389116729240"),
BigInteger.Parse("32670510020758816978083085130507043184471273380659243275938904335757337482424")
};
public static void Main()
{
BigInteger[] g0 = {0,0}, g2 = ECdouble(g), g4 = ECdouble(g2);
BigInteger[] z = ECMultiplication(7, g);
//z = ECaddition(z, g);
//z = ECaddition(z, g2);
//z = ECaddition(z, g4);
Console.WriteLine(z[0].ToString());
Console.WriteLine(z[1].ToString());
Console.WriteLine(IsOnCurve(z));
Console.WriteLine(IsOnCurve(zero));
}
public static BigInteger inverse(BigInteger a, BigInteger m) { return BigInteger.ModPow(a, m-2, m); }
public static BigInteger[] ECdouble(BigInteger[] point)
{
if (point[1] == 0) return zero;
BigInteger slope = (3 * BigInteger.ModPow(point[0], 2, p) * inverse((2 * point[1]), p)) % p;
BigInteger x = (BigInteger.ModPow(slope, 2, p) - (2 * point[0])) % p;
BigInteger y = (slope * (point[0] - x) - point[1]) % p;
if (x < 0) x += p;
if (y < 0) y += p;
BigInteger[] coord = { x, y };
return coord;
}
public static BigInteger[] ECaddition(BigInteger[] point1, BigInteger[] point2)
{
if (point1[1] == 0) return point2;
if (point2[1] == 0) return point1;
if (point1[0] == point2[0]) {
if (point1[1] == point2[1]) return ECdouble(point1);
return zero;
}
BigInteger slope = ((point2[1] - point1[1]) * inverse(point2[0] - point1[0], p)) % p;
BigInteger x = (BigInteger.ModPow(slope, 2, p) - point1[0] - point2[0]) % p;
BigInteger y = ((slope * (point1[0] - x)) - point1[1]) % p;
if (x < 0) x += p;
if (y < 0) y += p;
BigInteger[] coord = { x, y };
return coord;
}
public static BigInteger[] ECMultiplication(BigInteger k, BigInteger[] Gpoint)
{
BigInteger[] powerOfTwo = Gpoint;
BigInteger[] result = zero;
k %= n; if (k < 0) k += n;
while (k > 0) {
if ((k&1) == 1) result = ECaddition(result, powerOfTwo);
k >>= 1;
powerOfTwo = ECdouble(powerOfTwo);
}
return result;
}
public static bool IsOnCurve(BigInteger[] point)
{
BigInteger x = point[0] % p; if (x<0) x += p;
BigInteger y = point[1] % p; if (y<0) y += p;
return BigInteger.ModPow(y, 2, p) == (BigInteger.ModPow(x, 3, p) + 7) % p;
}
}
048282263212C609D9EA2A6E3E172DE238D8C39CABD5AC1CA10646E23FD5F5150811F8A8098557DFE45E8256E830B60ACE62D613AC2F7B17BED31B6EAFF6E26CAF
040F19435668D97C96E4AE99B4BC78EB71826D36F9B380E0B462FD3159F5D896642B2B297DED0525941A6BEBB8386979BDEFBC7DFC6707C6871E67983E0807E4523
public BigInteger inverse(BigInteger a, BigInteger m)
{
BigInteger m_orig = m;
BigInteger prevy = 0;
BigInteger y = 1;
BigInteger q;
BigInteger oldy = 0;
BigInteger olda = 0;
if (a < 0)
{
a = a % m;
}
while (a > 1)
{
q = m / a;
oldy = y;
y = prevy - q * y;
prevy = oldy;
olda = a;
a = m % a;
m = olda;
}
return y % m_orig;
}
public BigInteger[] ECdouble(BigInteger[] point)
{
BigInteger slope = ((3 * point[0] ^ 2) * inverse((2 * point[1]), p)) % p;
BigInteger x = (slope ^ 2 - (2 * point[0])) % p;
BigInteger y = (slope * (point[0] - x) - point[1]) % p;
BigInteger[] coord = { x, y };
return coord;
}
public BigInteger[] ECaddition(BigInteger[] point1, BigInteger[] point2)
{
if (point1[0] == point2[0] && point1[1] == point2[1])
{
return ECdouble(point1);
}
BigInteger slope = ((point1[1] - point2[1]) * inverse(point1[0] - point2[0], p)) % p;
BigInteger x = (slope ^ 2 - point1[0] - point2[0]) % p;
BigInteger y = ((slope * (point1[0] - x)) - point1[1]) % p;
BigInteger[] coord = { x, y };
return coord;
}
public BigInteger[] ECMultiplication(BigInteger k, BigInteger[] Gpoint)
{
BigInteger[] current = Gpoint;
//private key to binary
string binary = String.Join(String.Empty,
privatekey.Select(
c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')
)
);
// ignoring the first binary character
binary = binary.Substring(1);
for (int i=0; i{
current = ECdouble(current);
if (binary[i] == '1')
{
current = ECaddition(current, Gpoint);
}
}
return current;
}
048282263212C609D9EA2A6E3E172DE238D8C39CABD5AC1CA10646E23FD5F5150811F8A8098557DFE45E8256E830B60ACE62D613AC2F7B17BED31B6EAFF6E26CAF
047D285CA13DEC25E44F435B6876601CC9042F8787AD8B7DCC1F6588FF50D5327FF21E17C179DFC3A565E3ECCD0EEF92D9A39D6B23FAB1F8093A72E3468C9A2A335
public BigInteger modinv(BigInteger a, BigInteger m)
{
BigInteger prevy = 0;
BigInteger y = 1;
BigInteger q;
BigInteger oldy;
BigInteger olda;
if (a < 0)
{
a = a % m;
}
while (a > 1)
{
q = m / a;
oldy = y;
y = prevy - q * y;
prevy = oldy;
olda = a;
a = m % a;
m = olda;
}
return y;
}
string privatekey = "5"; // this is the private key in hex
BigInteger p = BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671663");
BigInteger[] g =
{
BigInteger.Parse("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", NumberStyles.AllowHexSpecifier),
BigInteger.Parse("483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", NumberStyles.AllowHexSpecifier)
};
BigInteger k = BigInteger.Parse(privatekey, NumberStyles.AllowHexSpecifier);
BigInteger[] point = ECMultiplication(k, g);
string x = point[0].ToString("X");
string y = point[1].ToString("X");
string public_key_uncompressed = "04" + x + y;
ECDSApublic.Text = public_key_uncompressed;
0441721458CC97441B6C43006E2AE8050D55F8A200A22E067BA1D4F6C4E846B27AF5D0F2E457F91F826EC0412BEA2A13BADD81D5DB59009620EA2E56C927D6ED521
042F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE4D8AC222636E5E3D6D4DBA9DDA6C9C426F788271BAB0D6840DCA87D3AA6AC62D6
y = prevy - q * y;
prevy = y;
a = m % a;
m = a;
y, prevy = prevy - q * y, y
a, m = m % a, a
oldy = y
y = prevy - q * y;
prevy = oldy;
olda = a
a = m % a;
m = olda;
var key = new PrivateKey(rng_or_wif_or_bytes_or_int);
string compPubHex = key.ToPublicKey().ToByteArray(true).ToBase16();
key.Dispose();
private readonly Autarkysoft.Bitcoin.Cryptography.Asymmetric.EllipticCurve.EllipticCurveCalculator calc = new Autarkysoft.Bitcoin.Cryptography.Asymmetric.EllipticCurve.EllipticCurveCalculator();
public PublicKey ToPublicKey()
{
return new PublicKey(calc.MultiplyByG(BigInteger.Parse("1")));
}
using Autarkysoft.Bitcoin.Cryptography.Arithmetic;
using Autarkysoft.Bitcoin.Cryptography.Asymmetric.KeyPairs;
using Autarkysoft.Bitcoin.Cryptography.Hashing;
using Autarkysoft.Bitcoin.Blockchain.Scripts;
using Autarkysoft.Bitcoin.Blockchain.Transactions;
using Autarkysoft.Bitcoin.Cryptography.Asymmetric.EllipticCurve;
public BigInteger[] ECMultiplication(BigInteger k, BigInteger[] Gpoint)
{
BigInteger[] current = g;
string binary = String.Join(String.Empty,
privatekey.Select(
c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')
)
);
// ignoring the first binary character
binary = binary.Substring(1);
current = ECdouble(current);
if (binary[0] == '1') {
current = ECaddition(current, Gpoint);
}
return current;
}
int modInverse(int a, int n)
{
int i = n, v = 0, d = 1;
while (a>0) {
int t = i/a, x = a;
a = i % x;
i = x;
x = d;
d = v - t*x;
v = x;
}
v %= n;
if (v<0) v = (v+n)%n;
return v;
}
# Modular Inverse - Ruby doesn't have a built-in function for finding modular inverses, so here's one using the extended Euclidean algorithm.
def modinv(a, m = $p)
a = a % m if a < 0 # make sure a is positive
prevy, y = 0, 1
while a > 1
q = m / a
y, prevy = prevy - q * y, y
a, m = m % a, a
end
return y
end
public BigInteger modinv(BigInteger a, BigInteger m)
{
BigInteger prevy = 0;
BigInteger y = 1;
BigInteger q;
if(a > 0)
{
a = a % m;
}
while(a > 1)
{
q = m / a;
y = prevy - q * y;
prevy = y;
a = m % a;
m = a;
}
return y;
}
# Double - Add a point on the curve to itself.
def double(point)
# slope = (3x^2 + a) / 2y
slope = ((3 * point[:x] ** 2) * modinv((2 * point[:y]))) % $p # using modular inverse to perform "division"
# new x = slope^2 - 2x
x = (slope ** 2 - (2 * point[:x])) % $p
# new y = slope * (x - new x) * y
y = (slope * (point[:x] - x) - point[:y]) % $p
# return x, y coordinates of point
return { x: x, y: y }
end
public BigInteger[] ECdouble(BigInteger[] point){
BigInteger slope = (3 * point[0] ^ 2) * modinv((2 * point[1]), p);
BigInteger x = (slope ^ 2 - (2 * point[0])) % p;
BigInteger y = (slope * (point[0] - x) - point[1]) % p;
BigInteger[] coord = { x, y };
return coord;
}
# Add - Add two points together.
def add(point1, point2)
# double if both points are the same
return double(point1) if point1 == point2
# slope = (y1 - y2) / (x1 - x2)
slope = ((point1[:y] - point2[:y]) * modinv(point1[:x] - point2[:x])) % $p
# new x = slope^2 - x1 - x2
x = (slope ** 2 - point1[:x] - point2[:x]) % $p
# new y = slope * (x1 - new x) - y1
y = ((slope * (point1[:x] - x)) - point1[:y]) % $p
# return x, y coordinates of point
return { x: x, y: y }
end
public BigInteger[] ECaddition(BigInteger[] point1, BigInteger[] point2)
{
if(point1 == point2)
{
return ECdouble(point1);
}
BigInteger slope = ((point1[1] - point2[1]) * modinv(point1[0] - point2[0], p)) % p;
BigInteger x = (slope ^ 2 - point1[0] - point2[0]) % p;
BigInteger y = ((slope * (point1[0] - x)) - point1[1]) % p;
BigInteger[] coord = { x, y };
return coord;
}
# Multiply - Use the double and add operations to quickly multiply a point by an integer (e.g. a private key).
def multiply(k, point = $g) # multiply the generator point by default
# create a copy the initial starting point (for use in addition later on)
current = point
# convert integer to binary representation (for use in the double and add algorithm)
binary = k.to_s(2)
# double and add algorithm for fast multiplication
binary.split("").drop(1).each do |char| # ignore first binary character
# 0 = double
current = double(current)
# 1 = double and add
if char == "1"
current = add(current, point)
end
end
# return the final point
return current
end
public BigInteger[] ECMultiplication(BigInteger k, BigInteger[] Gpoint)
{
BigInteger[] current = g;
string binary = String.Join(String.Empty,
privatekey.Select(
c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')
)
);
// ignoring the first binary character
binary = binary.Substring(1);
current = ECdouble(current);
if (binary[0] == '1') {
current = ECaddition(current, Gpoint);
}
return current;
}
BigInteger k = BigInteger.Parse(privatekey, NumberStyles.AllowHexSpecifier);
BigInteger[] point = ECMultiplication(k, g);
string x = point[0].ToString("X");
string y = point[1].ToString("X");
string public_key_uncompressed = "04" + x + y;
MessageBox.Show(public_key_uncompressed);
EF235AACF90D9F4AADD8C92E4B2562E1D9EB97F0DF9BA3B508258739CB013DB2
04F16342D6F4B64CC9911166A922D5AE5A9074B6BB59F3B7F159E82DFBB1F2641080931651B4F05BB9DD93ED3DF9D708BC0A1AD03F478767C3FDE73AEE2739C9ED54