Hi guys,
Hi have a little problem with md5 digest.I want to translate in bash language this function in python:
digest = int(md5(value).hexdigest(),16)
(it's an md5 update)
how i "translate" this function in bash or openssl utility in bash?
Thanks
pludi
2
Roughly?
digest=$( echo "ibase=16; $( echo $value | md5sum | cut -f1 -d ' ' | tr '[a-z]' '[A-Z]' )" | bc )
Thanks but not the same result:(
For example
echo -n "0011223344556677889910111213141516171819"|md5sum| cut -f1 -d ' ' | tr '[a-z]' '[A-Z]' | bc
19498340999655919679390993985391
and the pyton gives:
digest = int(md5(0011223344556677889910111213141516171819).hexdigest(),16)
37615660562377680210092719805016069009
whats the matter??
pludi
4
It's because you didn't specify the input base. Compare
$ echo -n "0011223344556677889910111213141516171819" | md5sum | cut -f1 -d ' ' | tr '[a-z]' '[A-Z]' | bc
19498340999655919679390993985391
$ ( echo "ibase=16"; echo -n "0011223344556677889910111213141516171819" | md5sum | cut -f1 -d ' ' | tr '[a-z]' '[A-Z]' ) | bc
37615660562377680210092719805016069009
From man man bc (Linux) (emphasis added)
That means that, with an ibase default of 10, A-F are changed to the number 9:
$ echo -n "0011223344556677889910111213141516171819" | md5sum | cut -f1 -d ' ' | tr '[a-z]' '[A-Z]'
1C4C8340AAE655C1F67F3F0CF3A85391
$ echo -n "0011223344556677889910111213141516171819" | md5sum | cut -f1 -d ' ' | tr '[a-z]' '[A-Z]'| bc
19498340999655919679390993985391