• If you're here for vtubers, I highly recommend you go to The Virtual Asylum instead.
    They'll love you there

ROT13

Halo

varishangout.com
Regular
I was bored this morning so made this ROT13... uh... thing?

Feel free to yell at me for doing stuff wrong :nana-thumb:
C++:
#include <iostream>

int main() {
    char alp[26] = {'a','b','c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o','p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y','z'};
    int c; //The offset amount
    std::string t; //actual word
    std::string n; //the ROT13 string

    std::cout << "Choose Offset: ";
    std::cin >> c;
    std::cout << "Type your word: ";
    std::cin >> t;

    for (int i = 0; i < t.length(); i++) {
        for (int w = 0; w < sizeof(alp); w++) { //loop through all 26 character of alphabet
            if (t[i] == alp[w]) { //when you find a match for the character
                if (w + c > 26) { //if the current is over the alphabet limit
                    int new_char = w + c - 26;
                    n = n + alp[new_char];
                }
                else { //if it is not
                    int new_char = w + c; //do the math and give number

                    n = n + alp[new_char]; //add to string

                }
            }
        }
    }
    std::cout << n;
    return 0;
}


Edit:

think about it could make the 13 a variable and have you choose the offset.. so I did that

Edit2:

ah just realised it doesn't work with upper case letter. Oops
 
Last edited:

Directional Vector

varishangout.com
I was bored this morning so made this ROT13... uh... thing?

Feel free to yell at me for doing stuff wrong :nana-thumb:
C++:
#include <iostream>

int main() {
    char alp[26] = {'a','b','c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o','p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y','z'};
    int c; //The offset amount
    std::string t; //actual word
    std::string n; //the ROT13 string

    std::cout << "Choose Offset: ";
    std::cin >> c;
    std::cout << "Type your word: ";
    std::cin >> t;

    for (int i = 0; i < t.length(); i++) {
        for (int w = 0; w < sizeof(alp); w++) { //loop through all 26 character of alphabet
            if (t[i] == alp[w]) { //when you find a match for the character
                if (w + c > 26) { //if the current is over the alphabet limit
                    int new_char = w + c - 26;
                    n = n + alp[new_char];
                }
                else { //if it is not
                    int new_char = w + c; //do the math and give number

                    n = n + alp[new_char]; //add to string

                }
            }
        }
    }
    std::cout << n;
    return 0;
}


Edit:

think about it could make the 13 a variable and have you choose the offset.. so I did that

Edit2:

ah just realised it doesn't work with upper case letter. Oops
Is there a reason you typed the entire alphabet into an array? I think it's easier to just use integers.

C++:
#include <iostream>
#include <cstring>
#include <string>

int main(int argc, const char **argv)
{
    if (argc < 3) // needs the unencoded string and a scaling factor
    {
        std::cout << "not enough arguments" << std::endl;
        return 0;
    }

    std::string r; // the rot13 string
    for (int i = 0; i < strlen(argv[1]); i++) // loop over every character of the first given string
    {
        int c = (int)(argv[1][i]); // current character as number
        if (c < 65 || c > 122 || (c > 90 && c < 97)) // char not within range of A - z or between Z & a
        {
            std::cout << "unsupported character: " << argv[1][i] << std::endl; // print the current character
            return 0;
        };

        int e = c + std::stoi(argv[2]); // add offset to the current character
        if (c < 91 && e > 90 || (c > 96 && e > 122)) // number out of bounds
        {
            e -= 26; // Roll back
        }
        r += (char)(e); // append shifted character to string
    }

    std::cout << r << std::endl;
    return 0;
}

You need the c > 90 && c < 97 in line 18 because ASCII is weird and between Z and a are some other special characters.
I tested this with [file] aAbBcCdDzZ 2 and it outputs cCdDeEfFbB.
Also this shits the bed if the second (third) argument is a character. A try catch block can handle it but I'm lazy.

Edit: some comments and a wrong number
 
Last edited:

Halo

varishangout.com
Regular
Is there a reason you typed the entire alphabet into an array? I think it's easier to just use integers.
I do not remember, this was a while ago. I think it was just the first thing that came to mind, like I said in the op i was bored after waking up and just wanted to make something.
Also a lot less thinking goes into that :hinata-hyper:
 

Directional Vector

varishangout.com
I just realised that my shit code can't be used to decrypt because I didn't check for characters being too low, give me a moment :puddicat-sweat:
C++:
else if (e < 65 || (e < 97 && e > 90))
{
    e += 26;
}
fixes it. I think that bit is self explaining.
C++:
#include <iostream>
#include <cstring>
#include <string>

int main(int argc, const char **argv)
{
    if (argc < 3) // needs the unencoded string and a scaling factor
    {
        std::cout << "not enough arguments" << std::endl;
        return 0;
    }

    std::string r;
    for (int i = 0; i < strlen(argv[1]); i++)
    {

        int c = (int)(argv[1][i]);
        if (c < 65 || c > 122 || (c > 90 && c < 97)) // char not within range of A - z
        {
            std::cout << "unsupported character: " << argv[1][i] << std::endl;
            return 0;
        };

        int e = c + std::stoi(argv[2]);
        if (c < 91 && e > 90 || (c > 96 && e > 122)) // out of bounds
        {
            e -= 26;
        }
        else if (e < 65 || (e < 97 && e > 90))
        {
            e += 26;
        }
        r += (char)(e);
    }

    std::cout << r << std::endl;
    return 0;
}
 
Top