C# Tutorial Create a text Caesar Cipher encryption application
- Subject: C# Tutorials
- Learning Time: 1.5 hours
Caesar Cipher encryption application full code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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