Click here to Skip to main content
12,076,216 members (47,358 online)
Click here to Skip to main content
Add your own
alternative version

Stats

12.6K views
609 downloads
11 bookmarked
Posted

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

You may also be interested in...

Comments and Discussions

 
GeneralNot so good Pin
PIEBALDconsult24-Mar-09 13:07
memberPIEBALDconsult24-Mar-09 13:07 
Generalgetters and setters.... Pin
Adrian Pasik24-Mar-09 11:18
memberAdrian Pasik24-Mar-09 11:18 
GeneralPlease... Pin
CreF24-Mar-09 6:27
memberCreF24-Mar-09 6:27 
GeneralRe: Please... Pin
Adrian Pasik24-Mar-09 8:32
memberAdrian Pasik24-Mar-09 8: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.

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