MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / caesar

Function caesar

lib/cipher.cpp:9–21  ·  view source on GitHub ↗

── Caesar ────────────────────────────────────────────────────

Source from the content-addressed store, hash-verified

7
8// ── Caesar ────────────────────────────────────────────────────
9std::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 ──────────────────────────────────────────────────
24std::string vigenere(const std::string& text, const std::string& key, bool decrypt) {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected