Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / Windows Forms

Encryption and Decryption

Rate me:
Please Sign up or sign in to vote.
3.36/5 (7 votes)
24 Mar 2009CPOL 24.6K   846   10   4
Its the software who can make the Ceasares Code

Introduction

Ceasares Code, to Encrypt the Text and Text File :)

Background

Using the Code

The software is in made in the Albanian language. So let's explain some words from Albanian to English.

The word ENKRIPTO - means Encrypt and DEKRYPTO means Decrypt. The word CELESI - means the KEY -> how many characters to displace(move) examples from:

A ->to C means Key 2 , and ENKRIPTIMI dhe DEKRIPTIMI means ENCRYPTIONS AND DECRYPTIONS

The trick is in Ceasers formulas and in KEY

The Class: Enkripto_Dekripto.cs

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CESAR1
{
    public class Enkripto_Dekripto
    {
        private float karakteret;
        private string strBrowse;
        private int MemoriaCelesi;

        public int CelesiMemorik
        {

            set 
            {
                MemoriaCelesi = value;
            }
            get 
            {
                return MemoriaCelesi;
            }
        }


        public float k
        {
            set
            {
                karakteret = value;
            }
            get
            {
                return karakteret;
            }
        }

        public string str
        {
            set
            {
                strBrowse = value;
            }
            get
            {
                return strBrowse;
            }
        }

        public Enkripto_Dekripto()
        {
            karakteret = 0.0f;
            strBrowse = string.Empty;
            MemoriaCelesi = 0;
        }
    }
}

private void btnEnkripto_Click(object sender, EventArgs e)
{
    if (txtPlainText.Text.Length != 0)
    {
        txtEnkriptuar.Clear();
        int Total = txtPlainText.Text.Length;
        lblTekstiCH.Text = Total.ToString();
        char[] c;
        int p;
        int Celesi = Convert.ToInt16(txtCelesi.Text);
        c = txtPlainText.Text.ToCharArray(0, Total);
        objEnkDek.CelesiMemorik = Celesi;
        for (int i = 0; i < Total; i++)
        {
            if (c[i] > 64 && c[i] < 91)
            {
                objEnkDek.k = objEnkDek.k + 1;
                p = (char)c[i];
                p = p - 65;
                if ((Celesi >= 0) && (Celesi <= 26))
                {
                    p = p + Celesi;
                    p = p % 26;
                    p = p + 65;
                    c[i] = (char)p;
                }
                else
                {
                    MessageBox.Show("Celesi duhet te jete numer pozitiv mbrenda 0-26");
                    txtCelesi.Text = "0";
                    Celesi = 0; 
                }
            }
            else if (c[i] > 96 && c[i] < 123)
            {
                objEnkDek.k = objEnkDek.k + 1;
                p = (char)c[i];
                p = p - 97;
                if ((Celesi >= 0) && (Celesi <= 26))
                {
                    p = p + Celesi;
                    p = p % 26;
                    p = p + 97;
                    c[i] = (char)p;
                }
                else
                {
                    MessageBox.Show("Celesi duhet te jete numer pozitiv mbrenda 0-26");
                    txtCelesi.Text = "0";
                    Celesi = 0;
                }
            }

            txtEnkriptuar.AppendText(c[i].ToString());
        }
    }
    else
    {
        MessageBox.Show("Ju lutem Mbushni Text per te Enkriptuar");
    }
    lblEnCH.Text = txtEnkriptuar.Text.Length.ToString();
} 

private void btnDekripto_Click(object sender, EventArgs e)
{
    if (txtiEnkriptuar.Text.Length != 0)
    {
        txtDekriptuar.Clear();
        int Total = txtiEnkriptuar.Text.Length;
        lblEnD.Text = Total.ToString();
        char[] c;
        int p;
        int CelesiDE = Convert.ToInt16(txtCelesiDE.Text);
        CelesiDE = CelesiDE % 26;
        c = txtiEnkriptuar.Text.ToCharArray(0, Total);

        for (int i = 0; i < Total; i++)
        {
            if (c[i] > 64 && c[i] < 91)
            {
                p = (char)c[i];
                p = p - 65;
                if ((CelesiDE >= 0) && (CelesiDE <= 26))
                {
                    p = p - CelesiDE;
                    if (p < 0)
                    {
                        p = 26 + p;
                    }
                    p = p + 65;
                    c[i] = (char)p;

                }
                else
                {
                    MessageBox.Show("Celesi duhet te jete numer pozitiv mbrenda 0-26");
                    txtCelesiDE.Text = "0";
                    CelesiDE = 0;

                }

            }
            else if (c[i] > 96 && c[i] < 123)
            {
                p = (char)c[i];
                p = p - 97;
                if ((CelesiDE >= 0) && (CelesiDE <= 26))
                {
                    p = p - CelesiDE;
                    if (p < 0)
                    {
                        p = 26 + p;
                    }
                    p = p + 97;
                    c[i] = (char)p;

                }
                else
                {
                    MessageBox.Show("Celesi duhet te jetenumer pozitiv mbrenda 0-26");
                    txtCelesiDE.Text = "0";
                    CelesiDE = 0;
                }

            }
            txtDekriptuar.AppendText(c[i].ToString());
        }
    }
    lblDECH.Text = txtDekriptuar.Text.Length.ToString();
}

History

To Be Conntinued

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Albania Albania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNot so good Pin
PIEBALDconsult24-Mar-09 12:07
mvePIEBALDconsult24-Mar-09 12:07 
Generalgetters and setters.... Pin
Adrian Pasik24-Mar-09 10:18
Adrian Pasik24-Mar-09 10:18 
GeneralPlease... Pin
CreF24-Mar-09 5:27
professionalCreF24-Mar-09 5:27 
Hi dj_limi,
I only would like to kindly ask you, if, for the next article and code, you could use localization or English in your code.

Thanks in advance
CreF Cool | :cool:

the CreF

GeneralRe: Please... Pin
Adrian Pasik24-Mar-09 7:32
Adrian Pasik24-Mar-09 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.