Click here to Skip to main content
Click here to Skip to main content

Encryption and Decryption

, 24 Mar 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Its the software who can make the Ceasares Code

Introduction

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

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dj_limi
Team Leader
Albania Albania
No Biography provided

Comments and Discussions

 
GeneralNot so good PinmemberPIEBALDconsult24-Mar-09 13:07 
Generalgetters and setters.... PinmemberAdrian Pasik24-Mar-09 11:18 
GeneralPlease... PinmemberCreF24-Mar-09 6:27 
GeneralRe: Please... PinmemberAdrian Pasik24-Mar-09 8:32 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150301.1 | Last Updated 24 Mar 2009
Article Copyright 2009 by dj_limi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid