3

A small part of a lab I am working on for school has asked me to take a file, hash the value using openssl sha256 and then change 1 bit, rehash it and compare the values. Specifically they want me:

"You can write a short program to count how many bits are the same between H1 and H2"

Currently the output form is a hex dump and whenever I try to add the -binary to the openssl command such as:

openssl dgst -sha256 -binary largefile.txt > hashInBinary.txt

I keep receiving symbols that I cannot read instead of 1s and 0s. I am really not sure how to approach this in any other way at this point. I dont understand why I am not receiving the binary format (1010101011) of the hash value when I add -binary. Any thoughts?

1 Answers1

2

Based on "I keep receiving symbols that I cannot read" I assume you actually get a binary output. So 1's and 0's. The problem is that your editor tries to represent it in a readable format, thus it expects some kind of encoding (lets say ascii). It reads one byte and prints it on the screen. However, you want to see values on a binary level, not a byte level.

You can use xxd -b hashInBinary.txt to see what is the result of the hashing.

Marek Klein
  • 1,410
  • 12
  • 20