Kriptozaštita

Kriptozaštita tekstualnih poruka je izuzetno interesantna oblast sa aspekta programiranja.
U pitanju je šifrovanje podataka s ciljem da tačnu informaciju može da vidi samo odabrana osoba.
Postoje različiti Algoritmi i rešenja za kriptozaštitu , a dole navedeno je jedno od jednostavnijih.
U pitanju je "rotacija" , uvećanje vrednosti ASCII koda za slova u okviru tekstualne poruke za određenu vrednost koja se odredi unosom putem tastature.Sobzirom da je svako slovo na kompjuteru predstavljeno jedinstvenim brojem  ASCII kodom ( a = 65 , b = 66 , c = 67 itd) uvećanjem te vrednosti za svako slovo u poruci za određenu vrednost recimo jedan
( a = 65 + 1 postaje slovo b , b = 66 +1 postaje slovo c itd)
dobijamo potpuno novu poruku koja je nerazumljiva svima
osim onome ko ima ključ za dešifrovanje.Osoba koja treba da pročita poruku mora da ima tekst
šifrovane  poruke i vrednost ključa za koju se vrši umanjenje vrednosti ASCII koda.Pažnja program samo šifuje podatke , program za dešifrovanje probajte da napravite sami. Potrebno je da se promeni samo jedan karakter u programu Encryption pa da postane Decryption :)) Ukoliko ne ide na dole navedenom linku imate dva programa Encryption i Decryption.Pokušajte da uz pomoć Encryption programa šifrujete poruku, a zatim da je dešifrujete uz pomoć Decryption programa,kao što je prikazano na slici.
 
 
Na kraju strane se nalazi link za preuzimanje kompletnog projekta za IDE SharpDevelop C# 4.0. Ukoliko koristite ovo integrisano okruženje, kada preuzmete projekat i otvorite ga možete pogledati kompletan program i menjati ga po želji.
 
Proučite dole prikazan programski kod i sve će vam biti jasno.
 
/*
 * Created by Perić Željko
 * periczeljkosmederevo@yahoo.com
 * IDE Sharp Develop C#
 * Date: 28.11.2011
 * Time: 11:20
 * 
 * This is a simple console application for encryption of short
 * text messages (up to 255 caracters).It is based on
 * increasing of generic ASCII code of letters in text messages
 * by value of Rotation_key enterd trough keyboard.
 * 
 * example : Rotation_key = 1
 *              Message = ABC (ASCII : 65 , 66 , 67)
 *              Encrypted = BCD (ASCII : 66 ,67 , 68)
 * 
 * Since the value of the ASCII code is limited ,
 * so the value of the Rotation_key should be limited
 * it is up to you to find min and max values.
 * When you do that , given key name will be justified.
 * 
 * !!! The program is not final because it has no part to check
 *      what exactly user had entered on the keyboard
 *         there should be try...parse...catch part.
 *         it is up to you.
 *         It allso can be modifed to load .txt document,
 *         encrypt text from it and then send it trough mail,
 *         for example.
 *         There is only part of program for encryption,
 *         the other part for decryption you shuld write 
 *         yourself.Look at this code it should be easy.
 * !!!
 * 
 * Good luck and happy learning of C#
 * 
 */
 
using System;

namespace Encryption
{
    class Program
    {
        public static void Main(string[] args)
        {
            
            //
            // variables declaration
            //
            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;
            
            //
            // Hello to user
            //
            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("");
            
            //
            // Get text message from console
            //
            Console.WriteLine("Type your message here :");
            Console.WriteLine("------------------------");
            Original_Message = Console.ReadLine();
            Console.WriteLine("");
            
            //
            // Get value of rotation key from console
            // and transfer it to number
            //
            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("");
            
            //
            // Encrypt message
            //
            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;
            }
            
            //
            // Write encrypted message on console
            //
            Console.WriteLine("Encrypted message");
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine(Encrypted_Message);
            Console.WriteLine("-------------------------------------------------");
            Console.WriteLine("");
            
            //
            // End of program
            //
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}