Skip to content

Instantly share code, notes, and snippets.

@AshyIsMe
Created September 12, 2021 06:09
Show Gist options
  • Save AshyIsMe/1c49716365f6ac07c0a74bad9f984ae7 to your computer and use it in GitHub Desktop.
Save AshyIsMe/1c49716365f6ac07c0a74bad9f984ae7 to your computer and use it in GitHub Desktop.
md5 hashing in j
0 : 0
Can you crack Aaron’s password hash? He seems to like
simple passwords. I’m sure he’ll use his name and birthday | in it. Hint: Aaron writes important dates as YYYYMMDD
rather than YYYY-MM-DD or any other special character | separator. Hash: 7f4986da7d7b52fa81f98278e6ec9dcb.
Author: moat, Pacific Northwest National Laboratory
)
y=:":"0 (1900 + i.120)
m=:(i.11) { ('0' ,"1 ":"0 (1+i.9)) , ('1' ,"1 ":"0 (1+i.9))
d=:('0' ,"1 ":"0 (1+i.9)) , (":"0) 10+i.22
md5=:15&(128!:6)
NB. md5 'foo'
NB. acbd18db4cc2f85cedef654fccc4a4d8
@AshyIsMe
Copy link
Author

require 'format/printf'
dates=:,/ (1+i.31) ,"1 0/~ ,/ (1900+i.120) ,"0/ (1+i.12)
sdates =: '%d%02d%02d' sprintf dates

passwords=:'Aaron',"1 1 sdates
hashes=:md5 passwords

NB. Compare the needle with the haystack.
NB. This compares each character and returns a list of bools for each comparison.
NB. Then we sum the bits together.
sums =: +/"1 '7f4986da7d7b52fa81f98278e6ec9dcb' ="1 1 hashes

NB. Find the index of a match
sums i: 32

NB. Grab the matching password
(sums i: 32) { passwords

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment