Author

Topic: Why is the result of sha256 the same for inputs 0 to 15? (Read 86 times)

legendary
Activity: 1778
Merit: 1070
Thx again.
legendary
Activity: 4326
Merit: 3041
Vile Vixen and Miss Bitcointalk 2021-2023
legendary
Activity: 1778
Merit: 1070
So, to do it correctly, if bc returns an odd number of digits, would it be correct to add a 0 at the beginning of the hex-string?
legendary
Activity: 1778
Merit: 1070
Because converting hex digits into bytes requires an even number of the former, since each byte requires two hex digits. In particular, xxd drops the last hex digit if there are an odd number of them, and if this results in a zero-length input, it will produce a zero-length output (compare your hash to the output of "echo -n | sha256sum").

I see. This makes sense! Cheesy

Thank you very much.
legendary
Activity: 4326
Merit: 3041
Vile Vixen and Miss Bitcointalk 2021-2023
Because converting hex digits into bytes requires an even number of the former, since each byte requires two hex digits. In particular, xxd drops the last hex digit if there are an odd number of them, and if this results in a zero-length input, it will produce a zero-length output (compare your hash to the output of "echo -n | sha256sum").
legendary
Activity: 1778
Merit: 1070
Just for curiosity:

Why does

Code:
echo "obase=16;ibase=10;$var" | bc | xxd -p -r | sha256sum

result in

Code:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

where $var is in {"0", ..., "15"}?

Thx.
Jump to: