-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLABprotectProgram2.1.cs
More file actions
31 lines (25 loc) · 890 Bytes
/
LABprotectProgram2.1.cs
File metadata and controls
31 lines (25 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.IO;
using System.Text;
class Program
{
static void Main()
{
Console.WriteLine("Enter the text-->");
string text = Console.ReadLine();
Console.WriteLine("Enter the key-->");
string key = Console.ReadLine();
byte[] textBytes = Encoding.UTF8.GetBytes(text);
byte[] keyBytes = Encoding.UTF8.GetBytes(key);
byte[] encryptedText = new byte[textBytes.Length];
for (int i = 0; i < textBytes.Length; i++)
{
encryptedText[i] = (byte)(textBytes[i] ^ keyBytes[i % keyBytes.Length]);
}
using (FileStream stream = new FileStream("data.dat", FileMode.OpenOrCreate))
{
stream.Write(encryptedText, 0, encryptedText.Length);
}
Console.WriteLine("Text encrypted and written to data.dat.");
}
}