Advertisement
Guest User

Untitled

a guest
May 1st, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Numerics;
  8. using System.Text;
  9.  
  10.  
  11. class Program
  12. {
  13.     public static string Decrypt(List<int> encrypted, string pass)
  14.     {
  15.         //assume pass.Length == 3
  16.         int currentPos = 0;
  17.  
  18.         List<int> decrypted = new List<int>();
  19.  
  20.         foreach (int n in encrypted)
  21.         {
  22.             decrypted.Add(n ^ (int)pass[currentPos]);
  23.  
  24.             currentPos++;
  25.             if (currentPos == 3)
  26.             {
  27.                 currentPos = 2;
  28.             }
  29.         }
  30.  
  31.         string s = "";
  32.         foreach (int n in decrypted)
  33.         {
  34.             s += (char)n;
  35.         }
  36.  
  37.         return s;
  38.     }
  39.  
  40.     [STAThread()]
  41.     public static void Main(string[] args)
  42.     {
  43.         string path = @"C:\Users\owner\Documents\Quick Access\cipher1.txt";
  44.         string data = "";
  45.         using (StreamReader sr = new StreamReader(path))
  46.         {
  47.             data = sr.ReadToEnd();
  48.         }
  49.  
  50.         List<int> encryptedNums = new List<int>();
  51.  
  52.         foreach (string s in data.Split(','))
  53.         {
  54.             encryptedNums.Add(Convert.ToInt32(s));
  55.         }
  56.  
  57.         string encryptedString = "";
  58.  
  59.         //WTF????
  60.         foreach (int n in encryptedNums)
  61.         {
  62.             try
  63.             {
  64.                 encryptedString += (char)n;
  65.             }
  66.             catch (Exception)
  67.             {
  68.                 Console.WriteLine(n);
  69.                 Console.ReadKey();
  70.             }
  71.         }
  72.  
  73.         string newPath = @"C:\Users\owner\Documents\Quick Access\cipher2.txt";
  74.  
  75.         for (char x = 'a'; x <= 'z'; x++)
  76.         {
  77.             for (char y = 'a'; y <= 'z'; y++)
  78.             {
  79.                 for (char z = 'a'; z <= 'z'; z++)
  80.                 {
  81.                     string pass = x + "" + y + "" + z;
  82.                     string decrypted = Decrypt(encryptedNums, pass);
  83.  
  84.                     Console.WriteLine("----PASS----");
  85.                     Console.WriteLine(pass);
  86.                     Console.WriteLine();
  87.                     Console.WriteLine();
  88.                     Console.WriteLine("-----DECRYPTED-----");
  89.                     Console.WriteLine(decrypted);
  90.                     Console.WriteLine();
  91.                     Console.WriteLine();
  92.                     Console.WriteLine("-----ENCRYPTED----");
  93.                     Console.WriteLine(encryptedString);
  94.                     Console.ReadKey();
  95.  
  96.                     using (System.IO.StreamWriter file = new StreamWriter(newPath, true))
  97.                     {
  98.                         file.WriteLine("Decrypted with pass: " + pass + ":\n" + decrypted + "\n\n");
  99.                     }
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement