Rot13 in C++

Published on 19 October 2023 (Updated: 19 October 2023)

Welcome to the Rot13 in C++ page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

#include <iostream>
#include <string>

using namespace std;

void rot13(string& str) {
    for (char& c : str) {
        if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
            if (('a' <= c && c <= 'm') || ('A' <= c && c <= 'M')) {
                c += 13;
            } else {
                c -= 13;
            }
        }
    }
}

int main(int argc, char* argv[]) {
    if (argc == 2 && string(argv[1]).size() != 0) {
        string inputString(argv[1]);
        rot13(inputString);
        cout << inputString << endl;
    } else {
        cout << "Usage: please provide a string to encrypt" << endl;
    }

    return 0;
}

Rot13 in C++ was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.