Skip to main content
Cryptography Basics
CHAPTER 02

Basic Encryption Concepts

Updated: May 15, 2026
20 min read

# CHAPTER 2

Basic Encryption Concepts

1. Introduction

To understand how modern security protocols work, we must first master the vocabulary of cryptography. Words like "encoding" and "encryption" are often incorrectly used interchangeably by beginners, leading to severe security flaws in software development. In this chapter, we will define the lifecycle of data as it transforms from readable text into a secure state, explore the critical function of cryptographic keys, and establish the distinct differences between Encoding, Encryption, and Hashing.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define Plaintext and Ciphertext.
  • Understand the role of an Encryption Algorithm (Cipher) versus a Key.
  • Clearly differentiate between Encoding and Encryption.
  • Introduce the high-level concepts of Symmetric vs. Asymmetric encryption.
  • Understand Kerckhoffs's Principle.

3. Beginner-Friendly Explanation

Imagine a locked diary.
  • Plaintext: The readable English words you write in the diary ("Dear Diary, my secret is...").
  • Cipher: The lock mechanism itself. (The design of the padlock).
  • Key: The physical metal key you put into the lock.
  • Ciphertext: The locked diary. If someone steals it, they can't read the words inside.

You can buy 1,000 diaries with the exact same lock design (the Cipher). The security doesn't rely on the lock design being a secret; it relies entirely on the fact that you possess the unique Key.

4. Plaintext, Ciphertext, and Keys

  • Plaintext (Cleartext): Information that is readable by humans or machines without any special processing. (e.g., A password, a photograph, an email).
  • Algorithm (Cipher): The mathematical formula used to scramble the data. (e.g., AES, RSA).
  • Key: A specific, secret sequence of numbers or characters. The Algorithm uses the Key as the variable to scramble the data.
  • Ciphertext: The resulting scrambled, unreadable data.

*Formula:* Plaintext + Key + Algorithm = Ciphertext

5. Encoding vs. Encryption

This is the most common beginner mistake in cybersecurity.
  • Encoding: Translating data into a different format for *usability*, not security. Examples include Base64 or URL-encoding. There is no "Key." Anyone who knows the format can instantly decode it.
*(Example: Translating "Hello" into Morse Code. It's not a secret; anyone who knows Morse Code can read it).*
  • Encryption: Translating data into a different format for *confidentiality*. It requires a secret Key. Even if the attacker knows the algorithm, they cannot reverse it without the Key.

6. Kerckhoffs's Principle

Auguste Kerckhoffs, a 19th-century cryptographer, stated a principle that governs all modern security: *"A cryptographic system should be secure even if everything about the system, except the key, is public knowledge."*
  • Bad Security (Security through Obscurity): A developer invents a secret mathematical formula to encrypt data, but hardcodes the key. If the formula leaks, the system is permanently broken.
  • Good Security: The AES encryption algorithm is public. Anyone can download the exact math behind it. Hackers have studied the math for 20 years. But because the *Key* is kept secret, the data remains 100% secure.

7. Mini Project: Encode and Decode Messages

Let's demonstrate why Encoding is NOT Encryption using the Linux command line.

Step-by-Step Walkthrough (Base64 Encoding):

  1. 1. Encode a message: We will encode the word "SecretData" using Base64.
``bash echo -n "SecretData" | base64 ` *Output:* U2VjcmV0RGF0YQ==
  1. 2. The Illusion of Security: To an untrained eye, U2VjcmV0RGF0YQ== looks like a strong, encrypted password.
  1. 3. The Reality: There is no key. A hacker sees the == at the end, recognizes it as Base64 encoding, and easily decodes it:
`bash echo -n "U2VjcmV0RGF0YQ==" | base64 --decode ` *Output:* SecretData *Lesson:* Never use Base64 to "protect" sensitive information!

8. Real-World Scenarios

A junior web developer is tasked with securely storing user API tokens in a local browser cookie. Believing they are securing the data, the developer uses Base64 to "encrypt" the token before saving it. A malicious actor performs a Cross-Site Scripting (XSS) attack, steals the cookie, recognizes the Base64 format, decodes it instantly without needing a key, and uses the API token to steal the user's data. The developer conflated Encoding (data formatting) with Encryption (data confidentiality).

9. Best Practices

  • Key Management is Everything: If you use the strongest, military-grade AES-256 encryption algorithm, but you save the decryption key in a text file named keys.txt` on your desktop, your security is zero. The hardest part of modern cryptography is not the math; it is safely storing, transmitting, and rotating the Keys.
When conducting security audits or penetration tests, discovering data that is merely encoded (like Base64) instead of encrypted is a critical vulnerability finding. As a professional, you must clearly articulate to management why encoding provides zero cryptographic protection.

11. Exercises

  1. 1. Write the formula that transforms Plaintext into Ciphertext. What are the two necessary inputs?
  1. 2. Explain why Morse Code is a form of Encoding, not Encryption.

12. FAQs

Q: How long should an encryption key be? A: It depends on the algorithm. For modern Symmetric encryption (AES), a 256-bit key is the gold standard. A 256-bit key has $2^{256}$ possible combinations. That number is larger than the estimated number of atoms in the observable universe. It is physically impossible to brute-force.

13. Interview Questions

  • Q: Explain Kerckhoffs's Principle. Why is "Security through Obscurity" considered an anti-pattern in modern cryptographic design?
  • Q: You are reviewing code and see a developer utilizing Base64 to store session identifiers in a database. What is the security implication, and how would you explain the difference between encoding and encryption to the developer?

14. Summary

In Chapter 2, we established the fundamental vocabulary of cryptography. We defined the transformation of Plaintext into Ciphertext via the interaction of an Algorithm and a secret Key. We emphatically debunked the misconception that Encoding (like Base64) provides security. Finally, we embraced Kerckhoffs's Principle, accepting that robust security relies entirely on protecting the Key, not on hiding the mathematics.

15. Next Chapter Recommendation

Before we dive into modern computer algorithms, we must understand the logical foundations of how ciphers manipulate data. Proceed to Chapter 3: Classical Cryptography Techniques.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·