From 975d1cfb855777d6c04a7827d8417004633441f1 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 1 Sep 2015 18:09:47 +0300 Subject: [PATCH] stubs for uint256/uint160 --- Novacoin/Novacoin.csproj | 3 + Novacoin/base_uint.cs | 96 ++++++++++++++++++++++++++++++++++++++++++++++ Novacoin/uint160.cs | 12 ++++++ Novacoin/uint256.cs | 12 ++++++ 4 files changed, 123 insertions(+), 0 deletions(-) create mode 100644 Novacoin/base_uint.cs create mode 100644 Novacoin/uint160.cs create mode 100644 Novacoin/uint256.cs diff --git a/Novacoin/Novacoin.csproj b/Novacoin/Novacoin.csproj index 6d483af..59481ac 100644 --- a/Novacoin/Novacoin.csproj +++ b/Novacoin/Novacoin.csproj @@ -107,6 +107,7 @@ + @@ -125,6 +126,8 @@ + + diff --git a/Novacoin/base_uint.cs b/Novacoin/base_uint.cs new file mode 100644 index 0000000..287be58 --- /dev/null +++ b/Novacoin/base_uint.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Novacoin +{ + public class base_uint + { + protected uint nWidth; + protected uint[] pn; + + public static bool operator !(base_uint a) + { + for (int i = 0; i < a.nWidth; i++) + { + if (a.pn[i] != 0) + { + return false; + } + } + return true; + } + + public static base_uint operator ~(base_uint a) + { + var ret = new base_uint(); + for (int i = 0; i < a.nWidth; i++) + { + ret.pn[i] = ~a.pn[i]; + } + return ret; + } + + public static base_uint operator -(base_uint a) + { + var ret = new base_uint(); + for (int i = 0; i < a.nWidth; i++) + { + ret.pn[i] = ~a.pn[i]; + } + ret++; + return ret; + } + + public static base_uint operator ++(base_uint a) + { + // prefix operator + int i = 0; + while (++a.pn[i] == 0 && i < a.nWidth - 1) + { + i++; + } + return a; + } + + public static base_uint operator --(base_uint a) + { + // prefix operator + int i = 0; + while (--a.pn[i] == uint.MaxValue && i < a.nWidth - 1) + { + i++; + } + return a; + } + + public static base_uint operator ^(base_uint a, base_uint b) + { + var c = new base_uint(); + c.pn = new uint[a.nWidth]; + for (int i = 0; i < c.nWidth; i++) + { + c.pn[i] = a.pn[i] ^ b.pn[i]; + } + return c; + } + + public static base_uint operator +(base_uint a, base_uint b) + { + var result = new base_uint(); + ulong carry = 0; + for (int i = 0; i < result.nWidth; i++) + { + ulong n = carry + a.pn[i] + b.pn[i]; + result.pn[i] = (uint)(n & 0xffffffff); + carry = n >> 32; + } + return result; + } + + + + } +} diff --git a/Novacoin/uint160.cs b/Novacoin/uint160.cs new file mode 100644 index 0000000..26e1dd9 --- /dev/null +++ b/Novacoin/uint160.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Novacoin +{ + public class uint160 : base_uint + { + } +} diff --git a/Novacoin/uint256.cs b/Novacoin/uint256.cs new file mode 100644 index 0000000..8ce6b97 --- /dev/null +++ b/Novacoin/uint256.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Novacoin +{ + public class uint256 : base_uint + { + } +} -- 1.7.1