Hacker News new | ask | show | jobs
by yubiox 807 days ago
What am I doing wrong here? echo "To begin with, for example, and to make sure your SHA-256 hash function is working, the hash value or checksum of this sentence, from capital 'T' to concluding colon, expressed in hexadecimal, is:" | sha256sum

95f5ed58505e08180eaa94f4eb13a0d2003cfe042116fa1767c2189491c36871 which is not

10c0c7d9b0222a5a61601337105f1cbb7b1723b991404b870537095d1174f2b2

2 comments

Add the -n flag to echo

echo -n "To begin with, for example, and to make sure your SHA-256 hash function is working, the hash value or checksum of this sentence, from capital 'T' to concluding colon, expressed in hexadecimal, is:" | sha256sum

Echo is automatically adding a newline

Editors like vi also add automatically add newlines to the end. You can check with hexdump if you have a newline or not:

    $ echo "To begin with, for example, and to make sure your SHA-256 hash function is working, the hash value or checksum of this sentence, from capital 'T' to concluding colon, expressed in hexadecimal, is:" | hexdump -C
    00000000  54 6f 20 62 65 67 69 6e  20 77 69 74 68 2c 20 66  |To begin with, f|
    00000010  6f 72 20 65 78 61 6d 70  6c 65 2c 20 61 6e 64 20  |or example, and |
    00000020  74 6f 20 6d 61 6b 65 20  73 75 72 65 20 79 6f 75  |to make sure you|
    00000030  72 20 53 48 41 2d 32 35  36 20 68 61 73 68 20 66  |r SHA-256 hash f|
    00000040  75 6e 63 74 69 6f 6e 20  69 73 20 77 6f 72 6b 69  |unction is worki|
    00000050  6e 67 2c 20 74 68 65 20  68 61 73 68 20 76 61 6c  |ng, the hash val|
    00000060  75 65 20 6f 72 20 63 68  65 63 6b 73 75 6d 20 6f  |ue or checksum o|
    00000070  66 20 74 68 69 73 20 73  65 6e 74 65 6e 63 65 2c  |f this sentence,|
    00000080  20 66 72 6f 6d 20 63 61  70 69 74 61 6c 20 27 54  | from capital 'T|
    00000090  27 20 74 6f 20 63 6f 6e  63 6c 75 64 69 6e 67 20  |' to concluding |
    000000a0  63 6f 6c 6f 6e 2c 20 65  78 70 72 65 73 73 65 64  |colon, expressed|
    000000b0  20 69 6e 20 68 65 78 61  64 65 63 69 6d 61 6c 2c  | in hexadecimal,|
    000000c0  20 69 73 3a 0a                                    | is:.|
    000000c5
If the string or file ends in `0a` you have a newline
To add to this, I solved the first puzzle but I'm not getting the right sha256sum for the answer. It's unclear to me which part of the deciphered text I should be doing the checksum on.

The text says: "here are the checksums for all the solutions to the eighty-nine puzzles", is the solution only the newly readable part, or the whole new text that has been transformed?

The whole new text that has been transformed.

A little earlier, the editorial instructions read: "These hash values, or checksums [...], were generated by the SHA-256 algorithm -- implementations of which you should easily be able to find and run on your own plaintexts. (By "plaintext", I mean the entire rest of the file, correctly deciphered -- of which, however, only the next chapter will be legible ... until the subsequent decipherment, and so on.)"

Is that helpful?

You should be (1) deleting everything up to and including "1.#####", then (2) applying the appropriate transformation to what remains. Looking at my code for this step, I see that I removed one newline character at the end of the file before doing everything else, and this apparently yielded the correct result; I didn't do this in subsequent steps.

(I've been playtesting this thing for a while. I'm not all the way through yet.)

>I see that I removed one newline character at the end of the file

Hm, strange. I don't see, and there shouldn't be, an extraneous newline at the end of the (original) file.

Interesting: maybe I added it by mistake in a text editor mishap or something :-).
Hmmm. The original, in fact, does NOT have the 0x0a at the end of the file; however, in process of deleting first part of file up through and including "1.#####", my linux command line tools (or vim?) added one there (unbeknownst to me at the time). I proceeded to solve first puzzle with the 0x0a there at the end in the head-shortened ciphertext, and I got readable plaintext, but my sha256sum does not match yours. If I remove the 0x0a, I get neither readable plaintext nor a matching sha256sum.

(btw, love this project, thanks for sharing it)

This is odd! We can visually troubleshoot this, and see that the first characters following 1.##### are «Cnrtltos » and the final characters at the end of the (original) file are «!niauago». Taking [SPOILER] alternately the first of the first and the last of the last gives us C, o, n, g, r, a, t, u, l, a, t, i, o, n, s, !. If there is an extraneous character inserted at the end, e.g. a newline, the transformation should be spoiled and illegible: C, newline, n, o, r, g, t, a, l, u, t, a, o, i, s, n, space, !.
Dunno if it's helpful for diagnosis, but my 01.txt that yields the expected sha256 sum ...

... is 0x3E1051 bytes long

... starts with <<Congratulations>>, as you already knew it should

... ends with <<IX%7M3+]vW7+zB]{\>>

(It couldn't be line-ending issues, could it? Do you have any 0x0D bytes?)

And, just in case it helps, my original text file (before stripping everything up to 1.#####, and _without_ the spurious 0x0A byte) is 0x3E404D bytes long and ends with << vhuY!niauago>>.