Komak57

Untitled

Jun 13th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Threading;
  5.  
  6. class keyEncrypt
  7. {
  8.     static void Main(string[] args)
  9.     {
  10.         string pass = "";
  11.         if (args.Length == 1) {
  12.             // argument is the password requesting encryption
  13.             pass = args[0];
  14.         } else {
  15.             // ask for password for encryption
  16.             Console.WriteLine("Password to encrypt:");
  17.             pass = Console.ReadLine();
  18.         }
  19.         Console.WriteLine("Encrypting...");
  20.        
  21.         // encrypt all with simple K power encrypition
  22.         string spass = "";
  23.         foreach(char c in pass)
  24.             spass += (c ^ 'K');
  25.        
  26.         // siphon string of numbers by sets of 2 into bytes
  27.         double a = spass.Length/2.0;
  28.         double len = Math.Ceiling(a);
  29.         List<byte> npass = new List<byte>();
  30.         for (int i = 0; i < len; i++)
  31.         {
  32.             try {
  33.                 npass.Add((byte)Convert.ToInt32(spass.Substring(i, 2)));
  34.             } catch {
  35.                 // assume we bugged because we're asking for a length that cannot be used
  36.                 npass.Add((byte)Convert.ToInt32(spass.Substring(i, 1)));
  37.             }          
  38.         }
  39.         byte[] buf = npass
  40.             .ToArray();
  41.         // convert to string
  42.         string newpass = System.Text.Encoding.UTF8.GetString(buf);
  43.        
  44.         // debug outputs
  45.         Console.WriteLine("- Length of Password: "+pass.Length);
  46.         Console.WriteLine("- Length of encryption: "+spass.Length);
  47.         Console.WriteLine("- a: "+a+", len: "+len);
  48.         Console.WriteLine("- Length of list: "+npass.Count);
  49.         Console.WriteLine("- Length of array: "+buf.Length);
  50.        
  51.         Console.WriteLine("Password: '"+newpass+"'");
  52.         Console.WriteLine("Goodbye! -Komak57");
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment