Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kamel78 authored Dec 18, 2018
1 parent fc5cce6 commit 1db6977
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Arithmetic/LargeIntegers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface

uses System.Types,System.UITypes, System.SysUtils, System.Math,VCL.dialogs;
//150
Const MaxLen=180 ;
Const MaxLen=190 ;

Const basediv2=2147483648;
base=4294967296;
Expand Down Expand Up @@ -149,7 +149,7 @@ FieldParams=record // Base Field parametres
Procedure ExtendedEuclid(a,b:LInt;Var s,t:LInt);
Function ResolveDiopantiene(a,b,c:LInt;var x,y:LInt):Boolean;
Procedure GetRandomLIntOnBits(Var Result:LInt;Numbits:Integer);
Procedure GetRandomLIntLowerThan(var Result:LInt;Limit:LInt;Seed:Word=0);
Procedure GetRandomLIntLowerThan(var Result:LInt;Limit:LInt;Seed:Word=0;SameBitlength:boolean=true);
Procedure InitMontgomeryStruct(Modulo:LInt;var Struct:PtrMontgomeryStruct);
Function IsLIntPrime(Number:LInt;Prob:Extended=0.9999):Boolean;
function ModSquareLInt(a,modulo:LInt;Var Output:LInt;MgStruct:PtrMontgomeryStruct; test:boolean=true):boolean;
Expand Down Expand Up @@ -2145,15 +2145,17 @@ procedure _Inv_Mod_LInt(a,modulo:LInt;var Result:LInt);inline; /// the modulo i
{***************************************************************************************}
{ Generate a random binary block Lower than Limit }
{***************************************************************************************}
Procedure GetRandomLIntLowerThan(var Result:LInt;Limit:LInt;Seed:Word=0);
Procedure GetRandomLIntLowerThan(var Result:LInt;Limit:LInt;Seed:Word=0;SameBitlength:boolean=true);
var i:integer;
begin
if seed=0 then Randomize
else RandSeed:=seed;
Result.data.i32[-1]:=Limit.data.i32[-1];
For i:=0 to Result.data.i32[-1]-1 do Result.data.i32[i]:=Random(MaxLongint);
_Mod_LInt(Result,Limit,Result);
while (Result.data.i32[Result.data.i16[-2]-1]=0)and(Result.data.i16[-2]>0) do dec(Result.data.i16[-2]);
repeat
if seed=0 then Randomize
else RandSeed:=seed;
Result.data.i32[-1]:=Limit.data.i32[-1];
For i:=0 to Result.data.i32[-1]-1 do Result.data.i32[i]:=Random(MaxLongint);
_Mod_LInt(Result,Limit,Result);
while (Result.data.i32[Result.data.i16[-2]-1]=0)and(Result.data.i16[-2]>0) do dec(Result.data.i16[-2]);
until (not(SameBitlength)or(Result.BitLength=Limit.BitLength));
end;

{***************************************************************************************}
Expand Down Expand Up @@ -2436,7 +2438,7 @@ function ModSquareLInt(a,modulo:LInt;Var Output:LInt;MgStruct:PtrMontgomeryStruc
s:=a;
if (s[1]='$') then s:=copy(S,2,length(s))
else if (s[1]='0')and(s[2]='x') then s:=copy(S,3,length(s));
setlength(result,(length(a) div 2+length(a) mod 2));
setlength(result,(length(s) div 2+length(s) mod 2));
i:=0;
While (s<>'') do begin
if length(s)>2 then begin
Expand Down

0 comments on commit 1db6977

Please sign in to comment.