1

So for a school assignment we are working with hashes. However I've encountered a problem where my file.txt containing:

test hashes
test hashes

without quotes doesn't match the hash from HashCalc (for windows) and http://www.md5hashgenerator.com/ both come up with cd7e8e88f33efb42e0a1148e92c5005b while md5sum on my kali linux comes up with f3c5fdf4320346eb9bd2a6b64235248e using

head -c -1 file.txt | md5sum

It works fine with just one line of test hashes, but with the second line I can't make it match.

  • 1
    cd7e8e88f33efb42e0a1148e92c5005b is the md5 hash for both lines combined with a newline character which seperates the first line from the second. – Ramhound Mar 27 '17 at 20:57
  • You have not told us what MD5 hash you actually are expecting. – Ramhound Mar 27 '17 at 21:02
  • I am expecting the one ending in 5005b to come up in md5sum and I want to know why they don't match. Isn't the algorithm the same? – James Mar 27 '17 at 21:06
  • If you are expecting the 5005b, then your command isn't correct. You currently are only getting a single line, whereas, you would need both lines to generated 5005b. Your current command is only reading 1 byte. You should be using the -n option not the -c option. You should provide us the string that generated 35248e – Ramhound Mar 27 '17 at 21:11
  • The head Command – Ramhound Mar 27 '17 at 21:11
3
$ echo -ne "test hashes\ntest hashes" | md5sum                                   
f3c5fdf4320346eb9bd2a6b64235248e  -
$ echo -ne "test hashes\r\ntest hashes" | md5sum                                 
cd7e8e88f33efb42e0a1148e92c5005b  -

It's about Unix (\n) vs. DOS line ending (\r\n).

You can convert Unix line endings to DOS ones with unix2dos:

$ echo -ne "test hashes\ntest hashes" | unix2dos | md5sum
cd7e8e88f33efb42e0a1148e92c5005b  -

The reverse command is dos2unix.

| improve this answer | |
  • Now we're getting somewhere. That explains why it isn't working so how would I add the \r into an entire file so the hash is the same for a .txt file windows and linux? EDIT: I mean a file created in windows and a file created in linux – James Mar 27 '17 at 21:19
  • Sorry confusing question. better phrased: What terminal command can I use to get the 5005b hash in linux for a file rather than an echo? – James Mar 27 '17 at 21:28
  • @James I have expanded my answer. – Kamil Maciorowski Mar 27 '17 at 21:40
  • Perfect that unix2dos is exactlywhat i was missing – James Mar 27 '17 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.