Advertisement
SuperLemrick

Caesars Cipher

Dec 7th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Caesars_Cipher
  11. {
  12.     public partial class CaesarCipherForm : Form
  13.     {
  14.         public CaesarCipherForm()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void EncodeButton_Click(object sender, EventArgs e)
  20.         {
  21.             string decodedString = StringTextBox.Text;
  22.             string encodedString = "";
  23.             for (int i = 0; i < decodedString.Length; i++)
  24.             {
  25.                 char thisChar = decodedString[i];
  26.                 int encodedValue = (int)thisChar;
  27.                 encodedString += encodedValue.ToString("D3") + ",";
  28.             }
  29.             StringTextBox.Text = encodedString;
  30.         }
  31.  
  32.         private void DecodeButton_Click(object sender, EventArgs e)
  33.         {
  34.             string encodedString = StringTextBox.Text;
  35.             string decodedString = "";
  36.             for (int i = 0; i < encodedString.Length; i += 4)
  37.             {
  38.                 string digits = encodedString.Substring(i, 3);
  39.                 int numericValue = int.Parse(digits);
  40.                 char decodedValue = (char)numericValue;
  41.                 decodedString += decodedValue;
  42.             }
  43.             StringTextBox.Text = decodedString;
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement