|
C Fundamentals
Algorithms Β· data structures Β· cryptography Β· systems β pure C11, zero deps
|
<picture> <source media="(prefers-color-scheme: dark)" srcset="assets/hero-banner-dark.svg" > </picture>
π API docs (Doxygen)
A reference implementation of the algorithms, data structures, cryptographic primitives, and systems calls every C programmer eventually writes by hand. Seven sorts, binary search, four crypto primitives (Caesar with chi-squared cracker, Vigenère, XOR, SHA-256), seven data structures (linked list, stack, queue, BST, heap / priority queue, trie, hash table), POSIX systems demos. Zero dependencies, 1009 test assertions, GCC + Clang clean on Linux + macOS, AddressSanitizer + UndefinedBehaviorSanitizer in CI.
| Module | Highlights |
|---|---|
| Sorting | Selection Β· Bubble Β· Insertion Β· Quicksort (Lomuto) Β· Merge sort (top-down with reusable aux buffer) Β· Heap sort (in-place) Β· Radix sort (LSD, byte-by-byte counting) |
| Searching | Binary search β iterative + recursive, size_t-safe midpoint, both int and string variants |
| Encryption | Caesar cipher with chi-squared frequency-analysis cracker · Vigenère polyalphabetic cipher · XOR stream cipher · SHA-256 from scratch (FIPS 180-4, validated against NIST test vectors) |
| Data structures | Singly-linked list Β· Stack (growable array) Β· Queue (circular buffer with O(1) push/pop) Β· Binary search tree Β· Min-heap / priority queue (with linear heap_build) Β· Trie (26-way prefix tree) Β· Open-addressing hash table (djb2, linear probing, tombstones, auto-resize) |
| Systems | Cross-platform sysinfo (uname, sysctl, sysconf, getloadavg, statvfs) Β· signal-demo showing graceful SIGINT/SIGTERM handling via sigaction + volatile sig_atomic_t |
| Benchmarks | Empirical comparison of all seven sorts on n={100, 1k, 10k} random integers, deterministic seed |
Compiler swap: make clean && make all CC=clang. Custom flags: ‘make CFLAGS=’-O3 -march=native ...'(the defaults already include-Wall -Wextra -Werror -pedantic`).
Algorithms: selection Β· insertion Β· bubble Β· quick Β· merge Β· heap Β· radix (radix is integers-only, others have both *_ints and *_strings).
Run ./build/benchmark to regenerate; deterministic seed = 42.
Iterative + recursive variants, tested for equivalence on every value 1..21 against a known sorted array.
The Caesar cracker uses chi-squared distance against standard English letter frequencies (not the naive "most-common-letter == E" approach). The SHA-256 implementation is straight from FIPS 180-4 β validated against NIST test vectors including the empty string, "abc", and the 56-byte boundary-padding example.
Each structure is a self-contained library β no inter-module deps except where noted (heap sort delegates max-sift-down to data_structures/heap).
| Structure | API surface | Notes |
|---|---|---|
linked_list | push_front/back, pop_front, find, reverse, size | Singly-linked, owns nodes |
cf_stack | push, pop, peek, size, is_empty | Growable array, doubles on full (renamed from stack to dodge POSIX stack_t) |
queue | enqueue, dequeue, peek, size | Circular buffer, head + size for full/empty disambiguation |
bst | insert, contains, min, max, in_order traversal | Plain binary search tree (no balancing) |
heap | insert, extract_min, peek_min, build_min (O(n)) | Min-heap; also exposes max-sift-down for heap sort |
trie | insert, contains, starts_with | 26-way prefix tree, lowercase a-z |
hash_table | set, get, remove, contains, size | Open addressing, djb2, linear probing, tombstones, auto-resize at 0.75 load |
CLI demos for linked_list and hash_table. The rest are exercised by tests:
sysinfo branches on __APPLE__ for sysctlbyname (CPU brand, RAM); falls back to sysconf on Linux/BSD. signal-demo is a textbook example of the safe pattern: handler sets a volatile sig_atomic_t flag, main loop polls.
Hand-rolled assertion macros β tests/test.h defines ASSERT, ASSERT_EQ_INT, ASSERT_EQ_STR, ASSERT_EQ_SIZE, ASSERT_TRUE/FALSE, ASSERT_NULL/NOT_NULL. Failures print location + message but do not abort, so a single make test run reports every failure in every suite at once.
| Suite | What it covers |
|---|---|
test_sorts | 7 algorithms Γ 2 type variants + edge cases (empty / 1 / sorted / reversed) |
test_search | Iterative Β· recursive Β· empty Β· missing Β· strings Β· iter-vs-recursive equivalence |
test_caesar | Encrypt Β· decrypt Β· negative + large shifts Β· punctuation Β· round-trip Β· chi-squared crack |
test_vigenere | Textbook example Β· case preserved Β· round-trip Β· empty key Β· punctuation passthrough |
test_xor | Round-trip Β· zero-key identity Β· empty-key passthrough |
test_sha256 | NIST vectors: empty string, "abc", 56-byte boundary; hex format invariants |
test_linked_list | Create Β· push front/back Β· find Β· reverse Β· pop empty |
test_stack | LIFO order Β· peek Β· pop empty Β· resize stress to 100 elements |
test_queue | FIFO order Β· peek Β· circular wraparound + resize stress |
test_bst | Insert Β· contains Β· duplicate handling Β· min/max Β· in-order yields sorted |
test_heap | Min-priority extraction Β· peek Β· empty cases Β· O(n) build_min |
test_trie | Insert Β· contains Β· starts_with Β· rejects non-{a-z} input |
test_hash_table | Create Β· set/get Β· overwrite Β· remove Β· resize-rehash Β· slot reuse after remove |
| Job | Matrix |
|---|---|
| build | {ubuntu-latest, macos-latest} Γ {gcc, clang} β build, run tests, run smoke |
| sanitizers | ubuntu-latest Γ clang β full test suite under -fsanitize=address then -fsanitize=undefined; halts on the first UB it finds |
Every push to main and every PR triggers all five jobs. Concurrency group cancels superseded runs.
Pull requests welcome. The code style is K&R-ish, two-space indent, snake_case, doc comments on every public function. Please:
-Wall -Wextra -Werror -pedantic clean on both GCC and Clang.make asan && make ubsan before opening a PR.[MIT](LICENSE) β use it, fork it, ship something with it.
/// OPEN FOR NEW WORK /// CONTRACT & FREELANCE /// REMOTE WORLDWIDE ///