Ceasar code (Caesar code)

Saturday, 17 January 2009
source code programe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CeasarCode
{
class Program
{
static void Main(string[] args)
{
int choice = 0;
while (choice != 3)
{
Menu();
Console.Write("\nChoose Menu mode\n=> ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1: Encode(); break;
case 2: Decode(); break;
case 3: Console.WriteLine("\n\nThank You..............\n\nBy PINYA SITTHIWONG");
DelayT(45); break;
default: break;
}

}

}
public static void Menu()
{
Console.WriteLine("\n\nCeasar Code Menu ");
Console.WriteLine("1.Encode ");
Console.WriteLine("2.Decode ");
Console.WriteLine("3.Exit ");
}
public static void Encode()
{
Console.WriteLine("\n\nCeasar EnCoder Mode\n");
Console.Write("Enter your Data for Encode\n=> ");
string strEn = Console.ReadLine();
Console.Write("Enter your hashing nuber\n=> ");
int hash = int.Parse(Console.ReadLine());
hash = hash % 26;
int len = strEn.Length;
char[] chE = new char[len];
chE = strEn.ToCharArray();
int count, temp, detected, diff;
for (count = 0; count < len; count++)
{
detected = chE[count];
temp = detected + hash;
if ((detected >= 65) && (detected <= 90))
{
if (temp > 90)
{
diff = temp - 90;
temp = 64 + diff;
}
chE[count] = Convert.ToChar(temp);
}
else if ((detected >= 97) && (detected <= 122))
{
if (temp > 122)
{
diff = temp - 122;
temp = 96 + diff;
}
chE[count] = Convert.ToChar(temp);
}

}
Console.Write("After Encoder \n=> ");
for (count = 0; count < len; count++)
{
Console.Write(chE[count]);
}
DelayT(38);
}
public static void Decode()
{
Console.WriteLine("\n\nCeasar Decoder Mode");
Console.Write("Enter your data for Decode\n=> ");
string strDe = Console.ReadLine();
Console.Write("\nEnter your hashing number\n=> ");
int hash = int.Parse(Console.ReadLine());
hash = hash % 26;
int len = strDe.Length;
char[] chD = new char[len];
chD = strDe.ToCharArray();
int count, temp, detected, diff;

for (count = 0; count < len; count++)
{
detected = chD[count];
temp = detected - hash;

if ((detected >= 65) && (detected <= 90))
{
if (temp < 65)
{
diff = 65 - temp;
temp = 91 - diff;
}
chD[count] = Convert.ToChar(temp);
}
else if ((detected >= 97) && (detected <= 122))
{
if (temp < 97)
{
diff = 97 - temp;
temp = 123 - diff;
}
chD[count] = Convert.ToChar(temp);
}

}

Console.WriteLine("After Decoder\n=> ");
for (count = 0; count < len; count++)
{
Console.Write(chD[count]);
}
DelayT(38);
}
public static void DelayT(int del)
{
int countD;
for (countD = 0; countD < del; countD++)
{
for (countD = 0; countD < del; countD++)
{
System.Threading.Thread.Sleep(del);
}
}
}
}
}
//end Ceasar code Example

3 comments:

Nadine H. said...

lol

Nadine H. said...

hahahhahahahahah XD

Nadine H. said...

ik ben niet meneer wellink

Post a Comment