Question

In: Computer Science

You have been tasked to write a C# application that will go through the first step...

You have been tasked to write a C# application that will go through the first step of encrypting an input file and writing the encrypted contents to an output file.

For this first step in encryption, read each letter in from the input file, add 3 letters to the value of the input letter. If the input letter is an A then the encrypted letter would be a D. If the input letter from the input file is an X then the encrypted letter would be an A.
All spaces, digits, punctuation, and special characters do not need to be encrypted at this level.   Simply write the space, punctuation, or special character to the output file as is.
If a letter is uppercase in the input file, it should remain as an uppercase character in the output file. If a letter is lowercase in the input file, it should remain as a lowercase character in the output file.

Since this program runs each month, the input file will be of various lengths; therefore, the program will read until end of file.

The input file is found in the current directory and is named October20.txt.   The output file will be written to the current directory and named EncryptOct20.txt.

An example:

If the contents of the input file is

Live long and prosper.



The output file would be:

Olyh orqj dqg survshu.



What the user should see when the program executes:


When the program begins, the statement "Encryption Level 1" should be displayed.
The focus should be set to the "Begin Encryption" button.
When the user clicks the "Begin Encryption" button, the program opens the input file, the statement "Opening input file...." should be displayed. The "Begin Encryption" button should be disabled.
When the program begins reading through the input file encrypting the contents, the statement "Encrypting input file...." should be displayed.
When the program closes the input and output files, the statement "Encryption complete...." should be displayed.
When the program is complete, the statement "End of process" should be displayed.

Solutions

Expert Solution

· Open "Visual Studio 2019"

· Click on "Create a New Project"

· Click on "Windows Forms App (.NET Framework)" -> Click "Next"

· Enter the Project Name as "Encryption" -> Click on "Create"

· Now the screen will look like this:

· Let's change the Form Title to Encryption

· Click on the Form =>   On the right hand side, Click on "Text" and enter "Encryption " into it

· Go to the Toolbox -> Search for Textbox (Add 4 Textboxes) and Button (Add 1 buttons) to the form

o Align the Textbox and Buttons in the form

o In the Properties box on the right-hand side, Click on the Textbox in the Form and change it's (Name) to txtDisplay. Likewise, change the remaining three Textbox's (Name)'s to , txtOutput1, txtOutput2 and txtOutput3.

o In the Properties box on the right-hand side, Click on the Buttons and change it's (Name) to BtnClickThis and it's Text to Begin Encryption

· For all the Textboxes, select "Read Only" option in the Properties window to True by clicking on the Textbox

· To write the C# code, Right-click on the Form and Click on "View Code" => This will open a Form1.cs file

· The program should do the operation on a Click to the Button. So, Double-Click on the Begin Encryption Button in the Form => A BtnClickThis_Click Function will be added to the Form1.cs file.

· In the Form1.cs, paste the following code,

using System;
using System.IO;
using System.Windows.Forms;
namespace Encrypt
{
    public partial class OutputLabel : Form
    {
        public OutputLabel()
        {
            InitializeComponent();
        }
        private void BtnClickThis_Click(object sender, EventArgs e)
        {
            txtOutput1.Text = "Opening input file...."; 
            BtnClickThis.Enabled = false;
            // If you don't want to open a file using Dialog box, Comment the next 10 lines
            // and uncomment the line after that
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "Text files | *.txt"; // file types, that will be allowed to upload
            dialog.Multiselect = false; // allow/deny user to upload more than one file at a time
            string text = "";
            if (dialog.ShowDialog() == DialogResult.OK) // if user clicked OK
            {
                String path = dialog.FileName; // get name of file
                text = File.ReadAllText(path);
                Console.WriteLine(text);
            }
            //text = File.ReadAllText("October20.txt");
            txtOutput1.Text = "Encrypting input file....";
            String output = "";
            for (int i = 0; i < text.Length; i++)
            {
                if (System.Convert.ToInt32(text[i]) >= 97 && System.Convert.ToInt32(text[i]) <= 122)
                {
                    if (System.Convert.ToInt32(text[i]) == 120)
                    {
                        output += Convert.ToChar(97);
                    }
                    else if (System.Convert.ToInt32(text[i]) == 121)
                    {
                        output += Convert.ToChar(98);
                    }
                    else if (System.Convert.ToInt32(text[i]) == 122)
                    {
                        output += Convert.ToChar(99);
                    }
                    else
                    {
                        output += Convert.ToChar(text[i] + 3);
                    }
                }
                else if (System.Convert.ToInt32(text[i]) >= 65 && System.Convert.ToInt32(text[i]) <= 90)
                {
                    if (System.Convert.ToInt32(text[i]) == 88)
                    {
                        output += Convert.ToChar(65);
                    }
                    else if (System.Convert.ToInt32(text[i]) == 89)
                    {
                        output += Convert.ToChar(66);
                    }
                    else if (System.Convert.ToInt32(text[i]) == 90)
                    {
                        output += Convert.ToChar(67);
                    }
                    else
                    {
                        output += Convert.ToChar(text[i] + 3);
                    }
                }
                else
                {
                    output += text[i];
                }

            }
            string[] WriteText = { output };
            txtOutput2.Text = "Encryption complete....";
            txtOutput1.Text = "";
            string outPath = "E:/EncryptOct20.txt";
            File.WriteAllLines(outPath, WriteText);
            txtOutput3.Text = "End of process";
            txtOutput2.Text = "";
        }
        private void OutputLabel_Load(object sender, EventArgs e)
        {
            // Displays this text on starting the application
            txtDisplay.Text = "Encryption Level 1";
        }
    }
}

OUTPUT:


Related Solutions

Write a C++ program that will use good object-oriented principles. You have been tasked to write...
Write a C++ program that will use good object-oriented principles. You have been tasked to write an application that will allow a user to change their system password. The XYZ Corporation has the following rules for passwords: each password should have a minimum of 8 characters each password should have a minimum of 2 uppercase characters (A - Z) each password should have a minimum of 2 lowercase characters (a - z) each password should have a minimum of 2...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for...
Intro C++ Programming Chapter 6 Functions You have been tasked to write a new program for the Research Center's shipping department. The shipping charges for the center are as follows: Weight of Package (in kilograms)                Rate per mile Shipped 2 kg or less                                                      $0.05 Over 2 kg but no more than 6 kg    $0.09 Over 6 kg but not more than 10 kg    $0.12 Over 10 kg    $0.20 Write a function in a program that asks for...
write a c++ code for following application You have been hired by XYZ Car Rental to...
write a c++ code for following application You have been hired by XYZ Car Rental to develop a software system for their business. Your program will have two unordered lists, one of Cars and one of Reservations. The Car class will have the following data: string plateNumber (this is the key) string make string model enum vehicleType (VehicleType Enumeration of options: sedan, suv, exotic) double pricePerDay bool isAvailable isAvailable should be set to true on initialization, and a public setter...
As the head of the local Criminal Justice Dept. You have been tasked to write changes...
As the head of the local Criminal Justice Dept. You have been tasked to write changes to departmental policy because of a recurring problem involving students failing to appear in class or appearing late in class. The dean has complained to you because he thinks attending class is a low priority for you students. Using cause and effect determine the possible causes for the late and missed classes. List the possible causes under the headings below Machines 1 2 3...
Congratulations! You have been appointed as a new product manager with Samsung and have been tasked...
Congratulations! You have been appointed as a new product manager with Samsung and have been tasked to introduce the latest smartphone in a new country. Choose and research a country other than the United States and India, and then formulate a plan to effectively integrate this product from a global and social standpoint. Speculate on the major challenges and opportunities you anticipate facing in this role. Provide a reference source.
The project description: As a programmer, you have been asked to write a Java application, using...
The project description: As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who...
As a programmer, you have been asked to write a Java application, using OOP concepts, for...
As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who have also a...
The first step in writing a software application is to determine the requirements. There is no...
The first step in writing a software application is to determine the requirements. There is no value in writing a program that does not address the needs of the client. Requirements can be gathered in many ways, but ultimately, the requirements serve to document what the application should and should not do. After the requirements are written, the application design can be prepared, followed by the actual coding. For this project, you will gain some practice in the design phase...
You are the HR manager for a new company and you have been tasked with developing...
You are the HR manager for a new company and you have been tasked with developing a concise employee manual for your new middle managers. This manual must help the managers understand certain HR initiatives so that they can recruit, select, and manager their staff effectively. The manual will consist of explaining and providing guidelines for best practices in the areas below. Explain the importance of a job description and briefly describe the necessary components Describe an effective recruiting process...
You are on a project selection committee and you have been tasked to find the NPV...
You are on a project selection committee and you have been tasked to find the NPV of two potential projects, Project A and Project B. The cash flows and discount rates are as shown below. Project A Year r Cash Flow Year 0 -$8,000 Year 1 5% $5,000 Year 2 5% $5,000 Project B Year r Cash Flow Year 0 -$1,000 Year 1 5% $2,411.90              You find that the NPV of both projects is $1,297. a. Can you make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT