Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 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.  
  10. namespace QuickEncryptTHIS
  11. {
  12. public partial class Form1 : Form
  13. {
  14. //Class wide shit
  15. public StringBuilder stringBuilder = new StringBuilder();
  16. string transfer = string.Empty;
  17.  
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. //THE BUTTONS
  24. private void button1_Click(object sender, EventArgs e)
  25. {
  26. EncryptData();
  27. }
  28.  
  29. private void button2_Click(object sender, EventArgs e)
  30. {
  31. ExitProgram();
  32. }
  33.  
  34. private void exitFileToolStripMenuItem_Click(object sender, EventArgs e)
  35. {
  36. ExitProgram();
  37. }
  38.  
  39. void ExitProgram()
  40. {
  41. Application.Exit();
  42. }
  43.  
  44.  
  45. void EncryptData()
  46. {
  47. //THE KEY
  48. byte[] keyArray = new byte[3];
  49.  
  50. new Random().NextBytes(keyArray); //used to fill an array with a random bytes, until the array is completely full
  51. int keyIndexSize = 0; //Counter for overflow prevention
  52. txtOutput.Clear();
  53.  
  54. //FILE ACCESS
  55. OpenFileDialog opn = new OpenFileDialog();
  56.  
  57. if (opn.ShowDialog() != DialogResult.OK)
  58. {
  59. return;
  60. }
  61. else
  62. {
  63. txtOutput.Text = "Encryption Started...";
  64. }
  65. byte[] fileBytes = File.ReadAllBytes(opn.FileName);//used for getting the file's bytes
  66. opn.FileName = null;
  67.  
  68.  
  69. //THE ENCRYPTION
  70. for (int i = 0; i < fileBytes.Length; i++)
  71. {
  72. byte enc = fileBytes[i];
  73. enc ^= keyArray[keyIndexSize];
  74. keyIndexSize++;
  75. if (keyIndexSize > (keyArray.Length - 1))
  76. {
  77. keyIndexSize = 0;
  78. }
  79. stringBuilder.Append((char)enc);
  80. }
  81. OutputWriter();
  82.  
  83. }
  84.  
  85. public void OutputWriter()
  86. {
  87. txtOutput.Text += "\r\n" + "Encryption Completed";
  88. txtOutput.Text += "\r\n" + "Your encrypted Output" + "\r\n" + stringBuilder.ToString();
  89. }
  90.  
  91.  
  92. }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement