From 16769b488597ec01cfd95c825e90271b8a10162a Mon Sep 17 00:00:00 2001 From: samson <114964564+samsonjaw@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:28:15 +0800 Subject: [PATCH] Update README.md --- README.md | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 678e7b5..a18b7de 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,42 @@ AES is a symmetric encryption algorithm that operates on 128-bit blocks of plain - **Base64 Encoding/Decoding**: Encodes encrypted data to Base64 format to ensure safe text output and decodes it for decryption. - **PKCS7 Padding**: This method involves adding padding bytes that equal the number of bytes needed to reach a block size of 16. For instance, if one byte is needed, 0x01 is added; if two bytes are needed, two 0x02s are added, and so forth up to 15 bytes, which would be 0x0f. Uniquely, if the length is already a multiple of 16, an entire block of 16 bytes (0x10) is added. This ensures that during decryption, the value of the last byte indicates the number of padding bytes to remove -## Code Overview -- **Encryption Selection**: Users can select whether to encrypt or decrypt by entering '0' for encryption and '1' for decryption. -- **Text Format for Encryption**: Allows users to choose whether the plaintext should be in byte storage (raw text) or Base64 encoded before encryption. -- **Key Input**: Accepts a 128-bit key required for the AES encryption/decryption process. -- **Base64 Handling**: Automatically handles Base64 encoding for encrypted output and Base64 decoding for input to decryption. -![image](https://github.com/samsonjaw/AES/assets/114964564/adc83c16-9d78-46bd-a5f4-5e7e26090985) +## Usage +- Compile and run main.cpp together with other required modules using g++: +- Select a Function: +When prompted, choose either encryption (0) or decryption (1): +```markdown +===============================請選擇功能=============================== + 0. encrypt加密 + 1. decrypt解密 +輸入你的選擇(0/1) +``` +### Encryption +- Choose Plaintext Format: +Choose how you want to input the plaintext. You can input as regular byte storage(raw text) or Base64 encoded text which will be converted to byte storage before encryption: +```markdown +===============================明文格式================================= + 0. 字節儲存(常見的1byte儲存一個) + 1. Base64編碼(會先轉為字節儲存再加密) +輸入你的選擇(0/1) +``` +- Input the Plaintext: +Enter your plaintext as instructed. If Base64 option was selected, the input will be decoded first. +- Input the Key: +Enter a 128-bit key for the encryption. Ensure the key is exactly 16 bytes long. +- View Encrypted Result: +The program will display the encrypted text in hexadecimal format and then in Base64 encoded format. +### Decryption +- Input the Encrypted Text: +Enter the encrypted text in Base64 format, which will be decoded to byte storage format. +- Input the Key: +Enter the same 128-bit key used during encryption. +- View Decrypted Result: +The program will display the decrypted text in hexadecimal format first and then in plaintext. +## Notes +Always ensure that the key length is exactly 16 bytes. +The input for encryption can be in plain byte storage or Base64 encoded form, but decryption only accepts Base64 encoded input. + Below is a snippet from main.cpp demonstrating how the program interacts with the user to perform encryption: ```cpp= @@ -38,8 +68,9 @@ int main() { } } ``` -## Building and Running -Compile and run main.cpp together with other required modules using g++: + +## Example +![image](https://github.com/samsonjaw/AES/assets/114964564/adc83c16-9d78-46bd-a5f4-5e7e26090985) ## Contributions Contributions to enhance functionality or improve the codebase are welcome. Please feel free to fork the repository, make your changes, and submit a pull request for review.