diff --git a/README.md b/README.md index 8acd9b0..2cdcc8a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This repository is intended as: * A interview‑prep playground * A reference for **concurrency, synchronization, low‑level and modern C++ techniques** * A growing set of **self‑contained, buildable examples** -* A collection of more useful examples than leetcode puzzles. +* A collection of more useful examples (and CLI tools) than leetcode puzzles. Examples include (and will expand to): @@ -28,6 +28,8 @@ Examples include (and will expand to): * Performance‑oriented C++ idioms * Algorithms * [integer-factorization](./integer-factorization/) + * Encoding + * [rot47](./rot47/) * OOP * [virtual-interface](./virtual-interface/) diff --git a/rot47/Makefile b/rot47/Makefile new file mode 100644 index 0000000..172da2f --- /dev/null +++ b/rot47/Makefile @@ -0,0 +1,30 @@ +# pull in shared compiler settings +include ../common.mk + +# per-example flags +# CXXFLAGS += -pthread + +## get it from the folder name +TARGET := $(notdir $(CURDIR)) +SRCS := $(wildcard *.cpp) +OBJS := $(SRCS:.cpp=.o) + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) -o $@ $^ + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +run: $(TARGET) + ./$(TARGET) $(ARGS) + +clean: + rm -f $(OBJS) $(TARGET) + +# Delegates to top-level Makefile +check-format: + $(MAKE) -f ../Makefile check-format DIR=$(CURDIR) + +.PHONY: all clean run check-format diff --git a/rot47/main.cpp b/rot47/main.cpp new file mode 100644 index 0000000..12973bc --- /dev/null +++ b/rot47/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +[[nodiscard]] +std::string +rot47(std::string_view input) +{ + auto transform = [](char c) { return (c >= 33 && c <= 126) ? static_cast(33 + ((c - 33 + 47) % 94)) : c; }; + + std::string output; + output.reserve(input.size()); + + for (char c : input | std::views::transform(transform)) { + output.push_back(c); + } + + return output; +} + +int +main(int argc, char* argv[]) +{ + for (int i = 1; i < argc; ++i) { + std::cout << rot47(argv[i]); + + if (i + 1 < argc) { + std::cout << ' '; + } + } +} diff --git a/rot47/tests.sh b/rot47/tests.sh new file mode 100755 index 0000000..337fb84 --- /dev/null +++ b/rot47/tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -ex + +./rot47 + +helloworld=$(./rot47 'w6==@ (@C=5P') + +if [ "$helloworld" != "Hello World!" ]; then + echo "Test failed: expected 'Hello World!' but got '$helloworld'" + exit 1 +fi diff --git a/virtual-interface/virtual-interface b/virtual-interface/virtual-interface deleted file mode 100755 index 67098f0..0000000 Binary files a/virtual-interface/virtual-interface and /dev/null differ