Advertisement
Guest User

Чщк

a guest
Jan 12th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.82 KB | None | 0 0
  1.         private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             Stream input = null;
  4.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  5.             {
  6.                 if ((input = openFileDialog1.OpenFile()) != null)
  7.                 {
  8.                     int p = 0;
  9.                     byte[] mass = File.ReadAllBytes(openFileDialog1.FileName);
  10.                     string rass = openFileDialog1.FileName.Substring(openFileDialog1.FileName.Length - 3);
  11.                     byte[] rasb = encode.GetBytes(rass);
  12.                     byte[] key = encode.GetBytes(textBox1.Text);
  13.                     byte[] fullkey = new byte[mass.Length];
  14.                     for (int i = 0; i < fullkey.Length; i++)
  15.                     {
  16.                         fullkey[i] = key[p];
  17.                         p++;
  18.                         if (p == key.Length)
  19.                             p = 0;
  20.                     }
  21.                     for (int i = 0; i < fullkey.Length; i++)
  22.                     {
  23.                         mass[i] = (byte)(mass[i] ^ fullkey[i]);
  24.                     }
  25.                     byte[] exemass = File.ReadAllBytes(Application.ExecutablePath);
  26.                     byte[] final = new byte[exemass.Length + mass.Length+3];
  27.                     for (int i = 0; i < exemass.Length; i++)
  28.                     {
  29.                         final[i] = exemass[i];
  30.                     }
  31.                     int k=0;
  32.                     for (int j = exemass.Length; j < exemass.Length + mass.Length; j++)
  33.                     {
  34.                         final[j] = mass[k];
  35.                         k++;
  36.                     }
  37.                     int l = 0;
  38.                     for (int m = exemass.Length + mass.Length; m < exemass.Length + mass.Length + 3; m++)
  39.                     {
  40.                         final[m] = rasb[l];
  41.                         l++;
  42.                     }
  43.                     File.WriteAllBytes(Application.StartupPath + "/Crypted.exe", final);
  44.                     MessageBox.Show("Success!");
  45.                 }                
  46.             }
  47.         }
  48.  
  49.         private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  50.         {
  51.             if (!Char.IsDigit(e.KeyChar))
  52.             {
  53.                 e.Handled = true;
  54.             }
  55.             button1.Enabled = true;
  56.             byte[] exemass = File.ReadAllBytes(Application.ExecutablePath);
  57.             if (exemass.Length > 11264)
  58.                 button2.Enabled = true;
  59.         }
  60.  
  61.         private void button2_Click(object sender, EventArgs e)
  62.         {
  63.             byte[] cryptedexe = File.ReadAllBytes(Application.ExecutablePath);
  64.             byte[] dividedfile = new byte[cryptedexe.Length - 11267];
  65.             byte[] rasb = new byte[3];
  66.             int h=0;
  67.             int p = 0;
  68.             int g = 0;
  69.             for (int i = 11264; i < cryptedexe.Length; i++)
  70.             {
  71.                 if (i < (cryptedexe.Length - 3))
  72.                 {
  73.                     dividedfile[h] = cryptedexe[i];
  74.                     h++;
  75.                 }
  76.                 else
  77.                 {
  78.                     rasb[g] = cryptedexe[i];
  79.                     g++;
  80.                 }
  81.             }
  82.             string rass = encode.GetString(rasb);
  83.             byte[] key = encode.GetBytes(textBox1.Text);
  84.             byte[] fullkey = new byte[dividedfile.Length];
  85.             for (int i = 0; i < fullkey.Length; i++)
  86.             {
  87.                 fullkey[i] = key[p];
  88.                 p++;
  89.                 if (p == key.Length)
  90.                     p = 0;
  91.             }
  92.             for (int i = 0; i < fullkey.Length; i++)
  93.             {
  94.                 dividedfile[i] = (byte)(dividedfile[i] ^ fullkey[i]);
  95.             }
  96.             File.WriteAllBytes(Application.StartupPath + "/decrypted."+rass, dividedfile);
  97.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement