see
http://code.jsoftware.com/wiki/System/ReleaseNotes/J806

SHA1 was also implemented using pure J script.

On Dec 23, 2017 12:15 AM, "Danil Osipchuk" <[email protected]> wrote:

> Actually presence of 128!:6  is (good) news - it certainly was not there,
> thank you Bill (difficult to tell apart memory and imagination when getting
> older ). MD5 while being not recommended, I'm sure will be missed. As a
> side note: a somewhat neater version with ^: 'if idiom'
>
> hmac =: 2 : 0 NB. m is a key data, n is as 128!:6, result - a monad to sign
> y
>
> H =. (-|n)&(128!:6) NB. select hash function
>
> BS =. (|n) { 64 64 64 64 128 128 144 136 104 72 NB. select pad len / block
> size of a hash function
>
> K =. BS {.a.i. H^:(BS<#m) m NB. if m is longer than pad (block size of
> hash) compress key by hashing, extend by 0
>
> 'i o'=.a.{~16b36 16b5c (22 b.)"0 1 K NB. compute input and output pads from
> the key bytes
>
> n 128!:6 o, H i,y NB. calculate the final signature
>
> )
>
> danil@dwork:~/L/j64-805$ ./jconsole.sh
>    1 (128!:6 ) 'ASDF'
> |domain error
> |   1    (128!:6)'ASDF'
>    JVERSION
> Engine: j805/j64/linux
> Release-a: commercial/2017-02-26T16:47:20
> Library: 8.05.13
> Platform: Linux 64
> Installer: J805 install
> InstallPath: /home/danil/L/j64-805
> Contact: www.jsoftware.com
>
>
>
> 2017-12-22 13:16 GMT+03:00 bill lam <[email protected]>:
>
> > j806 j engine supports various sha, both hex and byte output.
> >
> > On Dec 22, 2017 4:51 PM, "Danil Osipchuk" <[email protected]>
> > wrote:
> >
> > > Below is a snippet I used to sign files with md5hmac, may be of some
> use.
> > > (I envy people easily reading other's J, I have difficulties reading
> > mine a
> > > while later )
> > > regards,
> > >   Danil
> > >
> > >
> > > qthash =: 4 : 0                        NB. taken from qt ide, x is hash
> > > algo name str, y is a data string, result is hex string of hash
> > >   c=.'"',libjqt,'" gethash ',(IFWIN#'+'),' i *c *c i * *i'
> > >   'r t m w p n'=. c cd (tolower x);y;(#y);(,2);,0
> > >   res=. memr p,0,n
> > >   if. r do. res (13!:8) 3 end.
> > >   res
> > > )
> > > bfh=:a.{~_2(16&#.)\'0123456789abcdef'i.]    NB. bytes from hex string
> > > (lowercase) (253*254)-:bfh 'fefc'
> > > md5b=: [:bfh 'md5'&qthash            NB. libjqt returns hex string as a
> > > hash - convert it to bytes
> > > hmac =: 1 : 0                         NB. m is a key data, return verb
> > > computing md5-based signature for y
> > >  if. 64<#m do. k=.md5b m else.k=.m end.        NB. if m is longer than
> > pad
> > > (64 - block of md5) use md5 hash as a key
> > >  kb=.64{.a.i.k                        NB. extend to 64 the key pad data
> > > with zero bytes
> > >  'i o'=.a.{~16b36 16b5c (22 b.)"0 1 kb        NB. compute input and
> > output
> > > pads from the key bytes
> > >  md5b o, md5b i,y                NB. calculate the final signature as
> in
> > > wikipedia
> > > )
> > > md5SgnDir =: 3 : 0                 NB. sign like CryproSign.jar:
> > md5SgnDir
> > > (<;._1)' ../sandbox *.cdr .md5 ../z/sssti_m7ium1_2016-05-25/
> > > crypto/key.txt'
> > >  'dr ms ex kf'=. y                NB. directory name, mask of the
> > filename,
> > > extension added to md5 sign file, key file name
> > >   mk=.(fread kf)hmac                    NB. load a keyfile into a verb
> > for
> > > computing signature
> > >  ((mk@:fread"0)fwrite"1 0(,&ex&.>"0))dr fdls ms    NB. calculate the
> > > signature of the content of each file and write to extended name
> > > )
> > >
> > > 2017-12-22 4:32 GMT+03:00 bill lam <[email protected]>:
> > >
> > > > if possible, please provide some examples or tests and I will add
> them
> > to
> > > > addons. Thanks
> > > > ------------------------------------------------------------
> ----------
> > > > For information about J forums see http://www.jsoftware.com/
> forums.htm
> > > >
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to