From 49cde8eea4314a46fd9eb6eb4729f862868be6e0 Mon Sep 17 00:00:00 2001 From: John Dulin Date: Tue, 20 May 2014 22:43:21 -0700 Subject: [PATCH] Moved api helper arms into zuse. Added factorial ("fac") and Uppercase ("cuss") arms to hoon.hoon. --- arvo/hoon.hoon | 14 +++++++++++++- arvo/zuse.hoon | 32 +++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index a58c44657..e9a71d569 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -477,6 +477,13 @@ c $(a (sub a b), c +(c)) :: +++ fac :: factorial + |= a=@ :: This should be jetted. + ^- @ + ?: =(0 a) + 1 + (mul a $(a (dec a))) +:: ++ gte :: greater-equal ~/ %gte |= [a=@ b=@] @@ -828,7 +835,7 @@ (mod c (bex (mul (bex a) b))) :: ++ fil :: fill bloqstream - |= [a=bloq b=@ c=@] + |= [a=bloq b=@ c=@] =+ n=0 =+ d=c |- ^- @ @@ -2222,6 +2229,11 @@ |= vib=tape %+ rap 3 (turn vib |=(a=@ ?.(&((gte a 'A') (lte a 'Z')) a (add 32 a)))) +++ cuss :: uppercase + |= vib=tape + ^- @t + %+ rap 3 + (turn vib |=(a=@ ?.(&((gte a 'a') (lte a 'z')) a (sub a 32)))) :: ++ crip |=(a=tape `@t`(rap 3 a)) ++ mesc diff --git a/arvo/zuse.hoon b/arvo/zuse.hoon index 67f32385f..2e6d814eb 100644 --- a/arvo/zuse.hoon +++ b/arvo/zuse.hoon @@ -577,6 +577,18 @@ ?. &(?=(^ tin) =(key p.u.tin) =(msg q.u.tin)) ~|(%test-fail-seal !!) msg +:: +++ hmac :: HMAC calculation + |= [key=@ mes=@] + =+ ip=(fil 2 64 0x36) + =+ op=(fil 3 64 0x5c) + =+ ^= kex + ?: (gth (met 3 key) 64) + (lsh 3 44 (shan (swap 3 key))) + (lsh 3 (sub 64 (met 3 key)) (swap 3 key)) + =+ inn=(shan (swap 3 (cat 3 (swap 3 mes) (mix ip kex)))) + (shan (swap 3 (cat 3 inn (mix op kex)))) +:: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: section 3bC, UTC :: Gregorian only :: @@ -652,7 +664,10 @@ ;~(sfix dim:ag col) dim:ag (cold ~ (star next)) == [[%.y &3.tuc] &2.tuc &1.tuc &4.tuc &5.tuc &6.tuc ~] - +:: +++ unt :: UGT to UTC time + |= a=@ + (div (sub a ~1970.1.1) (bex 64)) :: ++ yu :: UTC format constants |% @@ -1486,6 +1501,21 @@ ?~(nex ~ [~ [`@`u.val u.nex]]) =+ nex=$(tep t.tep) ?~(nex ~ [~ i.tep u.nex]) +++ sifo :: 64-bit encode + |= tig=@ + ^- tape + =+ poc=(mod (sub 3 (mod (met 3 tig) 3)) 3) + =+ pad=(lsh 3 poc (swap 3 tig)) + =+ ^= ska + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + =+ ^= sif + %- flop + |- ^- tape + ?~ pad + ~ + =+ d=(end 0 6 pad) + [(snag d ska) $(pad (rsh 0 6 pad))] + (weld (scag (sub (lent sif) poc) sif) (trip (fil 3 poc '='))) :: ++ earl :: local purl to tape |= [who=@p pul=purl]