Im still noob on C Programming. And I just want to ask can you help me understand this codes. Like share some link about this topic and is there other way on doing it?

The output of this is like: When I type HELLO the output will be URYYB (Rot13 Encryption) I hope you can help me further understand and learn some other way(simple way) of doing it ^_^

#include <stdio.h>
#include <conio.h>
int main(){
int c;
        while ((c = getchar()) != EOF){
                if (c>='a' && c<='m') c += 13;
                else if (c >= 'n' && c <= 'z') c -= 13;
                else if (c >= 'A' && c <= 'M') c += 13;
                else if (c >= 'N' && c <= 'Z') c -= 13;

Search Google for ROT13 and you'll have links. Wikipedia is usually good for info on things like this - might go there first, actually.

ROT13 is just a simple replacement scheme. Each letter of the text is shifted up by 13 letters. That doesn't work for letter in the top half of the alphabet though, since there are only 26 letters. So those letters in the upper half of the alphabet, are shifted 13 letters down, instead of up. Handling that assignment, will take one if statement, at least.

Then you have the uppercase letters, and again, A through M are shifted upward, but letters > M must be shifted downwards, and again, all shifts are by 13 letters. That will take another if statement to handle that, at minimum.

In the code you posted, it's handled all together, by using if else if, else if, and else if, in one block of code.

The reason it works out so easily, is simply because 13 is half of 26. Needless to say, it's not a secure encryption, at all.

This article has been dead for over six months. Start a new discussion instead.