Hello,
I wanted to see if J could be faster than bespoke C programs (specifically 
aircrack-ng, ~10k/s on my machine).
From the wiki pages for SHA1 (turns outs there exists a foreign so I dropped 
it), HMAC, and PBKDF2I assembled:
sha1=:1&(128!:6)
bs=:512%8 NB. block size in bytes for md5, sha1, sha224, sha256
opad=:bs(([,(#@]))$])0 1 0 1 1 1 0 0 NB. 0x5c, outer padding byte up to block 
size
ipad=:bs(([,(#@]))$])0 0 1 1 0 1 1 0 NB. 0x36, inner padding byte up to block 
size

hmac=:{{)a NB. assuming y of form 'key';'msg'
if.bs&<@#key=.{.>y do.key=.u key end. NB. use hash of key as key, if greater 
than block size
key=.((],(((bs&-@#),8:)$0:))@((8:#2:)#:(a.&i.)))key NB. pad 0s to right up to 
block size; do 8 bits of ascii
u(({&a.@#.(key~:opad)),u(({&a.@#.(key~:ipad)),{:>y))
}}

sha1 hmac 'key';';msg'
I am getting the wrong hashes back with examples from the wiki examples, ones 
generated from https://cryptotools.net/hmac What exactly am I missing?

Cheers, v
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to