I need it to run on Visual Studio please need the whole code

I need it to run on Visual Studio please need the whole code.

Write a program that reads and encrypts a text file. Encryption is the science of hiding the contents of the file from users that are not allowed to read its contents.

- Your program will first read the data from a text file called data.txt and save the information in an array of strings. The first line of the text file has an integer value that indicates the number of lines in the text file. This number will allow you to create a dynamic array of the correct number of strings, where each element in the array of strings will hold a single line of text.

- After the data is read and saved in the array, the next step is to encrypt the data. Modify the contents of the array by encrypting its contents one element at a time. A very simple way of encrypting data is going through a string one character at a time, and adding 7 to the ASCII code of the character.

- After you are done with the text encryption, write the contents of the array in reverse order to a text file called encrypted.txt.

For example, let us assume that the content of is the following:

2

CMPSC 122: Intermediate Programming

This is an example of encrypting text.

The integer value 2 in the first line indicates that the file is composed of two lines of strings. You will then create a dynamic array of two strings where the first element of the array will hold the following string “CMPSC 122: Intermediate Programming” while the second element will hold “This is an example of encrypting text.” The next step is to encrypt the contents of the array and save it in a file called encrypted.txt. The contents of the file should now look like:

[opz\'pz\'hu\'lhtwsl\'vm\'lujy€w{pun\'{l{5 JTWZJ\'899A\'Pu{lytlkph{l\'Wyvnyhttpun

Where the first encrypted line refers to “This is an example of encrypting text.” In addition to the main function, your program should have the following functions:

- A function that reads the input from the text file (data.txt) and saves it in an array

- A function that encrypts the contents of the array of strings

- A function that saves the encrypted data to the output file (encrypted.txt)

Solution

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace RND2
{
class Program
{

public string[] ReadandSave()
{
int i = 0;
// read first line from data.txt ,It will give number of line
string line1 = File.ReadLines(@\"G:\\data.txt\").First(); // please provide correct path for your data.txt
// first line give no of line so this must be converted to integer value
int size = Convert.ToInt32(line1);
// size give size of dyanmic array
string[] stringLines = new string[size];
// Read each line of the file into a string array. Each element
// of the array is one line of the file.
string[] Lines = File.ReadAllLines(@\"G:\\data.txt\");

// below foreach loop copy from 2 nd lline to dyanamic array stringLines
foreach (string Line in Lines)
{
if (Line != size.ToString())
{
stringLines[i] = Line;
i++;
}

}
// here is lines form your data.txt
Console.Write(\" here is lines form your data.txt\");
foreach (string Line in stringLines)
{

Console.WriteLine(Line);
}
return stringLines;

}
// function for encrypts array
public string[] encrypts( string[] array)
{
for (int i = 0; i <= array.Length-1; i++)
{
char[] arr = array[i].ToCharArray();

for (int j = 0; j < arr.Length; j++)
{
arr[j] = (char)(7 + (int)arr[j]);

}
array[i] = new string(arr);
}

return array;
}
public void Saveencryptingtext(string[] arrayencrypts)
{

string[] reverse = new string[arrayencrypts.Length];

int j = 0;

for (int i = arrayencrypts.Length - 1; i >= 0; i--)
{
reverse[j] = arrayencrypts[i];
j++;
}
System.IO.File.WriteAllLines(@\"G:\\encryptingtext.txt\", reverse); // please provide correct path for your encryptingtext.txt
// here is lines form your encrypting text .txt
Console.WriteLine( \"here is lines form your encrypting text .txt----\");
  
foreach (string Line in reverse)
{

Console.WriteLine(Line);
}
}
static void Main(string[] args)
{

// object of class program
Program obj = new Program();
// calling read and save method to read data from data.txt and save to strind array
string[] StringArray= obj.ReadandSave();
// calling encrypts function to encrypt stringarray
string[] encryptsArray= obj.encrypts(StringArray);
// calling Saveencryptingtext function to save encrypt stringarray to encryptingtext.txt file
obj.Saveencryptingtext(encryptsArray);

Console.WriteLine(\"your data is save to encrypt test file in ecrypt form press any key \");

System.Console.ReadKey();
}
}
}

I need it to run on Visual Studio please need the whole code. Write a program that reads and encrypts a text file. Encryption is the science of hiding the conte
I need it to run on Visual Studio please need the whole code. Write a program that reads and encrypts a text file. Encryption is the science of hiding the conte
I need it to run on Visual Studio please need the whole code. Write a program that reads and encrypts a text file. Encryption is the science of hiding the conte

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site