/StringsAndCiphers

C11 codebase implementing string manipulation, struct handling, and classic ciphers, with Criterion tests and Makefile automation, designed for Linux environments and bash driven build workflows.

Primary LanguageC

Strings and Ciphers

This project explores four main areas: strings, system calls, caesar cipher, and substitution cipher. It provides both a C library and unit tests, making it a practical codebase designed for Linux environments. For more background on Linux environments and code I/O, see: Linux Operating Systems - rsiddiq.com.

Features

  • String helpers (get_str_length, copy_str, case conversion, find-first/last index)
  • Person and Group structs with basic operations
  • Caesar cipher (encrypt/decrypt)
  • General substitution cipher (encrypt/decrypt, key validation + inversion)
  • Unit tests with Criterion

Project Layout

StringsAndCiphers/
├─ .gitignore
├─ Makefile
├─ README.md
├─ unit_tests.c
├─ build/
│  └─ tests_runner
├─ src/
│  ├─ StringsAndCiphers.c
│  ├─ StringsAndCiphers.h
│  ├─ StringsAndCiphers.o
│  └─ log.h
├─ tests/
│  ├─ unittests_caesar.c
│  ├─ unittests_string.c
│  ├─ unittests_struct.c
│  └─ unittests_substitution.c
└─ .vscode/
   ├─ launch.json
   └─ tasks.json

Build Instructions

This project is intended for Linux systems and requires make, a C11 compiler, and Criterion.

Ubuntu/Debian

sudo apt-get install build-essential pkg-config make
# Criterion (Ubuntu 22.04+ has libcriterion-dev, else build from source)
sudo apt-get install libcriterion-dev

Alternative Environments

  • Windows: Use WSL (Windows Subsystem for Linux) to run a Linux environment with make and a C compiler.

  • macOS: Install Xcode command line tools (xcode-select --install) and Criterion via Homebrew (brew install criterion).

  • Docker: Build and test inside a Linux-based container for a consistent environment:

    docker run --rm -it -v $(pwd):/app -w /app gcc:latest bash
    apt-get update && apt-get install -y build-essential pkg-config libcriterion-dev
    make && ./build/tests_runner

Build and Run Tests

make
./build/tests_runner

Clean Build Artifacts

make clean

Usage as a Library

StringsAndCiphers.c/.h can be dropped into another project, or you can build a static/shared library if desired. Key entry points include:

  • get_str_length, copy_str, to_uppercase, to_lowercase
  • person_make_new, person_to_string, group_make_new, add_person, remove_person
  • encrypt_caesar, decrypt_caesar
  • is_reversible, get_decryption_key, encrypt_substitution, decrypt_substitution

Development Notes

  • Compiles with -Wall -Wextra -Wpedantic -std=c11. Treat warnings as errors locally with:

    CFLAGS="-Wall -Wextra -Wpedantic -Werror -std=c11" make
  • Memory safety: APIs that return newly allocated strings specify that the caller owns the memory.

  • Tests: Criterion-based tests live under tests/ and run via the build/tests_runner target.

Editor and IDE Support

This repo includes .vscode/launch.json and .vscode/tasks.json to make building and running tests convenient for VS Code users. For JetBrains CLion users, the project also works smoothly: open the folder as a CMake project, set up Criterion as an external library (via pkg-config or manual linking), and configure the test target to run build/tests_runner.