# Symmetric Encryption
## What is Symmetric Encryption
Symmetric encryption is a type of encryption where the same key is used for both encrypting plaintext and decrypting ciphertext. Both the sender and receiver must possess the same secret key. Because the same key performs both operations, symmetric encryption is also called secret key encryption or shared key encryption. Symmetric encryption is computationally efficient and fast, making it suitable for encrypting large amounts of data. The main challenge is securely distributing the shared key to all parties who need it without it being intercepted.
## Block Ciphers
Block ciphers divide the data into fixed-size blocks and encrypt each block independently using the key. DES, the Data Encryption Standard, was the dominant symmetric cipher from the 1970s until the late 1990s. It uses 56-bit keys and 64-bit blocks. The short key length makes DES vulnerable to brute force attacks with modern computers and it should not be used. Triple DES applies DES three times to increase effective key length. AES, the Advanced Encryption Standard, replaced DES as the recommended standard in 2001. AES supports key lengths of 128, 192, and 256 bits and uses 128-bit blocks. AES is secure against all known practical attacks and is widely used in applications ranging from WiFi to disk encryption to TLS.
## Stream Ciphers
Stream ciphers encrypt data one bit or byte at a time rather than in blocks. A stream cipher generates a keystream, which is a sequence of pseudorandom bits, from the key. The keystream is XORed with the plaintext to produce the ciphertext. RC4 was a widely used stream cipher but has vulnerabilities and is now deprecated. ChaCha20 is a modern stream cipher used in TLS and other applications.
## Modes of Operation
Block ciphers can be used in different modes that affect how blocks are combined. Electronic Codebook mode encrypts each block independently, which means identical plaintext blocks produce identical ciphertext blocks, making patterns visible. Cipher Block Chaining mode XORs each plaintext block with the previous ciphertext block before encryption, so identical plaintext blocks produce different ciphertext. Counter mode converts a block cipher into a stream cipher. GCM, Galois Counter Mode, provides both encryption and authentication.
## Key Distribution Problem
The fundamental challenge of symmetric encryption is securely distributing the shared key to all parties who need it. If the key is transmitted over an insecure channel, it could be intercepted. This problem is solved in modern systems by using asymmetric encryption to exchange symmetric keys securely, as done in TLS handshakes.Back to Subject