Freedom The Open Source Way Contribute Articles or News to OSForgeOSForge HomeLogout from Forums
Contacting OSForgeOSForge HomeAbout OSForge
  

Root
Contribute News
Learning Corner
Linux Distributions
Linux Common FAQ's
Discussion Forums
Community Gallery
Links Directory
Search OSForge
Networking
Industry Updates
Linux & Open Source
Opinions
Press Release
Programming
Security
Web Development

White Paper
Plat'Home Launches First Linux-based Eco-Friendly Servers In United States
World’s Largest Python Conference Sees 70 Percent Jump in Attendance
Leading SaaS Infrastructure Provider Deploys Zenoss to Improve Uptime and Reduce Cost
JasperSoft is Most Widely-Deployed Business Intelligence Software in the World
Cluster Resources to Showcase Adaptive Windows/Linux Cluster at BrainShare
Funambol Helps New AGPLv3 Open Source License Gain Formal OSI Approval
Zenoss Sponsors PyCon 2008 and Leads Application Monitoring Discussion
The Linux Foundation Reveals Speaker Line-up for 2nd Annual Collaboration Summit
Zenoss Core Named 2008 CODiE Awards Finalist for Best Open Source Solution

View More »

Implementing and strengthening the ROT-13 encryption algorithm
By : Nikhil Ribeiro Find more article by Nikhil Ribeiro on Programming
Saturday the 18th, May 2002 at 01:18 PM (CDT)
Send this Story to a Friend Readers TalkBack (0) - 2646 Reads

Printer Friendly Page Printable format
Send this Story to a Friend Foward to Email

Learn how to implement the ROT-13 encryption algorithm and how to make it stronger. A basic knowledge of C++ is required.

Introduction -

Encryption is basically just a method of distorting data so that no one other than you can read it. In this tutorial you will learn how to implement encryption algorithm ROT-13. Knowledge of C++ is required to fully understand this tutorial.

How encryption works ?

The data you want to be encrypted is known as the plain-text. The encrypted data is known as cipher-text. The first algorithm we will learn about works like this ?

Plain-text ? key ? Cipher-text

We won?t learn encryption using a key here, you will only learn how to use ROT-13 and how to strengthen it.

The ROT-13 method ?

The ROT-13 method or algorithm is actually much easier to implement than XOR. Its working is very simple, any character that it reads it will add 13 to it, so "a" will become "n". Its so amazingly simple that there?s no need for anymore explanation. Here?s some C++ code that demonstrates the ROT-13 algorithm.

//Warning: This code might not work, it meant solely for demonstration purposes//

#include

#include

#include

main()

{

cout
char *name;

cin >> name;

FILE *in;

FILE *out;

in = fopen(name, "r");

out = fopen("enc.txt", "w");

int c;

while(( c = getc(in)) != EOF)

{

c = c + 13;

putc(c, out);

}

fcloseall();

cout
return 0;

}

Strengthening ROT-13 -

Now, as you might have guessed its pretty easy to break ROT-13, all you have to do is read a character from a file and subtract 13 from it. Next let us learn how to strengthen ROT-13 considerably. There are various ways to strengthen ROT-13, I will explain only two ?

Ask the user for a key and suppose the length of the key is 10, perform ROT-13 ten times continuously. Therefore, if a person doesn?t know the length of the key it would be slightly difficult to find the original text. This too can be broken but not as easily as the plain ROT-13.
Ask the user for a key. Read character by character from the key and add them all up. If the sum of all the digits is an even number, encrypt every second character. If the key is a odd number, reverse the file before encryption.
This section was meant only for experienced C++ programmers so don?t worry if you didn?t understand a thing.

Conclusion-

Sorry for making this tutorial so very short but it was meant to explain only the ROT-13 algorithm and that?s exactly what It does J

I promise I?ll write more tutorials on various algorithms in the near future.

If you have any problems feel free to e-mail me at nikhil2ribeiro@yahoo.com.

  
Reader Rating from 1-5

 

Poor very 

1

2

3

4

5
 very Excellent

Talkback

Post Your Talkback | View All Talkback (0 Posted)


 Currently there are no Talkback posted on "Implementing and strengthening the ROT-13 encryption algorithm", Click here to be the first to post a talkback.


 
Scroll Up

   About | Term of Use | Privacy | Contact us | Tell a Friend | Advertise  

OSForge News RSS Feed