Hello ,
this is my solution for JoeilG ,
first browse in the CodeProject under
Learning Zones ,
Solutions Center ,
General Programming,
Cryptograpfy & Security
you have a whole chapter devoted to cryptography.
http://www.codeproject.com/KB/security/[
^]
Here is sample of code for Encryption of small text messages :
Program.cs
using System;
namespace Encryption
{
class Program
{
public static void Main(string[] args)
{
string Original_Message = "";
string Encrypted_Message = "";
string Original_Message_Letter_String = "";
string Encrypted_Message_Letter_String = "";
string Rotation_key_string = "";
char Original_Message_Letter_Char = ' ';
char Encrypted_Message_Letter_Char = ' ';
int Letter_code = 0;
int Rotation_key_number = 0;
int Message_Lenght = 0;
int Counter = 0;
Console.Title = "Encryption program";
Console.SetWindowSize(80,25);
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("-------------------------------------------------");
Console.WriteLine(" Program for encryption of text messages");
Console.WriteLine("-------------------------------------------------");
Console.WriteLine("");
Console.WriteLine("Type your message here :");
Console.WriteLine("------------------------");
Original_Message = Console.ReadLine();
Console.WriteLine("");
Console.WriteLine("Value of rotation key :");
Console.WriteLine("------------------------");
Rotation_key_string = Console.ReadLine();
Rotation_key_number = int.Parse(Rotation_key_string);
Console.WriteLine("------------------------");
Console.WriteLine("");
Message_Lenght = Original_Message.Length;
Counter = 0;
while(Counter < Message_Lenght)
{
Original_Message_Letter_String = Original_Message.Substring(Counter,1);
Original_Message_Letter_Char = char.Parse(Original_Message_Letter_String);
Letter_code = Original_Message_Letter_Char;
Letter_code = Letter_code + Rotation_key_number;
Encrypted_Message_Letter_Char = (char) Letter_code;
Encrypted_Message_Letter_String = Encrypted_Message_Letter_Char.ToString();
Encrypted_Message = Encrypted_Message + Encrypted_Message_Letter_String;
Counter = Counter + 1;
}
Console.WriteLine("Encrypted message");
Console.WriteLine("-------------------------------------------------");
Console.WriteLine(Encrypted_Message);
Console.WriteLine("-------------------------------------------------");
Console.WriteLine("");
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
Here is sample of code for Decryption of small text messages :
Program.cs
using System;
namespace Decryption
{
class Program
{
public static void Main(string[] args)
{
string Encrypted_Message = "";
string Decrypted_Message = "";
string Encrypted_Message_Letter_String = "";
string Decrypted_Message_Letter_String = "";
string Rotation_key_string = "";
char Encrypted_Message_Letter_Char = ' ';
char Decrypted_Message_Letter_Char = ' ';
int Letter_code = 0;
int Rotation_key_number = 0;
int Message_Lenght = 0;
int Counter = 0;
Console.Title = "Decryption program";
Console.SetWindowSize(80,25);
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("-------------------------------------------------");
Console.WriteLine(" Program for decryption of text messages");
Console.WriteLine("-------------------------------------------------");
Console.WriteLine("");
Console.WriteLine("Type your Encrypted message here :");
Console.WriteLine("-----------------------------------");
Encrypted_Message = Console.ReadLine();
Console.WriteLine("");
Console.WriteLine("Value of rotation key :");
Console.WriteLine("------------------------");
Rotation_key_string = Console.ReadLine();
Rotation_key_number = int.Parse(Rotation_key_string);
Console.WriteLine("------------------------");
Console.WriteLine("");
Message_Lenght = Encrypted_Message.Length;
Counter = 0;
while(Counter < Message_Lenght)
{
Encrypted_Message_Letter_String = Encrypted_Message.Substring(Counter,1);
Encrypted_Message_Letter_Char = char.Parse(Encrypted_Message_Letter_String);
Letter_code = Encrypted_Message_Letter_Char;
Letter_code = Letter_code - Rotation_key_number;
Decrypted_Message_Letter_Char = (char) Letter_code;
Decrypted_Message_Letter_String = Decrypted_Message_Letter_Char.ToString();
Decrypted_Message = Decrypted_Message + Decrypted_Message_Letter_String;
Counter = Counter + 1;
}
Console.WriteLine("Decrypted message - Original text");
Console.WriteLine("-------------------------------------------------");
Console.WriteLine(Decrypted_Message);
Console.WriteLine("-------------------------------------------------");
Console.WriteLine("");
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
If you are using IDE SharpDevelop you can find complete solutions for those programs on this adress :
Encryption[
^]
All the best,
Perić Željko