# Simple Encryption in C++

A simple encryption library and demonstration program implemented in C++ that provides two basic encryption methods:

1. **Caesar Cipher** - Shifts letters by a specified number of positions in the alphabet
2. **XOR Encryption** - Uses XOR operation with a key for encryption/decryption

## Features

- **Caesar Cipher Encryption/Decryption** with customizable shift values
- **XOR Encryption/Decryption** with string keys
- **Random Key Generation** for XOR encryption
- **Interactive Mode** for user input
- **Demonstration Mode** showing all features
- **Clean C++ Implementation** following established coding standards

## Files

- `SimpleEncryption.h` - Header file with class declaration
- `SimpleEncryption.cc` - Implementation of the encryption class
- `EncryptionDemo.cc` - Demonstration program with examples
- `Makefile` - Build configuration
- `README.md` - This documentation file

## Building the Program

### Prerequisites
- C++ compiler (g++ recommended)
- Make utility

### Compilation
```bash
# Build the program
make

# Or build with debug symbols
make debug

# Clean build artifacts
make clean
```

### Running the Program
```bash
# Run directly
./encryption_demo

# Or use make
make run
```

## Usage Examples

### Caesar Cipher
```cpp
SimpleEncryption encryptor(5); // Default shift of 5

std::string message = "Hello World!";
std::string encrypted = encryptor.EncryptCaesar(message);
std::string decrypted = encryptor.DecryptCaesar(encrypted);
```

### XOR Encryption
```cpp
SimpleEncryption encryptor;

std::string message = "Secret Message";
std::string key = "MyKey123";
std::string encrypted = encryptor.EncryptXor(message, key);
std::string decrypted = encryptor.DecryptXor(encrypted, key);
```

### Random Key Generation
```cpp
SimpleEncryption encryptor;
std::string random_key = encryptor.GenerateRandomKey(16); // 16-character key
```

## Class Methods

### Constructors
- `SimpleEncryption()` - Default constructor (Caesar shift = 3)
- `SimpleEncryption(int key)` - Constructor with custom default key

### Caesar Cipher Methods
- `EncryptCaesar(plaintext, shift)` - Encrypt using Caesar cipher
- `DecryptCaesar(ciphertext, shift)` - Decrypt Caesar cipher

### XOR Encryption Methods
- `EncryptXor(plaintext, key)` - Encrypt using XOR
- `DecryptXor(ciphertext, key)` - Decrypt XOR (same as encrypt)

### Utility Methods
- `SetDefaultKey(key)` - Set default Caesar shift
- `GetDefaultKey()` - Get current default key
- `IsValidText(text)` - Check if text is valid
- `GenerateRandomKey(length)` - Generate random key

## Security Note

⚠️ **Important**: This is a simple educational implementation. The encryption methods provided (Caesar cipher and basic XOR) are **NOT secure** for real-world applications. They are easily breakable and should only be used for:

- Learning purposes
- Simple obfuscation
- Educational demonstrations
- Basic data transformation

For production applications requiring real security, use established cryptographic libraries like:
- OpenSSL
- Crypto++
- libsodium
- Botan

## Program Flow

1. **Demonstration Mode**: Shows examples of both encryption methods
2. **Interactive Mode**: Allows user to input text and choose encryption method
3. **Key Generation**: Demonstrates random key creation

## Code Style

This implementation follows established C++ coding standards:
- Clear naming conventions with prefixes (m for members, etc.)
- Proper class organization (public, protected, private)
- Comprehensive error handling
- Memory-safe string operations
- Const-correctness where applicable

## License

Licensed under the Apache License, Version 2.0. See the license headers in source files for details.