- Course
- Text Files B
- Encrypt a text file
Encrypt a text file
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a C# program that makes a copy of a text file but encrypted.
Add the characters of each letter 13 times to encrypt the contents of the text file.
Input
Output
Solution
using System.IO;
public class FileEncrypter
{
public static void Main(string[] args)
{
string inputFileName = "input.txt";
string outputFileName = "output.txt";
string contents = File.ReadAllText(inputFileName);
string cipher = string.Empty;
byte key = 13;
foreach (char letter in contents)
{
cipher += (char)(letter + key);
}
File.WriteAllText(outputFileName, cipher);
}
}