MarpaX-Hoonlint

 view release on metacpan or  search on metacpan

hoons/arvo/sys/zuse.hoon  view on Meta::CPAN

      $%  {$hear p/lane q/@}                            ::
          {$mess p/ship q/path r/*}                     ::  send message
          {$wake $~}                                    ::
      ==                                                ::
    ++  card                                            ::  out cards
      $%  {$west p/ship q/path r/*}                     ::  network request
      ==                                                ::
    ++  sign                                            ::  in response $-<
      $:  $g                                            ::
          $%  {$rend p/path q/*}                        ::  network request
              {$mack p/(unit tang)}                     ::  message ack
      ==  ==                                            ::
    ++  note                                            ::  out request $->
      $%  {$c $west p/ship q/path r/*}                  ::  to %clay
          {$e $west p/ship q/path r/*}                  ::  to %eyre
          {$g $west p/ship q/path r/*}                  ::  to %gall
          $:  $j                                        ::  to %jael
              $%  {$line p/ship q/@da r/code}           ::
                  {$link p/ship q/@da r/code}           ::
                  {$meet p/farm:pki:jael}               ::
                  {$veil p/ship}                        ::
                  {$west p/ship q/path r/*}             ::  to %gall
      ==  ==  ==                                        ::
    --  ::  able
  ::
  ::::                                                  ::  (1i2)
    ::
  ++  code  @uvI                                        ::  symmetric key
  ++  lane                                              ::  packet route
    $%  {$if p/@da q/@ud r/@if}                         ::  IP4/public UDP/addr
        {$is p/@ud q/(unit lane) r/@is}                 ::  IPv6 w+alternates
        {$ix p/@da q/@ud r/@if}                         ::  IPv4 provisional
    ==                                                  ::
  ++  life  @ud                                         ::  regime number
  --  ::xmas
--  ::
::                                                      ::  ::
::::                                                    ::  ::  (2) engines
  ::                                                    ::  ::
|%
::                                                      ::::
::::                      ++number                      ::  (2a) number theory
  ::                                                    ::::
++  number  ^?
  |%
  ::                                                    ::  ++fu:number
  ++  fu                                                ::  modulo (mul p q)
    |=  a/{p/@ q/@}
    =+  b=?:(=([0 0] a) 0 (~(inv fo p.a) (~(sit fo p.a) q.a)))
    |%
    ::                                                  ::  ++dif:fu:number
    ++  dif                                             ::  subtract
      |=  {c/{@ @} d/{@ @}}
      [(~(dif fo p.a) -.c -.d) (~(dif fo q.a) +.c +.d)]
    ::                                                  ::  ++exp:fu:number
    ++  exp                                             ::  exponent
      |=  {c/@ d/{@ @}}
      :-  (~(exp fo p.a) (mod c (dec p.a)) -.d)
      (~(exp fo q.a) (mod c (dec q.a)) +.d)
    ::                                                  ::  ++out:fu:number
    ++  out                                             ::  garner's formula
      |=  c/{@ @}
      %+  add  +.c
      %+  mul  q.a
      %+  ~(pro fo p.a)  b
      (~(dif fo p.a) -.c (~(sit fo p.a) +.c))
    ::                                                  ::  ++pro:fu:number
    ++  pro                                             ::  multiply
      |=  {c/{@ @} d/{@ @}}
      [(~(pro fo p.a) -.c -.d) (~(pro fo q.a) +.c +.d)]
    ::                                                  ::  ++sum:fu:number
    ++  sum                                             ::  add
      |=  {c/{@ @} d/{@ @}}
      [(~(sum fo p.a) -.c -.d) (~(sum fo q.a) +.c +.d)]
    ::                                                  ::  ++sit:fu:number
    ++  sit                                             ::  represent
      |=  c/@
      [(mod c p.a) (mod c q.a)]
    --  ::fu
  ::                                                    ::  ++pram:number
  ++  pram                                              ::  rabin-miller
    |=  a/@  ^-  ?
    ?:  ?|  =(0 (end 0 1 a))
            =(1 a)
            =+  b=1
            |-  ^-  ?
            ?:  =(512 b)
              |
            ?|(=+(c=+((mul 2 b)) &(!=(a c) =(a (mul c (div a c))))) $(b +(b)))
        ==
      |
    =+  ^=  b
        =+  [s=(dec a) t=0]
        |-  ^-  {s/@ t/@}
        ?:  =(0 (end 0 1 s))
          $(s (rsh 0 1 s), t +(t))
        [s t]
    ?>  =((mul s.b (bex t.b)) (dec a))
    =+  c=0
    |-  ^-  ?
    ?:  =(c 64)
      &
    =+  d=(~(raw og (add c a)) (met 0 a))
    =+  e=(~(exp fo a) s.b d)
    ?&  ?|  =(1 e)
            =+  f=0
            |-  ^-  ?
            ?:  =(e (dec a))
              &
            ?:  =(f (dec t.b))
              |
            $(e (~(pro fo a) e e), f +(f))
        ==
        $(c +(c))
    ==
  ::                                                    ::  ++ramp:number
  ++  ramp                                              ::  make r-m prime
    |=  {a/@ b/(list @) c/@}  ^-  @ux                   ::  {bits snags seed}
    =>  .(c (shas %ramp c))
    =+  d=*@
    |-



( run in 2.333 seconds using v1.01-cache-2.11-cpan-302cb4679cc )