> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/cis/cryptography-basics.md).

# Cryptography — Basics

### 1. What is Cryptography?

Cryptography is the study of techniques used to secure communication and information from unauthorized access. It converts readable data (**plaintext**) into an unreadable form (**ciphertext**) using a set of rules called an **algorithm** (or **cipher**), usually controlled by a secret value called a **key**.

The reverse process — converting ciphertext back to plaintext — is called **decryption**.

```
Plaintext  --[Encryption + Key]-->  Ciphertext
Ciphertext --[Decryption + Key]-->  Plaintext
```

### 2. Goals of Cryptography (CIA + 2)

| Goal                | Meaning                                    |
| ------------------- | ------------------------------------------ |
| **Confidentiality** | Only authorized parties can read the data  |
| **Integrity**       | Data has not been altered in transit       |
| **Authentication**  | Confirms the identity of the sender        |
| **Non-repudiation** | Sender cannot deny having sent the message |
| **Availability**    | Data/systems remain accessible when needed |

### 3. Types of Cryptography

#### 3.1 Symmetric Key Cryptography

* Same key is used for both encryption and decryption.
* Fast, but key distribution is a challenge (both parties must securely share the same secret key).
* Examples: Caesar Cipher, DES, AES, Rail Fence Cipher.

```
Key (K) is same on both sides
Plaintext --Encrypt(K)--> Ciphertext --Decrypt(K)--> Plaintext
```

#### 3.2 Asymmetric Key Cryptography (Public Key Cryptography)

* Uses a **pair of keys**: a **public key** (shared with everyone) and a **private key** (kept secret).
* What is encrypted with the public key can only be decrypted with the corresponding private key, and vice versa.
* Slower than symmetric cryptography but solves the key-distribution problem.
* Examples: RSA, ECC, Diffie-Hellman.

### 4. Classical Cipher Techniques

Classical ciphers (used historically, mainly for learning purposes today) fall into two broad categories:

#### 4.1 Substitution Cipher

* Each character in the plaintext is **replaced** by another character according to a fixed rule.
* The *positions* of characters stay the same, but the *identity* of each character changes.
* Example: **Caesar Cipher**.

#### 4.2 Transposition Cipher

* The characters of the plaintext are **rearranged** (their positions are shuffled) according to a fixed system.
* The *identity* of each character stays the same, but the *position* changes.
* Example: **Rail Fence Cipher**.

### 5. Modern Cryptographic Concepts

#### 5.1 Hashing

A **hash function** takes an input of any size and produces a fixed-size output (the **hash** or **digest**). It is a one-way function: you cannot practically reverse a hash back to the original input.

* Used to check data integrity.
* Examples: SHA-1, SHA-256, MD5 (MD5 and SHA-1 are now considered weak/broken for security-critical use).

#### 5.2 Digital Signatures

A digital signature proves that a message was created by a specific sender (**authentication**) and was not altered (**integrity**), and the sender cannot later deny sending it (**non-repudiation**).

General process:

1. Sender hashes the message.
2. Sender encrypts (signs) the hash using their **private key** → this is the "signature."
3. Receiver hashes the received message independently, then decrypts the signature using the sender's **public key** to recover the original hash.
4. If both hashes match, the signature is valid.

Digital signatures use asymmetric cryptography, but note: they provide authentication and integrity, **not confidentiality** (the message itself isn't hidden unless separately encrypted).

### 6. Key Terms Glossary

| Term               | Definition                                                                                               |
| ------------------ | -------------------------------------------------------------------------------------------------------- |
| Plaintext          | Original, readable message                                                                               |
| Ciphertext         | Encrypted, unreadable message                                                                            |
| Key                | Secret value controlling encryption/decryption                                                           |
| Cipher             | Algorithm used to perform encryption/decryption                                                          |
| Cryptanalysis      | The study of breaking ciphers without the key                                                            |
| Brute Force Attack | Trying every possible key until the correct one is found                                                 |
| Modulo (mod)       | Remainder after division; used heavily in cipher math (e.g. wrapping the alphabet A-Z back to A after Z) |

### 7. Practicals in This Set

1. **Practical 1** — Caesar Cipher (Substitution Technique)
2. **Practical 2** — Rail Fence Cipher (Transposition Technique)
3. **Practical 3** — RSA Digital Signature (Asymmetric Cryptography)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/cis/cryptography-basics.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
