Cleanup Projectfile, Fixed Unsigned/Signed Conversion, Removed Euclid Debug Output
parent
4d1d400515
commit
e287225eaf
|
@ -35,11 +35,8 @@
|
||||||
<Compile Include="BigIntegerWrapper.cs" />
|
<Compile Include="BigIntegerWrapper.cs" />
|
||||||
<Compile Include="NumericsExtensions.cs" />
|
<Compile Include="NumericsExtensions.cs" />
|
||||||
<Compile Include="UInteger.cs" />
|
<Compile Include="UInteger.cs" />
|
||||||
<Compile Include="FixedWidthUBigInteger.cs" />
|
|
||||||
<Compile Include="IntField.cs" />
|
<Compile Include="IntField.cs" />
|
||||||
<Compile Include="BigUIntMath.cs" />
|
<Compile Include="BigUIntMath.cs" />
|
||||||
<Compile Include="UInt256.cs" />
|
|
||||||
<Compile Include="IUInteger.cs" />
|
|
||||||
<Compile Include="IntBase.cs" />
|
<Compile Include="IntBase.cs" />
|
||||||
<Compile Include="Euclid.cs" />
|
<Compile Include="Euclid.cs" />
|
||||||
<Compile Include="Integer.cs" />
|
<Compile Include="Integer.cs" />
|
||||||
|
|
|
@ -82,32 +82,25 @@ namespace BigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UInt32[] signedFromUnsigned(UInt32[] value){
|
public static UInt32[] signedFromUnsigned(UInt32[] value){
|
||||||
int lg2 = log2(value);
|
if (sign(value)){
|
||||||
int vlen = value.Length;
|
return value.Extend(value.Length+1);
|
||||||
|
|
||||||
if (lg2 < 0){
|
|
||||||
lg2 = 34 - lg2;
|
|
||||||
if ((lg2 % 32)==0){
|
|
||||||
vlen++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return value.Extend(vlen);
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduce signed integer to smallest width, needed to represent its value
|
* Reduce signed integer to smallest width, needed to represent its value
|
||||||
**/
|
**/
|
||||||
public static UInt32[] reduceSigned(UInt32[] value){
|
public static UInt32[] reduceSigned(UInt32[] value){
|
||||||
int lg2 = log2(value);
|
int n = value.Length;
|
||||||
if (lg2 < 0){
|
for (; n > 1; n--){
|
||||||
lg2 = 0 - lg2;
|
if (
|
||||||
|
(value[n-1] != 0) || ((value[n-2] & 1<<31)!=0)
|
||||||
|
){
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lg2 >>= 5;
|
return value.Segment(0,n);
|
||||||
lg2++;
|
|
||||||
if (value.Length != lg2){
|
|
||||||
return value.Segment(0, lg2);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,23 +108,13 @@ namespace BigInt
|
||||||
**/
|
**/
|
||||||
public static UInt32[] reduceUnsigned(UInt32[] value)
|
public static UInt32[] reduceUnsigned(UInt32[] value)
|
||||||
{
|
{
|
||||||
int lg2 = log2(value);
|
int n = value.Length;
|
||||||
if (lg2 < 0){
|
for (; n > 1; n--){
|
||||||
lg2 = value.Length;
|
if (value[n-1] != 0){
|
||||||
} else {
|
break;
|
||||||
lg2 >>= 5;
|
}
|
||||||
lg2++;
|
|
||||||
}
|
}
|
||||||
|
return value.Segment(0,n);
|
||||||
if (lg2 < 1)
|
|
||||||
{
|
|
||||||
lg2 = 1;
|
|
||||||
}
|
|
||||||
if (value.Length != lg2)
|
|
||||||
{
|
|
||||||
return value.Segment(0, lg2);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UInt32[] add(UInt32[] a, UInt32[] b)
|
public static UInt32[] add(UInt32[] a, UInt32[] b)
|
||||||
|
@ -289,8 +272,8 @@ namespace BigInt
|
||||||
sgna = sign(a);
|
sgna = sign(a);
|
||||||
sgnb = sign(b);
|
sgnb = sign(b);
|
||||||
|
|
||||||
Console.WriteLine("sdivmod(): a = {0}",a.getBytes().Reverse().toHexString());
|
//Console.WriteLine("sdivmod(): a = {0}",a.getBytes().Reverse().toHexString());
|
||||||
Console.WriteLine("sdivmod(): b = {0}",b.getBytes().Reverse().toHexString());
|
//Console.WriteLine("sdivmod(): b = {0}",b.getBytes().Reverse().toHexString());
|
||||||
|
|
||||||
if (sgna){
|
if (sgna){
|
||||||
a = twos(a);
|
a = twos(a);
|
||||||
|
@ -308,8 +291,8 @@ namespace BigInt
|
||||||
a = twos(a);
|
a = twos(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("sdivmod(): result = {0}",result.getBytes().Reverse().toHexString());
|
//Console.WriteLine("sdivmod(): result = {0}",result.getBytes().Reverse().toHexString());
|
||||||
Console.WriteLine("sdivmod(): reminder = {0}",a.getBytes().Reverse().toHexString());
|
//Console.WriteLine("sdivmod(): reminder = {0}",a.getBytes().Reverse().toHexString());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,18 +36,18 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\sharp-extensions\sharp.extensions.csproj">
|
<ProjectReference Include="..\BigInt.csproj">
|
||||||
<Project>{97CA3CA9-98B3-4492-B072-D7A5995B68E9}</Project>
|
|
||||||
<Name>sharp.extensions</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\BigInteger\BigInt.csproj">
|
|
||||||
<Project>{E745E261-9E3E-4401-B3BA-78B38753A82E}</Project>
|
<Project>{E745E261-9E3E-4401-B3BA-78B38753A82E}</Project>
|
||||||
<Name>BigInt</Name>
|
<Name>BigInt</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Crypto\Crypto.csproj">
|
<ProjectReference Include="..\..\sharp-crypto\Crypto.csproj">
|
||||||
<Project>{15D8398F-01EB-4280-8E2E-B03417DD3215}</Project>
|
<Project>{15D8398F-01EB-4280-8E2E-B03417DD3215}</Project>
|
||||||
<Name>Crypto</Name>
|
<Name>Crypto</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\sharp-extensions\sharp.extensions.csproj">
|
||||||
|
<Project>{97CA3CA9-98B3-4492-B072-D7A5995B68E9}</Project>
|
||||||
|
<Name>sharp.extensions</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
|
@ -12,8 +12,8 @@ namespace BigIntegerTest
|
||||||
{
|
{
|
||||||
testIntegerBase();
|
testIntegerBase();
|
||||||
testIntegerConversion();
|
testIntegerConversion();
|
||||||
//testUInteger();
|
testUInteger();
|
||||||
//testEC();
|
testEC();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testEC()
|
public static void testEC()
|
||||||
|
@ -26,10 +26,12 @@ namespace BigIntegerTest
|
||||||
|
|
||||||
Console.WriteLine("Gy^2 = {0}", yy.toHexString());
|
Console.WriteLine("Gy^2 = {0}", yy.toHexString());
|
||||||
Console.WriteLine("Y2(Gx) = {0}", ec.Y2(ec.G.X));
|
Console.WriteLine("Y2(Gx) = {0}", ec.Y2(ec.G.X));
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
CurvePoint G2 = ec.G + ec.G;
|
CurvePoint G2 = ec.G + ec.G;
|
||||||
Console.WriteLine("G + G = {0}", G2.toHexString());
|
Console.WriteLine("G + G = {0}", G2.toHexString());
|
||||||
Console.WriteLine("on Curve? {0}", ec.isOnCurve(G2));
|
Console.WriteLine("on Curve? {0}", ec.isOnCurve(G2));
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (int i = 1; i < 6; i++){
|
for (int i = 1; i < 6; i++){
|
||||||
|
|
|
@ -40,10 +40,10 @@ namespace BigInt
|
||||||
act.r - (q * next.r),
|
act.r - (q * next.r),
|
||||||
act.t - (q * next.t)
|
act.t - (q * next.t)
|
||||||
);
|
);
|
||||||
Console.WriteLine("EUCLID: q = {0}",q);
|
//Console.WriteLine("EUCLID: q = {0}",q);
|
||||||
Console.WriteLine("EUCLID: act: r = {0} / t = {1}",act.r,act.t);
|
//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: next: r = {0} / t = {1}",next.r,next.t);
|
||||||
Console.WriteLine("EUCLID: future: r = {0} / t = {1}",future.r,future.t);
|
//Console.WriteLine("EUCLID: future: r = {0} / t = {1}",future.r,future.t);
|
||||||
|
|
||||||
act = next;
|
act = next;
|
||||||
next = future;
|
next = future;
|
||||||
|
|
Loading…
Reference in New Issue