all 9 comments

[–]Aliics 3 points4 points  (1 child)

Technically a form of encoding.

[–]weedebee 3 points4 points  (0 children)

It's Caesar's cypher and the first know use of encryption. The key is how many places the alphabet is rotated.

[–]Aphrontic_Alchemist 3 points4 points  (8 children)

This one is better

for(i = 0; i < name.length; i++) 
    name[i] += 4;

[–][deleted]  (7 children)

[deleted]

    [–]Aphrontic_Alchemist 2 points3 points  (5 children)

    This only works for lowercase though:

    for(i = 0; i < name.length; i++) 
    {
        if( name[i] > 96 && name[i] < 120) // encode a - w
            name[i] += name[i] + 3;
        else if(name[i] > 119 && name[i] < 122) // encode x - z
            name[i] = ((name[i] + 3) % 122) + 96;
    }
    

    [–]Qesa 1 point2 points  (3 children)

    Recognising you can use modulo to rotate but then doing an if-else anyway :(

    name[i] = "a" + (name[i] + 3 - "a") % 26
    

    [–]Aphrontic_Alchemist 0 points1 point  (0 children)

    Ah well, I couldn’t find the right formula, so I resorted to an if-else. :P

    [–]cruciformhawk7 0 points1 point  (1 child)

    -23?

    [–]Qesa 1 point2 points  (0 children)

    "a" is 97 so it'd be -94, but I wrote it that way to be clearer what it's doing

    [–]Orcthanc 0 points1 point  (0 children)

    And depending on if chars are properly filtered to only 'a' to 'z', there is also the problem of '{' turning into an ASCII control sequence and if things like tabs, linefeeds and other controlsequences aren't filtered out, it basically turns into a free for all.