Encrypted-book Reader

by Northstrix in Circuits > Microcontrollers

491 Views, 4 Favorites, 0 Comments

Encrypted-book Reader

IMG_20220718_142448_hdr.jpg

Encrypted-book reader is a device that literally reads encrypted electronic books.

The idea to make this device came to me when I was learning how to work with the SD card. At one point, I realized I could make a device that reads encrypted electronic books. So, I made it.

Supplies

  • ESP8266 x1
  • 1.77 Inch TFT LCD with ST7735 x1
  • SD Card Reader Module x1
  • SD card x1
  • Buttons x2
  • 4.7k resistors x2

Encryption Algorithm

Encryption algorithm.png

Both book encrypter software and ESP8266 are making use of the 3DES encryption algorithm in CTR mode to encrypt and decrypt books.

CTR mode means counter mode. In that mode (at least in that implementation), key increments each time after the block is encrypted. So, each block is encrypted with its own key.

Now, let me give you a brief explanation of how the encryption process works.

First, the plaintext gets split into 64-bit (8 characters) blocks. If the length of an input block isn't equal to 64-bit, then the padding is applied. After that, the block gets split into eight equal parts. Each part goes through Rijndael's forward S-box. The resulted output is fed to the 3DES alongside a key that consists of the three parts. When the encryption process is completed, 3DES produces 64-bits of the ciphertexts that are presented in the hexadecimal form. Now, it's time to increment each third of the key by one and encrypt the next block.

The decryption process is done in exactly reverse order, except for the type of the S-boxes used. There are inverse S-boxes instead of the forward ones.

Install Drivers and Configure Arduino IDE *Optional

If you've never flashed ESP8266 before you'll need to configure Arduino IDE and install drivers to upload the firmware to the board, you can find drivers here:

CH340 driver: https://sparks.gogo.co.nz/ch340.html

CP210x driver: https://www.silabs.com/developers/usb-to-uart-brid...

In case you don't have Arduino IDE, you can download it here:

https://www.arduino.cc/en/software/

Configuring IDE isn't a part of this tutorial, you can read about it here:

https://randomnerdtutorials.com/how-to-install-esp...

Download Firmware From GitHub

Untitled.png

Download and Install Necessary Libraries

Adafruit-GFX-Library: https://github.com/adafruit/Adafruit-GFX-Library

Adafruit_ILI9341: https://github.com/adafruit/Adafruit_ILI9341

Adafruit_BusIO: https://github.com/adafruit/Adafruit_BusIO

DES_Library: https://github.com/fcgdam/DES_Library

SD: https://github.com/arduino-libraries/SD

The process of unpacking libraries is typical. You can unpack the content of the archive into the folder: ...\Arduino\libraries. Or open the Arduino IDE, click to the Sketch -> Include Library -> Add .ZIP Library... and select every archive with libraries.

Generate Key

IMG_20220717_161851.jpg

You can do it by any means possible.

The best way to do it is to throw 20-sided dice.

If you get a number from 1 to 9, write it down. If you get a number from 10 to 15, write down a letter corresponding to that number.

10 = A;

11 = B;

12 = C;

13 = D;

14 = E;

15 = F.

If you get 20, write down 0.

If you get something else, throw the dice again.

Modify Firmware

mf.png

Open the file "Firmware_for_ESP8266.ino" and replace my key with the one you've generated.

Flash the ESP8266

8266.png

Upload the firmware from the folder "Firmware_for_ESP8266" into the ESP8266.

Assemble the Device

Circuit diagram of the vault.png

Prepare SD Card

Untitled.png

If your SD card isn't already formatted to the FAT32, you need to format it. On Windows, it shouldn't be hard: right-click on the volume, press "Format...," make sure to match the parameters on the screenshot, and then press "Start."

Get the Book in the Text Format

1.png
2.png
4.png

First of all, you need to find the book you want to encrypt. There are many websites where you can find it, for example, Project Gutenberg (not a promotion of the website, I just found it to be convenient). Then you need to get the book in either UTF-8 or ASCII encoding. After that, copy the text of the entire book (Ctrl + A) and paste it into a text document (Ctrl + V), name the file however you want and save it.

Create File With the Key

3.png

You need the key to encrypt the book. Just copy this segment from the firmware into the text file, name the file however you want, and save it.

byte des_key[] = { 
                  0x3C, 0x77, 0x6C, 0xBC, 0xFA, 0x4A, 0xD7, 0x17,
                  0x5C, 0x82, 0x9A, 0x21, 0xF4, 0xB0, 0x93, 0xEA,
                  0x14, 0xF7, 0x3B, 0xC8, 0x4C, 0x8A, 0x50, 0x67
                };

Encrypt Book

6.png
7.png
8.png
9.png
10.png
11.png
12.png
13.png

To encrypt the book:

1) Launch either "Book Encrypter.exe" or "Book Encrypter.jar" from the "Book Encrypter" folder;

2) Click File -> Select encryption key;

3) Navigate to the file with the key, select it, and press the "Open" button;

4) Click File -> Encrypt Book;

5) Navigate to the book, select it, and press the "Open" button;

6) Wait till the inscription "Encrypting book. It might take several minutes." will change to "Select the book to encrypt."

The encrypted book will appear in the same folder as the original book, with only one difference - It will have a ".encr" extension.

The UI is a bit deceptive though the inscription "Encrypting book. It might take several minutes." appears when you click File -> Encrypt Book, not when the encryption process actually starts.


When you're done with the encryption process, move all encrypted books to the SD card. The name and the extension of the books are irrelevant.


I renamed "Promised Land.txt.encr" to "Book"


Insert SD Card and Power the Device Up

IMG_20220718_141159_hdr.jpg

Insert the SD card first, and then power the device up. If there's a problem along the way, you'll see the inscription "SD card initialization failed."

The device is controlled by two buttons:

The button connected to the D0 pin is the "OK/Next page" button;

The button connected to the D1 pin is the "Next file/Close book" button.


While in the main menu, hold the button connected to the D1 pin for roughly 0.3 seconds to select the book you want to read, and then hold the button connected to the D0 pin for the same amount of time to open the selected book.


While reading the book, hold the button connected to the D0 pin to get to the next page, and hold button connected to the D1 pin to close the book and return to the main menu.


Important note! If you want to reboot the device, don't do this by pressing the reboot button on the ESP8266. Unplug the cable and plug it back instead because you need to reboot the SD card too.

Read the Book

IMG_20220718_142212_hdr.jpg
IMG_20220718_142231_hdr.jpg
IMG_20220718_142300_hdr.jpg
IMG_20220718_142343_hdr.jpg
IMG_20220718_142448_hdr.jpg

Finally, you can read a book on this "unconventional" device.

That's it for this tutorial.

I hope you will find a good use for this device.

If you like this tutorial, please share it.

Thank you for reading this tutorial.