The Department of Computing and Cyber Security is hosting a competition and has invited our class to help them create a cipher algorithm. The competition rules are to design a cipher algorithm extendi

using System; // these are standard libraries thatare included when

using System.Drawing; // creating a project using VS 2017 for C#

Windows project using .NET

using System.Windows.Forms;

namespace HelloCipher

{
public partial class HelloCipher_Form1 : Form
{
public static TextBox tbxOriginalText = new TextBox();

// text box to enter/view original text

public static TextBox tbxCipherText = new TextBox();

// text box to enter/view encrypted text
17
18 public static TrackBar tkbCipherOffset = new TrackBar();

// track bar tocontrol cipher rotation
19
20 public static Label lblTrackbarValue = new Label();

// labels for showing trackbar values
21
22 public static Label lblTkbr0 = new Label();

// trackbar label 0
23
24 public static Label lblTkbr5 = new Label();

// trackbar label 5
25
26 public static Label lblTkbr10 = new Label();

// trackbar label 10
27
28 public static Label lblTkbr15 = new Label();

// trackbar label 15
29
30 public static Label lblTkbr20 = new Label();

// trackbar label 20
31
32 public static Label lblTkbr25 = new Label();

// trackbar label 25

public static Label lblOriginalText = new Label();

// Label Original Text
33
34 public static Label lblOriginalText = new Label();

// Label Original Text
35
36 public static Label lblCipherText = new Label();

// Label CipherText
37
38 public static Label lblSelectOffset = new Label();

// Label which shows the cipher offset
39
40 public static Font Font30 = new Font("Times Roman",30,FontStyle.Bold);

// Font of size 30 Bold
41
42 public static Font Font8 = new Font("Times Roman", 8);

// Font of size8
43
44 public static Font Font12 = new Font("Times Roman", 12);

// Font of size12
45
46 public static Font Font16 = new Font("TimesRoman", 16);

// Font of size16
47
48 public static String OriginalText = "";

// String for original text
49
50 public static String CipherText = "";

// String for encrypted text
51
52 public HelloCipher_Form1()

// main form ofthe program
53 {
54 InitializeComponent();

// Initialize windows form system
55
56 Size = new Size(600, 500);

// set form size
57
58 Text = "Hello Cipher World (c) Akhtar Lodgher";

// set text of the form
59
60 tbxOriginalText.Location = new Point(20, 150); / //Settings for the Text box control of Original Text
61 tbxOriginalText.Width = 500;
62 tbxOriginalText.Height = 100;
63 tbxOriginalText.ReadOnly = false;
64 tbxOriginalText.Multiline = true;
65 tbxOriginalText.ScrollBars = ScrollBars.Vertical;
66 tbxOriginalText.BackColor = Color.White;
67 tbxOriginalText.TextAlign = HorizontalAlignment.Left;
68 tbxOriginalText.AcceptsReturn = true;
69 tbxOriginalText.AcceptsTab = true;
70 tbxOriginalText.WordWrap = true;
71 tbxOriginalText.CharacterCasing = CharacterCasing.Upper;

// All text is shown in Upper case
72 tbxOriginalText.Font = Font12;
73
74 tbxCipherText.Location = new Point(20, 310);

//Settings for the Text box control of Cipher Text
75 tbxCipherText.Width = 500;
76 tbxCipherText.Height = 100;
77 tbxCipherText.ReadOnly = true;
78 tbxCipherText.Multiline = true;
79 tbxCipherText.ScrollBars = ScrollBars.Vertical;
80 tbxCipherText.BackColor = Color.White;
81 tbxCipherText.TextAlign = HorizontalAlignment.Left;
82 tbxCipherText.Font = Font12;
83
84 tkbCipherOffset.Location = new Point(20, 60);

// Settings forthe trackbar control
85 tkbCipherOffset.Width = 400;
86 tkbCipherOffset.Minimum = 0;
87 tkbCipherOffset.Maximum = 25;
88 tkbCipherOffset.TickStyle = TickStyle.Both;
89 tkbCipherOffset.TickFrequency = 1;
90 tkbCipherOffset.SmallChange = 1;
91 tkbCipherOffset.LargeChange = 1;
92 tkbCipherOffset.Value = 5;
93
94 lblOriginalText.Location = new Point(20, 120);

// Settings for the OriginalText Label
95 lblOriginalText.Width = 400;
96 lblOriginalText.Height = 40;
97 lblOriginalText.Font = Font16;
98 lblOriginalText.Text = "Original Text:";
99
100 lblCipherText.Location = new Point(20, 275);

// Settingsfor the CipherText Label
101 lblCipherText.Width = 400;
102 lblCipherText.Height = 40;
103 lblCipherText.Font = Font16;
104 lblCipherText.Text = "Encrypted Cipher Text:";
105
106 lblTrackbarValue.Location = new Point(445, 45);

// Settingsfor the Trackbar Label
107 lblTrackbarValue.Width = 75;
108 lblTrackbarValue.Height = 50;
109 lblTrackbarValue.Text = tkbCipherOffset.Value.ToString();
110 lblTrackbarValue.Font = Font30;
111
112 lblSelectOffset.Location = new Point(20, 5);

// Settingsfor the Offset Value Label
113 lblSelectOffset.Width = 400;
114 lblSelectOffset.Height = 40;
115 lblSelectOffset.Font = Font16;
116 lblSelectOffset.Text = "Select Cipher Rotation Offset:";
117
118 lblTkbr0.Location = new Point(27, 40);

// Settingsfor the Trackbar 0 label
119 lblTkbr0.Width = 10;
120 lblTkbr0.Height = 15;
121 lblTkbr0.Text = "0";
122 lblTkbr0.Font = Font8;
123
124 lblTkbr5.Location = new Point(lblTkbr0.Location.X + 75,
125 lblTkbr0.Location.Y); // Settings for the Trackbar 5 label
126 lblTkbr5.Width = 10;
127 lblTkbr5.Height = 15;
128 lblTkbr5.Text = "5";
129 lblTkbr5.Font = Font8;
130
131 lblTkbr10.Location = new Point(lblTkbr0.Location.X + 145,
132 lblTkbr0.Location.Y); // Settings for the Trackbar 10 label
133 lblTkbr10.Width = 20;
134 lblTkbr10.Height = 15;
135 lblTkbr10.Text = "10";
136 lblTkbr10.Font = Font8;
137
138 lblTkbr15.Location = new Point(lblTkbr0.Location.X + 220,
139 lblTkbr0.Location.Y); // Settings for the Trackbar 15 label
140 lblTkbr15.Width = 20;
141 lblTkbr15.Height = 15;
142 lblTkbr15.Text = "15";
143 lblTkbr15.Font = Font8;
144
145 lblTkbr20.Location = new Point(lblTkbr0.Location.X + 295,
146 lblTkbr0.Location.Y);// Settings for the Trackbar 20 label
147 lblTkbr20.Width = 20;
148 lblTkbr20.Height = 15;
149 lblTkbr20.Text = "20";
150 lblTkbr20.Font = Font8;
151
152 lblTkbr25.Location = new Point(lblTkbr0.Location.X + 370,
153 lblTkbr0.Location.Y);// Settings for the Trackbar 25 label
154 lblTkbr25.Width = 20;
155 lblTkbr25.Height = 15;
156 lblTkbr25.Text = "25";
157 lblTkbr25.Font = Font8;
158
159 Controls.Add(tbxOriginalText);// Add the controlsto the form.
160
161 Controls.Add(tbxCipherText);
162 Controls.Add(tkbCipherOffset);
163 Controls.Add(lblTrackbarValue);
164 Controls.Add(lblTkbr0);
165 Controls.Add(lblTkbr5);
166 Controls.Add(lblTkbr10);
167 Controls.Add(lblTkbr15);
168 Controls.Add(lblTkbr20);
169 Controls.Add(lblTkbr25);
170 Controls.Add(lblSelectOffset);
171 Controls.Add(lblOriginalText);
172 Controls.Add(lblCipherText);
173
174 // Event handler to call when text is changed in original text box
175 tbxOriginalText.TextChanged += TbxOriginalText_TextChanged;
176
177 // Event handler to call when Cipher offset value is changed using the track bar
178
179 tkbCipherOffset.ValueChanged += TkbCipherOffset_ValueChanged;
180 {
181 // This event handler is used to convert the original text to cipher

text by offsetting the
182 // original text characters by the offset value whenever the original

text is changed
183 // It calls the event handler for the changing of the trackbar value
184
185 public void TbxOriginalText_TextChanged(object sender, EventArgs e)
186 {
187 TkbCipherOffset_ValueChanged(sender, e);
188 {
189 // Template for Lab 6.1 and Lab 6.2
190 // This event handler is used to convert the original text to

cipher text by offsetting the
191 // original text characters by the offset value
192
19 public void TkbCipherOffset_ValueChanged(object sender, EventArgs e)
194 {
195
// Change the offset value label when the offset value is changed on

track bar
197 lblTrackbarValue.Text = tkbCipherOffset.Value.ToString();
198 // Trim the text of any blanks
OriginalText = tbxOriginalText.Text.ToString().Trim();
200 CipherText = "";

// Initialize the cipher text string
201
202 // Loop through the original text string one character at a time
203 for (int index = 0; index < OriginalText.Length; index++)
204 {
205 // convert only between A and Z.
206 if ((OriginalText[index] >= 'A') && (OriginalText[index] <= 'Z'))
207 {
208 int intval = (char)OriginalText[index];
209 intval = intval + tkbCipherOffset.Value;
210 intval = (intval - Convert.ToInt16('A')) % 26;
211 intval = intval + Convert.ToInt16('A');
212 CipherText = CipherText + Convert.ToChar(intval);
213 }
214 else
215 CipherText = CipherText + OriginalText[index];
216 }
217 }
218
219 tbxCipherText.Text = CipherText;

// Assign the encryptedtext to the text box string
220 tbxCipherText.SelectionStart = tbxCipherText.TextLength;

// set cursor to the last charcter of Cipher text box
221 tbxCipherText.ScrollToCaret();

// Scroll the text box to the last positio
222
223
224 }
225
226 }
227
228
229 }
230
231 }
232
233
234 }
235 }