Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static string EncryptDecrypt(string textToEncrypt, int encryptionKey)
- {
- StringBuilder inSb = new StringBuilder(textToEncrypt);
- StringBuilder outSb = new StringBuilder(textToEncrypt.Length);
- char c;
- for (int i = 0; i < textToEncrypt.Length; i++)
- {
- c = inSb[i];
- c = (char)(c ^ encryptionKey);
- outSb.Append(c);
- }
- return outSb.ToString();
- }
- static void Main(string[] args)
- {
- ArrayList openArray = new ArrayList();
- ArrayList closeArray = new ArrayList();
- Console.WriteLine("+----------------------+");
- Console.WriteLine("+ ------------------ +");
- Console.WriteLine("+ Encryption Program +");
- Console.WriteLine("+ ------------------ +");
- Console.WriteLine("+----------------------+");
- Console.WriteLine("");
- Console.WriteLine("");
- Console.WriteLine("Enter the path of the file to be encrypted/decrypted...");
- string beginPath = Console.ReadLine();
- Console.WriteLine("Enter the path of the output file.");
- string endPath = Console.ReadLine();
- Console.WriteLine("Enter a encryption key. No letters or special characters, only numbers.");
- int enKey = Convert.ToInt32(Console.ReadLine());
- using (FileStream fs = new FileStream(beginPath, FileMode.Open, FileAccess.Read))
- {
- using (StreamReader sr = new StreamReader(fs))
- {
- while (!sr.EndOfStream)
- {
- openArray.Add(sr.ReadLine());
- }
- sr.Close();
- }
- fs.Close();
- }
- foreach (string line2 in openArray)
- {
- closeArray.Add(EncryptDecrypt(line2, enKey));
- }
- TextWriter tw = new StreamWriter(endPath);
- foreach (string encoded in closeArray)
- {
- tw.WriteLine(encoded);
- }
- tw.Close();
- Console.WriteLine("Encoding finished.");
- Console.WriteLine("Opening output file now...");
- Process.Start("notepad.exe",endPath);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement