RSA - 6


if (s1<>s2) then

begin

WriteLn(':

!');

WriteLn(' Enter .'); ReadLn;

Halt(1);

end;

WriteLn('OK');

WriteLn;

// .

WriteLn('--------------------------------------------------');

BN_bignum_to_hex(e,s1);

WriteLn(' e = 0x',s1,' (',BN_a_upbit(e),'bit)');

BN_bignum_to_hex(d,s1);

WriteLn(' d = 0x',s1,' (',BN_a_upbit(d),'bit)');

BN_bignum_to_hex(n,s1);

WriteLn(' n = 0x',s1,' (',BN_a_upbit(n),'bit)');

WriteLn('--------------------------------------------------');

WriteLn;

WriteLn(' : ',IntToStr(BN_a_upbit(n)-1),' ');

WriteLn(' : ',IntToStr(BN_a_upbit(n)),' bit');

WriteLn;

WriteLn(' Enter .'); ReadLn;

end.

18.2. uBigNumber

unit uBigNumber;

{$IFDEF FPC}

{$MODE DELPHI}

{$ASMMODE INTEL}

{$ENDIF}

18.2

interface

const BIGNUM_DWORD = 31;

type TBigNum = array[0..BIGNUM_DWORD] of Cardinal;

procedure BN_bignum_to_hex(var a: TBigNum; var s: string);

procedure BN_hex_to_bignum(var s: string; var a: TBigNum);

procedure BN_bignum_to_dec(var a: TBigNum; var s: string);

procedure BN_dec_to_bignum(var s: string; var a: TBigNum);

function BN_a_cmp_b(var a,b: TBigNum): Integer;

procedure BN_a_add_b(var a,b,res: TBigNum);

procedure BN_a_sub_b(var a,b,res: TBigNum);

procedure BN_a_mul_b(var a,b,res: TBigNum);

procedure BN_a_shl_k(var a: TBigNum; k: Integer;

var res: TBigNum);

procedure BN_a_shr_k(var a: TBigNum; k: Integer;

var res: TBigNum);

function BN_a_upbit(var a: TBigNum): Integer;

procedure BN_a_setbit_k(var a: TBigNum; k: Integer);

procedure BN_a_mod_b(var a,b,res: TBigNum);

procedure BN_a_div_b(var a,b,res: TBigNum);

procedure BN_a_exp_b_mod_c(var a,b,c,res: TBigNum);

procedure BN_ab_GCD(var a,b,res: TBigNum);

procedure BN_a_modinv_b(var a,b,res: TBigNum);