A C++20 implementation of the Data Encryption Standard (DES) algorithm. Built as an educational tool to study and visualize the internal structure of DES, including all 16 Feistel rounds, key scheduling, S-box substitutions, and permutations.
Based on Cryptography and Network Security by Behrouz A. Forouzan.
Note: DES is considered cryptographically broken and should not be used for securing real data. This project is for educational purposes only.
Requires a C++20-compatible compiler (GCC 10+, Clang 12+, MSVC 2019+).
With CMake:
cmake -B build
cmake --build buildWith g++/clang++ directly:
c++ -std=c++20 -O2 -o des main.cpp des.cppUsage: des <-e|-d> -k <key> -t <text> [-v]
Options:
-e Encrypt mode
-d Decrypt mode
-k <key> 16-character hex key (64 bits)
-t <text> 16-character hex input (64 bits)
-v Verbose: show all 16 rounds
-h Show this help
./des -e -k AABB09182736CCDD -t 123456ABCD132536Plaintext : 123456ABCD132536
Key : AABB09182736CCDD
Ciphertext: C0B7A8D05F3A829C
./des -d -k AABB09182736CCDD -t C0B7A8D05F3A829CCiphertext: C0B7A8D05F3A829C
Key : AABB09182736CCDD
Plaintext : 123456ABCD132536
Use -v to display all 16 Feistel rounds with left/right halves and round keys:
./des -e -k AABB09182736CCDD -t 123456ABCD132536 -v Round Left Right Round Key
1 18CA18AD 5A78E394 194CD072DE8C
2 5A78E394 4A1210F6 4568581ABCCE
3 4A1210F6 B8089591 06EDA4ACF5B5
4 B8089591 236779C2 DA2D032B6EE3
5 236779C2 A15A4B87 69A629FEC913
6 A15A4B87 2E8F9C65 C1948E87475E
7 2E8F9C65 A9FC20A3 708AD2DDB3C0
8 A9FC20A3 308BEE97 34F822F0C66D
9 308BEE97 10AF9D37 84BB4473DCCC
10 10AF9D37 6CA6CB20 02765708B5BF
11 6CA6CB20 FF3C485F 6D5560AF7CA5
12 FF3C485F 22A5963B C2C1E96A4BF3
13 22A5963B 387CCDAA 99C31397C91F
14 387CCDAA BD2DD2AB 251B8BC717D0
15 BD2DD2AB CF26B472 3330C5D9A36D
16 CF26B472 19BA9212 181C5D75C66D
Plaintext : 123456ABCD132536
Key : AABB09182736CCDD
Ciphertext: C0B7A8D05F3A829C
des.h DES class declaration, lookup tables, and constants
des.cpp DES algorithm implementation
main.cpp CLI entry point with argument parsing
CMakeLists.txt CMake build configuration
DES operates on 64-bit blocks using a 56-bit key (64 bits with 8 parity bits):
- Initial Permutation — rearranges the 64 input bits
- 16 Feistel Rounds — each round applies:
- Expansion permutation (32 -> 48 bits)
- XOR with round key
- S-box substitution (48 -> 32 bits)
- Straight permutation
- Final Permutation — inverse of the initial permutation
Decryption uses the same algorithm with round keys applied in reverse order.
MIT