Block Diagram of Cryptography Algorithms

_cryptoalgomathclasstutor_

Block Diagram of Cryptography Algorithms — With the Mathematics Behind Them

A complete, illustrated walkthrough of how cryptography protects information — covering symmetric ciphers, asymmetric (public-key) ciphers, hash functions, and key exchange, with the core equations explained.

1. What Cryptography Actually Does

Cryptography is the science of transforming readable information (plaintext) into an unreadable form (ciphertext) so that only an authorized party holding the correct key can reverse the process and recover the original data. Every cryptographic system — no matter how advanced — is built from the same basic pipeline. Understanding that pipeline as a block diagram makes the rest of cryptography (AES, RSA, SHA, Diffie–Hellman, etc.) far easier to reason about.

2. General Block Diagram of a Cryptographic System

The diagram below shows the universal structure common to every encryption scheme: a sender, an encryption block, an insecure channel, an eavesdropper (Eve), a decryption block, and a receiver.

Plaintext P Encryption Algorithm E C = E(K1, P) Key K1 Ciphertext C (insecure channel) Eve (attacker) Decryption Algorithm D P = D(K2, C) Key K2 Plaintext P (recovered) Key Generation / Key Management

Note: If K1 = K2 (the same secret key is used to encrypt and decrypt), the system is symmetric-key cryptography. If K1 and K2 are mathematically related but different (a public key and a private key), the system is asymmetric-key (public-key) cryptography.

3. Symmetric-Key Cryptography (Same Key Both Sides)

In symmetric cryptography, both sender and receiver share one secret key K. Encryption and decryption are mathematical inverses of each other:

C = E(K, P)     and     P = D(K, C) = D(K, E(K, P))

Simplest example — XOR stream cipher: if P is the plaintext bit-string and K is a key stream of the same length,

C = P ⊕ K     (bitwise XOR)
P = C ⊕ K     (since (P ⊕ K) ⊕ K = P)

Modern block ciphers such as AES (Advanced Encryption Standard) extend this idea across fixed-size blocks (128 bits) using several rounds, each combining:

  • SubBytes — a non-linear substitution using a lookup table (S-box), based on inversion in the finite field GF(28)
  • ShiftRows — cyclic permutation of bytes within each row
  • MixColumns — matrix multiplication over GF(28): state' = M · state
  • AddRoundKey — XOR with a round-specific subkey derived from K via a key schedule

AES-128 repeats this sequence for 10 rounds, AES-192 for 12, and AES-256 for 14.

4. Asymmetric-Key Cryptography (RSA Example)

Public-key cryptography uses two mathematically linked keys: a public key (shared openly) and a private key (kept secret). RSA is the classic example, built on the difficulty of factoring large numbers.

Key Generation

  1. Choose two large prime numbers, p and q.
  2. Compute the modulus: n = p × q
  3. Compute Euler's totient: φ(n) = (p-1)(q-1)
  4. Choose a public exponent e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1
  5. Compute the private exponent d, the modular inverse of e: d ≡ e-1 (mod φ(n))

Public key: (e, n)  |  Private key: (d, n)

Encryption & Decryption

Encryption:   C = Pe mod n
Decryption:   P = Cd mod n

This works because of Euler's theorem: since e · d ≡ 1 (mod φ(n)), raising to e and then to d returns the original value modulo n. Security relies on the fact that, given only n and e, factoring n back into p and q (and thus deriving d) is computationally infeasible for sufficiently large primes (2048+ bits in practice).

Tiny Worked Example (small numbers, for illustration only — never use in real systems)

p = 61, q = 53 → n = 3233, φ(n) = 3120
e = 17 (public) → d = 2753 (private, since 17 × 2753 mod 3120 = 1)
Encrypt P = 65:   C = 6517 mod 3233 = 2790
Decrypt C = 2790:   P = 27902753 mod 3233 = 65

5. Hash Functions — Ensuring Integrity

A cryptographic hash function H maps an input of any length to a fixed-length output (a "digest"), and is designed to be a one-way function:

h = H(M)     where |h| is fixed (e.g., 256 bits for SHA-256)

Three required properties, stated formally:

  • Pre-image resistance: given h, it is computationally hard to find any M such that H(M) = h
  • Second pre-image resistance: given M1, it is hard to find M2 ≠ M1 such that H(M1) = H(M2)
  • Collision resistance: it is hard to find any pair M1 ≠ M2 such that H(M1) = H(M2)

SHA-256 achieves this through repeated rounds of bitwise rotation, XOR, and modular addition (mod 232) applied to 512-bit message blocks, compressing the running hash state after each block (Merkle–Damgård construction).

6. Diffie–Hellman Key Exchange — Sharing a Secret Over an Open Channel

Alice and Bob want a shared secret key without ever transmitting it. They publicly agree on a large prime p and a generator g.

Alice picks secret a → sends   A = ga mod p
Bob picks secret b → sends   B = gb mod p
Alice computes:   K = Ba mod p
Bob computes:   K = Ab mod p
Both arrive at the same K = gab mod p

An eavesdropper who sees p, g, A, and B still cannot efficiently compute K without solving the discrete logarithm problem (recovering a from A, or b from B) — believed to be computationally hard for large primes.

7. What This Whole Pipeline Achieves

Security Goal Achieved By
ConfidentialitySymmetric ciphers (AES) or asymmetric ciphers (RSA)
IntegrityHash functions (SHA-256), MACs
AuthenticationDigital signatures (RSA/ECDSA sign with private key, verify with public key)
Key EstablishmentDiffie–Hellman / ECDH over an insecure channel

8. Conclusion

Every cryptographic system, however sophisticated, reduces to the same block diagram: plaintext enters an encryption block governed by a key, becomes ciphertext, crosses a potentially hostile channel, and is restored by a matching decryption block. The mathematics — modular exponentiation for RSA, finite-field operations for AES, one-way compression for SHA, and discrete logarithms for Diffie–Hellman — is what makes reversing that process infeasible for anyone without the correct key, while remaining fast and simple for anyone who has it.

Diagrams and formulas above are original illustrations created for this article and are safe to publish.

Post a Comment

0 Comments