Skip to content

Instantly share code, notes, and snippets.

@williamhaley
Last active January 20, 2021 20:51
Show Gist options
  • Save williamhaley/31188a4b4c64736a43d9e4d04551589f to your computer and use it in GitHub Desktop.
Save williamhaley/31188a4b4c64736a43d9e4d04551589f to your computer and use it in GitHub Desktop.
A demonstration of encryption vs hashing using the full English text of the book, Alice in Wonderland

Plain text / source material

Here is the plain text English full version of Alice in Wonderland.

Hashed

Here is a hash of the entire book. Every single word, punctation mark, space, etc.

c8f5de222fcf1804197e97b0df02d30d25ab70715fcf93bb8d61c0f7b2c13acb

That's it. That's the whole hash for the entirety of the book. It was created with this command.

sha256sum alice_in_wonderland.txt > alice_in_wonderland.hashed.txt

Note that the hashed data is relatively short given how long the book is. It's a summary, a unique identifier, it is the result of "boiling down" the contents of alice_in_wonderland.txt to a single unique value. We cannot realistically work backwards from this hash to produce the full contents of alice_in_wonderland.txt again.

Encrypted

Here is an encrypted version of alice_in_wonderland.txt created with this command.

gpg --cipher-algo AES256 --symmetric --output alice_in_wonderland.enc.txt alice_in_wonderland.txt

Note that the encrypted data is roughly similar to the length of the book. It's the original content, but transformed to be unreadable without the password, and it can be reversed to reveal the original content if the password is known. See here the command to decrypt the data.

gpg -o alice_in_wonderland.decrypted.txt -d alice_in_wonderland.enc.txt

The encrypted data can be reversed to restore the original plain text contents of alice_in_wonderland.txt. The password is "password".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment