'~ Autor: @@Jan Klečka@@
'~ Tenhle soubor obsahuje jednotlivé funkce pro generování parametrů.
'~ Jsou zde definováne hodnoty G256 jako veřejné body EC a q256 pro omezení rozsahu soukromého klíče.


Public G256$=Chr$(&H6b,&H17,&Hd1,&Hf2,&He1,&H2c,&H42,&H47,&Hf8,&Hbc,&He6,&He5,&H63,&Ha4,&H40,&Hf2,&H77,&H03,&H7d,&H81,&H2d,&Heb,&H33,&Ha0,&Hf4,&Ha1,&H39,&H45,&Hd8,&H98,&Hc2,&H96,&H4f,&He3,&H42,&He2,&Hfe,&H1a,&H7f,&H9b,&H8e,&He7,&Heb,&H4a,&H7c,&H0f,&H9e,&H16,&H2b,&Hce,&H33,&H57,&H6b,&H31,&H5e,&Hce,&Hcb,&Hb6,&H40,&H68,&H37,&Hbf,&H51,&Hf5)
Public q256$ =Chr$(&HFF,&HFF,&HFF,&HFF,&H00,&H00,&H00,&H00,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HFF,&HBC,&HE6,&HFA,&HAD,&HA7,&H17,&H9E,&H84,&HF3,&HB9,&HCA,&HC2,&HFC,&H63,&H25,&H51)


#include BigInt.def
Declare Sub GenerujObaKlice(prk$,pubk$)
Declare Function GenerujID_R1 () As String
Declare Function GenerujK_CS () as String
Declare Function PorovnejR (R$) As String

Sub GenerujObaKlice(prk$,pubk$)

private temp$
private test%
private q%
private cislo^

Private I : For I = 1 To 32
q% = q%+ Asc(Left$(Mid$(q256$, I), 1))
next I


Do 
Do 
cislo^ = Rnd
if cislo^ > q% then
cislo^ = cislo^  mod q%
end if
Loop Until cislo^ > 1 
temp$ = temp$+Hex$(cislo^)
Loop while Len(temp$) < 33
prk$= Mid$(temp$,1,32)

     test% = BigIntCompare(prk$,q256$)
   if test% <> -1 then 
   exit
   end if
  
temp$ =""
  temp$= G256$
  call EcpMultiplyPoint(temp$,prk$)
  
pubk$ = temp$
end sub


Function GenerujID_R1 () As String
private temp$
Do
temp$ = temp$ + Hex$(Rnd)
Loop while len(temp$)<9
  temp$ =Mid$(temp$,1,8)
  GenerujID_R1 = temp$

End Function


Function GenerujK_CS () as String
private temp$

Do
temp$ = temp$ + Hex$(Rnd)
Loop while len(temp$)<33
  temp$ =Mid$(temp$,1,32)
  GenerujK_CS  = temp$
  
end function 


Function Vyzva () As String

Private temp$
Do
temp$ = temp$ + Hex$(Rnd)
Loop while len(temp$)<33
  temp$ =Mid$(temp$,1,32)
  Vyzva  = temp$


End Function

