
Implementing and strengthening the ROT-13 encryption algorithm
Date: Saturday, May 18 2002 Topic: Programming
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.
|
|