diff --git a/BigInt.csproj b/BigInt.csproj
index 1cd2810..2950591 100644
--- a/BigInt.csproj
+++ b/BigInt.csproj
@@ -35,11 +35,8 @@
-
-
-
diff --git a/BigIntMath.cs b/BigIntMath.cs
index 13a0e52..f4bbd7d 100644
--- a/BigIntMath.cs
+++ b/BigIntMath.cs
@@ -82,32 +82,25 @@ namespace BigInt
}
public static UInt32[] signedFromUnsigned(UInt32[] value){
- int lg2 = log2(value);
- int vlen = value.Length;
-
- if (lg2 < 0){
- lg2 = 34 - lg2;
- if ((lg2 % 32)==0){
- vlen++;
- }
+ if (sign(value)){
+ return value.Extend(value.Length+1);
}
- return value.Extend(vlen);
+ return value;
}
/**
* Reduce signed integer to smallest width, needed to represent its value
**/
public static UInt32[] reduceSigned(UInt32[] value){
- int lg2 = log2(value);
- if (lg2 < 0){
- lg2 = 0 - lg2;
+ int n = value.Length;
+ for (; n > 1; n--){
+ if (
+ (value[n-1] != 0) || ((value[n-2] & 1<<31)!=0)
+ ){
+ break;
+ }
}
- lg2 >>= 5;
- lg2++;
- if (value.Length != lg2){
- return value.Segment(0, lg2);
- }
- return value;
+ return value.Segment(0,n);
}
/**
@@ -115,23 +108,13 @@ namespace BigInt
**/
public static UInt32[] reduceUnsigned(UInt32[] value)
{
- int lg2 = log2(value);
- if (lg2 < 0){
- lg2 = value.Length;
- } else {
- lg2 >>= 5;
- lg2++;
+ int n = value.Length;
+ for (; n > 1; n--){
+ if (value[n-1] != 0){
+ break;
+ }
}
-
- if (lg2 < 1)
- {
- lg2 = 1;
- }
- if (value.Length != lg2)
- {
- return value.Segment(0, lg2);
- }
- return value;
+ return value.Segment(0,n);
}
public static UInt32[] add(UInt32[] a, UInt32[] b)
@@ -289,8 +272,8 @@ namespace BigInt
sgna = sign(a);
sgnb = sign(b);
- Console.WriteLine("sdivmod(): a = {0}",a.getBytes().Reverse().toHexString());
- Console.WriteLine("sdivmod(): b = {0}",b.getBytes().Reverse().toHexString());
+ //Console.WriteLine("sdivmod(): a = {0}",a.getBytes().Reverse().toHexString());
+ //Console.WriteLine("sdivmod(): b = {0}",b.getBytes().Reverse().toHexString());
if (sgna){
a = twos(a);
@@ -308,8 +291,8 @@ namespace BigInt
a = twos(a);
}
- Console.WriteLine("sdivmod(): result = {0}",result.getBytes().Reverse().toHexString());
- Console.WriteLine("sdivmod(): reminder = {0}",a.getBytes().Reverse().toHexString());
+ //Console.WriteLine("sdivmod(): result = {0}",result.getBytes().Reverse().toHexString());
+ //Console.WriteLine("sdivmod(): reminder = {0}",a.getBytes().Reverse().toHexString());
return result;
}
diff --git a/BigIntegerTest/BigIntegerTest.csproj b/BigIntegerTest/BigIntegerTest.csproj
index 025c859..dd6f363 100644
--- a/BigIntegerTest/BigIntegerTest.csproj
+++ b/BigIntegerTest/BigIntegerTest.csproj
@@ -36,18 +36,18 @@
-
- {97CA3CA9-98B3-4492-B072-D7A5995B68E9}
- sharp.extensions
-
-
+
{E745E261-9E3E-4401-B3BA-78B38753A82E}
BigInt
-
+
{15D8398F-01EB-4280-8E2E-B03417DD3215}
Crypto
+
+ {97CA3CA9-98B3-4492-B072-D7A5995B68E9}
+ sharp.extensions
+
\ No newline at end of file
diff --git a/BigIntegerTest/Program.cs b/BigIntegerTest/Program.cs
index 50c9cb6..5d06e83 100644
--- a/BigIntegerTest/Program.cs
+++ b/BigIntegerTest/Program.cs
@@ -12,8 +12,8 @@ namespace BigIntegerTest
{
testIntegerBase();
testIntegerConversion();
- //testUInteger();
- //testEC();
+ testUInteger();
+ testEC();
}
public static void testEC()
@@ -26,10 +26,12 @@ namespace BigIntegerTest
Console.WriteLine("Gy^2 = {0}", yy.toHexString());
Console.WriteLine("Y2(Gx) = {0}", ec.Y2(ec.G.X));
+ Console.WriteLine();
CurvePoint G2 = ec.G + ec.G;
Console.WriteLine("G + G = {0}", G2.toHexString());
Console.WriteLine("on Curve? {0}", ec.isOnCurve(G2));
+ Console.WriteLine();
/*
for (int i = 1; i < 6; i++){
diff --git a/Euclid.cs b/Euclid.cs
index 85b96b9..9d7c29f 100644
--- a/Euclid.cs
+++ b/Euclid.cs
@@ -40,10 +40,10 @@ namespace BigInt
act.r - (q * next.r),
act.t - (q * next.t)
);
- Console.WriteLine("EUCLID: q = {0}",q);
- Console.WriteLine("EUCLID: act: r = {0} / t = {1}",act.r,act.t);
- Console.WriteLine("EUCLID: next: r = {0} / t = {1}",next.r,next.t);
- Console.WriteLine("EUCLID: future: r = {0} / t = {1}",future.r,future.t);
+ //Console.WriteLine("EUCLID: q = {0}",q);
+ //Console.WriteLine("EUCLID: act: r = {0} / t = {1}",act.r,act.t);
+ //Console.WriteLine("EUCLID: next: r = {0} / t = {1}",next.r,next.t);
+ //Console.WriteLine("EUCLID: future: r = {0} / t = {1}",future.r,future.t);
act = next;
next = future;