VB icon

ROT13

Email
Submitted on: 8/28/2016 4:52:13 PM
By: Ben  
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general), Microsoft Visual C++, UNIX C++
Views: 1203
 
     This is an example or the very popluer ROT13 encryption. This is made for beginners to learn some simple encryption. Hope if comes in handy.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: ROT13
// Description:This is an example or the very popluer ROT13 encryption. This is made for beginners to learn some simple encryption. Hope if comes in handy.
// By: Ben
//**************************************

//ROT13 Encryption
//By ~DreamVB~
#include <iostream>
using namespace std;
using std::cout;
using std::endl;
string Rot13(string s){
	int i = 0;
	string s_buffer = "";
	unsigned char c = '\0';
	while(i <=s.length()){
		//Get char
		c = s[i];
		//Check lowercase letters.
		if (islower(c)){
			c += 13;
			if (c > 'z'){
				c-= 26;
			}
		}
		//Check uppercase letters.
		if (isupper(c)){
			c += 13;
			if (c > 'Z'){
				c-=26;
			}
		}
		//Build string
		s_buffer += c;
		//INC counter
		i++;
	}
	//Return string
	return s_buffer;
}
int main(int argc, char *argv[]){
	string s_test = "This is an example of ROT13 in C++";
	string s0 = "";
	//Encrypt
	s0 = Rot13(s_test);
	cout << "Original : " << s_test.c_str() << endl;
	cout << "Encrypted : " << s0.c_str() << endl;
	//Decrypt
	s0 = Rot13(s0);
	cout << "Decrypted : " << s0.c_str() << endl;
	//Clear up
	s0.clear();
	s_test.clear();
	system("pause");
	return 0;
}


Other 50 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.