Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Encryption and Decryption

0.00/5 (No votes)
23 Mar 2009 1  
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

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here