Question

I run echo lol | md5 in Mac Terminal and it returns: 59bcc3ad6775562f845953cf01624225

But then I run print hashlib.md5("lol").hexdigest() in python 2.7 and I get: 9cdfb439c7876e703e307864c9167a15

What am I doing wrong?

Was it helpful?

Solution

echo appends a newline at the end by default, so it will give a different hash.

In python, with the newline ending

>>> print hashlib.md5("lol\n").hexdigest()
59bcc3ad6775562f845953cf01624225

Standard echo command, with the newline ending omitted.

$ echo -n lol | md5sum -
9cdfb439c7876e703e307864c9167a15  -
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top