Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# Windows Forms Application : Cipher program The use of codes (or ciphers) as a

ID: 3678213 • Letter: C

Question

C#

Windows Forms Application: Cipher program The use of codes (or ciphers) as a means of hiding the meaning of messages traces its roots to ancient history. The first known military use of codes was by Julius Caesar in 50 - 60 B.C. The Caesar cipher specified that each letter in the alphabet would be encoded using the letter three positions later in the alphabet. For example, 'a' would be encoded as 'd', 'b' would be encoded as 'e', 'c' would be encoded as 'f', and so on. The code wraps around at the end of the alphabet, so 'x', 'y' and 'z' would be encoded as 'a', 'b', and 'c', respectively. The complete mapping of letters is shown below.

Caesar cipher:

abcdefghijklmnopqrstuvwxyz

| | | | | | | | | | | | | V V V V V V V V V V V V V

defghijklmnopqrstuvwxyzabc

Create a Windows Form Application C# that has radio buttons for encoding or decoding a phrase. If the user enters a phrase in a textbox and selects the encode radio button and then presses a “go” button (whatever you would like to call it), you should invoke an encode method and display the resulting phrase. If the user were to select decode, you should translate the phrase from the coded message back to the original. Your final program should have encode and decode methods and should use a Hashmap to map the cipher alphabet to the original alphabet

Explanation / Answer

using System.IO;
using System;
using System.Drawing;
using System.Windows.Forms;

using System.Collections;


namespace WindowsmyApplication1 // creating application
{
public partial class Myform1 : Form //creating form
{
public Myform1()
{
InitializeComponent();//starting the application
}

private void Myform1_Load(object sender, EventArgs e) //loading the form
{
textBox1.Width = 250;
textBox1.Height = 50;
textBox1.Multiline = true;
textBox1.BackColor = Color.Blue;
textBox1.ForeColor = Color.White;
textBox1.BorderStyle = BorderStyle.Fixed3D;
radioButton1.Checked = true;// checking radio buttons
}

private void Go_Click(object sender, EventArgs e)
{
string st;
st = textBox1.Text;//for plain text
MessageBox.Show(st);//showing plain text
if (radioButton1.Checked == true)
{
MessageBox.Show ("You are selected for encoding ");
Myform1= m new Myform1();
st = m.encode(st);//calling for encryption
MessageBox.Show(st);//shows encrypted code
return;
}
  
else
{
MessageBox.Show("You are selected for decoding ");
Myform1= m new Myform1();
st = m.decode(st);//for decrypting
MessageBox.Show(st);//shows plain text
return;
}
}
public string encode(string str) // encoding method
{
for (int r = 0; r <= str.Length - 1; r++ )
{

if(int(str[r])<119)
Console.Write(char(int(str[r])+4), str[ctr]);   

else

  Console.Write(char(int(str[r])-22), str[ctr]);   
}  

}

public string decode(string str) //decoding method
{
for (int r = 0; r <= str.Length - 1; r++ )
{

if(int(str[r])>100)
Console.Write(char(int(str[r])-4), str[ctr]);   

else

  Console.Write(char(int(str[r])+22), str[ctr]);   
}  

}


}
}
}