Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Threading;
  9. using System.Security.Cryptography;
  10.  
  11. namespace QuickEncryptTHIS
  12. {
  13. public static partial class Form1 : Form
  14. {
  15. //Class wide shit
  16. public StringBuilder stringBuilder = new StringBuilder();
  17. string transfer = string.Empty;
  18. RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
  19.  
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. }
  24.  
  25. //THE BUTTONS
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. EncryptData();
  29. }
  30.  
  31. private void button2_Click(object sender, EventArgs e)
  32. {
  33. ExitProgram();
  34. }
  35.  
  36. private void exitFileToolStripMenuItem_Click(object sender, EventArgs e)
  37. {
  38. ExitProgram();
  39. }
  40.  
  41. private void button3_Click(object sender, EventArgs e)
  42. {
  43. SaveFileDialog sve = new SaveFileDialog();
  44. if (sve.ShowDialog() != DialogResult.OK)
  45. {
  46. txtOutput.Text += Environment.NewLine + "You stupid two pump chump, you fucked something up";
  47. }
  48. }
  49.  
  50. void ExitProgram()
  51. {
  52. Application.Exit();
  53. }
  54.  
  55.  
  56. private void EncryptData()
  57. {
  58. //THE KEY
  59. byte[] keyArray = new byte[512];
  60.  
  61. rand.GetBytes(keyArray); //used to fill an array with a random bytes, until the array is completely full
  62. int keyIndexSize = 0; //Counter for overflow prevention
  63. txtOutput.Clear();
  64. stringBuilder.Clear();
  65.  
  66. //FILE ACCESS
  67. OpenFileDialog opn = new OpenFileDialog();
  68.  
  69. if (opn.ShowDialog() != DialogResult.OK)
  70. {
  71. return;
  72. }
  73. else
  74. {
  75. txtOutput.Text = "Encryption Started...";
  76. }
  77. byte[] fileBytes = File.ReadAllBytes(opn.FileName);//used for getting the file's bytes
  78. opn.FileName = null;
  79.  
  80.  
  81. //THE ENCRYPTION
  82. for (int i = 0; i < fileBytes.Length; i++)
  83. {
  84. fileBytes[i] ^= keyArray[keyIndexSize];
  85. keyIndexSize++;
  86. if (keyIndexSize > (keyArray.Length - 1))
  87. {
  88. keyIndexSize = 0;
  89. }
  90. }
  91. stringBuilder.Append(Encoding.ASCII.GetString(fileBytes));//TODO: Handle larger files...
  92. OutputWriter();
  93.  
  94. }
  95.  
  96. public void OutputWriter()
  97. {
  98. txtOutput.Text += "\r\n" + "Encryption Completed!";
  99. txtOutput.Text += "\r\n" + "Your encrypted Output" + "\r\n\r\n" + stringBuilder.ToString();
  100. }
  101.  
  102.  
  103.  
  104.  
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement