| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
The Data Encryption Standard (DES) is a symmetric-key block cipher that operates on 64-bit blocks of data using a 56-bit key (plus 8 parity bits). Developed by IBM in the 1970s and adopted as a U.S. federal standard in 1977, DES was the foundation of digital cryptography for decades. Although DES is now considered obsolete for secure communications, it remains a cornerstone for understanding block cipher design and symmetric encryption.
DES uses a Feistel network with 16 rounds.
Each round splits the block into left (L) and right (R) 32-bit halves:
L0 = IP_block[0..31] R0 = IP_block[32..63]
For each round i (1 ≤ i ≤ 16):
Li = Ri-1 Ri = Li-1 XOR F(Ri-1, Ki)
Where:
The F-function is central to DES security, introducing both confusion and diffusion:
Expansion (E-Box):
The 32-bit right half is expanded to 48 bits by duplicating and permuting certain bits, according to the E-table:
expanded_block[0..47] = ExpansionPermutation(Ri-1)
This ensures each S-box input depends on multiple plaintext bits.
XOR with Subkey:
The expanded block is XORed with the 48-bit round subkey:
xored_block = expanded_block XOR Ki
Substitution (S-Boxes):
The 48-bit block is divided into eight 6-bit chunks.
Each chunk is mapped through a specific S-box, producing a 4-bit output.
This yields a 32-bit output, dramatically increasing non-linearity.
for i in 0..7:
sbox_output[i] = Sbox[i](xored_block[i*6 : (i+1)*6])
combined_sbox = concat(sbox_output[0..7]) // 32 bits
Permutation (P-Box):
The combined S-box output is permuted to further diffuse the bits:
permuted = PPermutation(combined_sbox)
3DES (“Triple DES”) enhances DES security by applying the DES cipher three times in sequence with three different keys:
Ciphertext = DES_encrypt(K3, DES_decrypt(K2, DES_encrypt(K1, Plaintext)))
Let’s walk through the operations for a single round:
Input Block:
plaintext_block[64] = [b0, b1, ..., b63]
Initial Permutation:
IP_block[64] = InitialPermutation(plaintext_block)
Split into Halves:
L0[32] = IP_block[0..31] R0[32] = IP_block[32..63]
Round 1:
L1 = R0 R1 = L0 XOR F(R0, K1)
F-function Steps:
expanded_R0[48] = ExpansionPermutation(R0) xored = expanded_R0 XOR K1 sbox_out[32] = SBoxSubstitution(xored) permuted = PPermutation(sbox_out)
Combine and Swap:
After 16 rounds, final output is (R16, L16), which is then permuted using IP-1.
This library supports all major block cipher modes, for both DES and TripleDES:
Each mode provides different security properties and is suitable for various applications. All are implemented in des.hpp with a unified API.
For cryptographic safety and demonstration flexibility, this library includes secure key and IV generators:
This project delivers a modern, header-only C++11 implementation of DES and 3DES algorithms, including all common block cipher modes and secure random key/IV generation.
It’s ideal for cryptography education, experimentation, and understanding the inner workings of classic symmetric ciphers.
All modes are available for both DES and TripleDES with identical API.
#include "des.hpp"std::string message("something to encrypt with DES");
std::string key("12345678");
// additionally, define 2 more keys for 3DES...
std::string key2("12345678"); // note that these should be different and secure keys...
std::string key3("12345678");
// now define the IV for modes using an IV...
std::vector<bool> iv(64, 1); // example iv with all bits set, im using bool type because it's ok to represent bits...auto cbc_enc = DES::CBC::Encrypt(message, key, iv);
auto cbc_dec = DES::CBC::Decrypt(cbc_enc.toString(), key, iv);auto tdes_enc = DES::CBC::Encrypt3DES(message, key, key2, key3);
auto tdes_dec = DES::CBC::Decrypt3DES(tdes_enc.toString(), key, key2, key3);This project is licensed under the MIT License.
| Back | FazBrowse Home | New Git URL |