── Caesar ────────────────────────────────────────────────────
| 7 | |
| 8 | // ── Caesar ──────────────────────────────────────────────────── |
| 9 | std::string caesar(const std::string& text, int shift, bool decrypt) { |
| 10 | if (decrypt) shift = (26 - (shift % 26)) % 26; |
| 11 | std::string result; |
| 12 | for (char c : text) { |
| 13 | if (std::isalpha(c)) { |
| 14 | char base = std::isupper(c) ? 'A' : 'a'; |
| 15 | result += (char)((c - base + shift) % 26 + base); |
| 16 | } else { |
| 17 | result += c; |
| 18 | } |
| 19 | } |
| 20 | return result; |
| 21 | } |
| 22 | |
| 23 | // ── Vigenere ────────────────────────────────────────────────── |
| 24 | std::string vigenere(const std::string& text, const std::string& key, bool decrypt) { |