C# Tutorial Create a text Caesar Cipher encryption application
- Subject: C# Tutorials
- Learning Time: 1.5 hours
Caesar Cipher encryption application full code below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace encryptionsystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string origMessage = normalText.Text;
int shiftNum = Int32.Parse(textBox3.Text);
cypherText.Text = doEncryption(origMessage.ToLower(), shiftNum);
}
private static string doEncryption(string words, int shiftNo)
{
char[] buffer = words.ToCharArray();
for (int i = 0; i < buffer.Length; i++) { // each letter will be seperated and then changed. char letter = buffer[i]; // shift the letters according to the shift no variable letter = (char)(letter + shiftNo); // Subtract 26 on overflow. // Add 26 on underflow. if (letter > 'z')
{
letter = (char)(letter - 26);
}
else if (letter < 'a')
{
letter = (char)(letter + 26);
}
// Store.
buffer[i] = letter;
}
return new string(buffer);
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
helpScreen helpForm = new helpScreen();
helpForm.Show();
}
}
}
Pages: 1 2