Cleanup Projectfile, Fixed Unsigned/Signed Conversion, Removed Euclid Debug Output
parent
4d1d400515
commit
e287225eaf
|
@ -35,11 +35,8 @@
|
|||
<Compile Include="BigIntegerWrapper.cs" />
|
||||
<Compile Include="NumericsExtensions.cs" />
|
||||
<Compile Include="UInteger.cs" />
|
||||
<Compile Include="FixedWidthUBigInteger.cs" />
|
||||
<Compile Include="IntField.cs" />
|
||||
<Compile Include="BigUIntMath.cs" />
|
||||
<Compile Include="UInt256.cs" />
|
||||
<Compile Include="IUInteger.cs" />
|
||||
<Compile Include="IntBase.cs" />
|
||||
<Compile Include="Euclid.cs" />
|
||||
<Compile Include="Integer.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;
|
||||
}
|
||||
|
|
|
@ -36,18 +36,18 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\sharp-extensions\sharp.extensions.csproj">
|
||||
<Project>{97CA3CA9-98B3-4492-B072-D7A5995B68E9}</Project>
|
||||
<Name>sharp.extensions</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\BigInteger\BigInt.csproj">
|
||||
<ProjectReference Include="..\BigInt.csproj">
|
||||
<Project>{E745E261-9E3E-4401-B3BA-78B38753A82E}</Project>
|
||||
<Name>BigInt</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Crypto\Crypto.csproj">
|
||||
<ProjectReference Include="..\..\sharp-crypto\Crypto.csproj">
|
||||
<Project>{15D8398F-01EB-4280-8E2E-B03417DD3215}</Project>
|
||||
<Name>Crypto</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\sharp-extensions\sharp.extensions.csproj">
|
||||
<Project>{97CA3CA9-98B3-4492-B072-D7A5995B68E9}</Project>
|
||||
<Name>sharp.extensions</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -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++){
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue