Advertisement
Guest User

Xor application in visual C# 2010

a guest
Jan 7th, 2012
1,236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.Linq;
  5. using System.Text;
  6. using System.IO;
  7. using System.Diagnostics;
  8.  
  9. namespace ConsoleApplication1
  10. {
  11.     class Program
  12.     {
  13.  
  14.  
  15.  
  16.             public static string EncryptDecrypt(string textToEncrypt, int encryptionKey)
  17.             {
  18.                 StringBuilder inSb = new StringBuilder(textToEncrypt);
  19.                 StringBuilder outSb = new StringBuilder(textToEncrypt.Length);
  20.                 char c;
  21.                 for (int i = 0; i < textToEncrypt.Length; i++)
  22.                 {
  23.                     c = inSb[i];
  24.                     c = (char)(c ^ encryptionKey);
  25.                     outSb.Append(c);
  26.                 }
  27.                 return outSb.ToString();
  28.             }
  29.  
  30.  
  31.  
  32.         static void Main(string[] args)
  33.         {
  34.             ArrayList openArray = new ArrayList();
  35.             ArrayList closeArray = new ArrayList();
  36.  
  37.             Console.WriteLine("+----------------------+");
  38.             Console.WriteLine("+  ------------------  +");
  39.             Console.WriteLine("+  Encryption Program  +");
  40.             Console.WriteLine("+  ------------------  +");
  41.             Console.WriteLine("+----------------------+");
  42.             Console.WriteLine("");
  43.             Console.WriteLine("");
  44.             Console.WriteLine("Enter the path of the file to be encrypted/decrypted...");
  45.             string beginPath = Console.ReadLine();
  46.             Console.WriteLine("Enter the path of the output file.");
  47.             string endPath = Console.ReadLine();
  48.             Console.WriteLine("Enter a encryption key. No letters or special characters, only numbers.");
  49.             int enKey = Convert.ToInt32(Console.ReadLine());
  50.  
  51.             using (FileStream fs = new FileStream(beginPath, FileMode.Open, FileAccess.Read))
  52.             {
  53.                 using (StreamReader sr = new StreamReader(fs))
  54.                 {
  55.                     while (!sr.EndOfStream)
  56.                     {
  57.                         openArray.Add(sr.ReadLine());
  58.                     }
  59.                     sr.Close();
  60.                 }
  61.                 fs.Close();
  62.  
  63.             }
  64.            
  65.             foreach (string line2 in openArray)
  66.             {
  67.                 closeArray.Add(EncryptDecrypt(line2, enKey));
  68.             }
  69.  
  70.             TextWriter tw = new StreamWriter(endPath);
  71.  
  72.             foreach (string encoded in closeArray)
  73.             {
  74.                 tw.WriteLine(encoded);
  75.             }
  76.  
  77.             tw.Close();
  78.  
  79.             Console.WriteLine("Encoding finished.");
  80.             Console.WriteLine("Opening output file now...");
  81.             Process.Start("notepad.exe",endPath);
  82.  
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement