# Caesar Cipher Implementation in C++

A comprehensive implementation of the Caesar cipher encryption algorithm in C++, following modern C++ best practices and coding standards.

## Features

- **Encryption and Decryption**: Full support for both operations
- **Case Preservation**: Maintains original case of letters
- **Non-alphabetic Character Handling**: Preserves spaces, punctuation, and numbers
- **Flexible Shift Values**: Supports any integer shift value (automatically normalized)
- **Brute Force Attack**: Utility to try all possible decryptions
- **Interactive Mode**: Command-line interface for user input
- **Demonstration Mode**: Built-in examples and testing

## Files

- `CaesarCipher.h` - Header file with class declaration
- `CaesarCipher.cc` - Implementation file with all methods
- `Makefile` - Build configuration for easy compilation
- `README_CaesarCipher.md` - This documentation file

## Compilation

### Using Make (Recommended)
```bash
# Build the program
make

# Build with debug symbols
make debug

# Clean build artifacts
make clean

# Build and run
make run

# Run with test input
make test
```

### Manual Compilation
```bash
g++ -std=c++11 -Wall -Wextra -O2 -o caesar_cipher CaesarCipher.cc
```

## Usage

### Interactive Mode
```bash
./caesar_cipher
```
Enter a message when prompted, and the program will encrypt it with a shift of 3, then decrypt it back.

### Demonstration Mode
If you run the program without entering any text, it will automatically run a demonstration showing various features.

## Code Structure

### Class Design
The `CaesarCipher` class follows C++ best practices:

- **Constructor**: Takes an optional shift value (default: 0)
- **Destructor**: Properly cleans up resources
- **Public Methods**: Core encryption/decryption functionality
- **Private Members**: Encapsulated shift value with proper naming (`mShift`)

### Key Methods

#### Core Operations
- `Encrypt(const std::string& plaintext)` - Encrypts a string
- `Decrypt(const std::string& ciphertext)` - Decrypts a string
- `EncryptChar(char character)` - Encrypts a single character
- `DecryptChar(char character)` - Decrypts a single character

#### Utility Methods
- `GetShift()` - Returns current shift value
- `SetShift(int shift)` - Sets new shift value
- `BruteForceDecrypt(const std::string& ciphertext)` - Returns all possible decryptions
- `IsValidChar(char character)` - Checks if character is alphabetic
- `Demonstrate()` - Runs built-in demonstration

## Algorithm Details

### Caesar Cipher Formula
- **Encryption**: `(character - base + shift) % 26 + base`
- **Decryption**: `(character - base - shift + 26) % 26 + base`

Where `base` is 'A' for uppercase letters and 'a' for lowercase letters.

### Shift Normalization
The implementation automatically normalizes shift values to the range 0-25:
```cpp
mShift = ((shift % ALPHABET_SIZE) + ALPHABET_SIZE) % ALPHABET_SIZE;
```

This ensures that negative shifts and shifts greater than 25 work correctly.

## Examples

### Basic Usage
```cpp
CaesarCipher cipher(3);
std::string encrypted = cipher.Encrypt("Hello, World!");
std::string decrypted = cipher.Decrypt(encrypted);
```

### Brute Force Attack
```cpp
std::vector<std::string> possibilities = CaesarCipher::BruteForceDecrypt("Khoor, Zruog!");
// Returns all 26 possible decryptions
```

## Security Note

The Caesar cipher is a **very weak** encryption method and should **never** be used for actual security purposes. It's easily broken by:
- Frequency analysis
- Brute force (only 25 possible keys)
- Pattern recognition

This implementation is for educational purposes and demonstrates basic cryptographic concepts.

## Coding Standards

This implementation follows the established C++ coding standards:
- **Naming Conventions**: PascalCase for methods, mPrefix for member variables
- **File Organization**: Separate header and implementation files
- **Memory Management**: Efficient string operations with reserve()
- **Error Handling**: Proper input validation and exception safety
- **Documentation**: Comprehensive comments and documentation

## License

Licensed under the Apache License, Version 2.0. See the license header in each file for details.