❯ ./bin/test_sha --arg foo 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
❯ echo foo | sha256sum - b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c -
On 2023-11-04 15:39, wvxvw wrote:
❯ ./bin/test_sha --arg foo
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
❯ echo foo | sha256sum -
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c -
I think the problem may be that echo adds an LF:
$ echo foo | hd
00000000 66 6f 6f 0a |foo.|
Since sha256sum expects to work on arbitrary files, it would include the
LF in its input.
I think the problem may be that echo adds an LF:
$ echo foo | hd
00000000 66 6f 6f 0a |foo.|
Since sha256sum expects to work on arbitrary files, it would include
the LF in its input.
"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> writes:
I think the problem may be that echo adds an LF:
$ echo foo | hd
00000000 66 6f 6f 0a |foo.|
Since sha256sum expects to work on arbitrary files, it would include
the LF in its input.
Hi, thanks for the idea, but no, that's not it.
Eg, with GNAT.SHA256 for string "foo" I get:
❯ ./bin/test_sha --arg foo 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
With the line end added
I get 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61
from Ada.
On 2023-11-04 17:09, Jeffrey R.Carter wrote:
On 2023-11-04 15:39, wvxvw wrote:
❯ ./bin/test_sha --arg foo
2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
❯ echo foo | sha256sum -
b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c -
I think the problem may be that echo adds an LF:
$ echo foo | hd
00000000 66 6f 6f 0a |foo.|
Since sha256sum expects to work on arbitrary files, it would include the LF in
its input.
Hi, thanks for the idea, but no, that's not it. With the line end added
I get 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61
from Ada.
Some implementations of "echo" accept an option "-n" to suppress the trailing newline (LF). The OP could try that option as a quick check of this answer (which seems very plausible).
Ah! You didn't add a newline! I can get the same hash by guesswork:
$ printf foo\\\\n >input
$ sha256sum input 04e1806fda6bdbc9e5e3534edd993c7c2bf03173f5489742db53d1e8b0ef8c61 input
$ hd input
00000000 66 6f 6f 5c 6e |foo\n|
00000005
What you added to the test string was a backslash and a letter n.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 355 |
Nodes: | 16 (2 / 14) |
Uptime: | 29:23:41 |
Calls: | 7,658 |
Calls today: | 2 |
Files: | 12,815 |
Messages: | 5,700,934 |