ROT13 C++

The following program (written in C++) creates a filter program for converting ascii into ROT13 encoding. A very simple cypher where each character in the alphabet is replaced with the 13th letter from its position. To download a compiled windows compatible binary, click here.

#include <cstring>
#include <cstdio>
#include <cctype>

using namespace std;

char translate(char c)
{
    int cflag = 0;
    char oc = c;
    char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
    int alphalen = strlen(alphabet);
    if(isalpha(c)) {
        if(isupper(c)) {
            cflag = 1;
            c = tolower(c);
        }
        for(int i=0;i<alphalen; ++i) {
            if(c==alphabet[i]) {
                oc = alphabet[(i+13)%alphalen];
            }
        }
        if(cflag==1) {
            oc = toupper(oc);
        }
    }
    return oc;
}

int main() {
    char c;
    while((c=(char)getchar())!=EOF) {
        putchar(translate(c));
    }
    return 0;
}

4 Replies to “ROT13 C++”

  1. Magnificent goods from you, man. I’ve understand your stuff previous to and you are just too excellent. I really like what you have acquired here, really like what you are stating and the way in which you say it. You make it entertaining and you still care for to keep it smart. I can’t wait to read far more from you. This is really a terrific site.

  2. Hi there, i read your blog occasionally and i own a similar one and i was just curious if you get a lot of spam comments? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it’s driving me crazy so any assistance is very much appreciated.

  3. Hello there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when browsing from my iphone4. I’m trying to find a template or plugin that might be able to fix this issue. If you have any suggestions, please share. Appreciate it!

  4. A ton of spam that I never noticed until recently, guess I was under their radar for awhile but not anymore. So now increased posting security is going on.

Comments are closed.