Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- using System.Linq;
- using System.Threading;
- namespace QuickEncryptTHIS
- {
- public partial class Form1 : Form
- {
- //Class wide shit
- public StringBuilder stringBuilder = new StringBuilder();
- string transfer = string.Empty;
- public Form1()
- {
- InitializeComponent();
- }
- //THE BUTTONS
- private void button1_Click(object sender, EventArgs e)
- {
- EncryptData();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- ExitProgram();
- }
- private void exitFileToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ExitProgram();
- }
- void ExitProgram()
- {
- Application.Exit();
- }
- void EncryptData()
- {
- //THE KEY
- byte[] keyArray = new byte[3];
- new Random().NextBytes(keyArray); //used to fill an array with a random bytes, until the array is completely full
- int keyIndexSize = 0; //Counter for overflow prevention
- txtOutput.Clear();
- //FILE ACCESS
- OpenFileDialog opn = new OpenFileDialog();
- if (opn.ShowDialog() != DialogResult.OK)
- {
- return;
- }
- else
- {
- txtOutput.Text = "Encryption Started...";
- }
- byte[] fileBytes = File.ReadAllBytes(opn.FileName);//used for getting the file's bytes
- opn.FileName = null;
- //THE ENCRYPTION
- for (int i = 0; i < fileBytes.Length; i++)
- {
- byte enc = fileBytes[i];
- enc ^= keyArray[keyIndexSize];
- keyIndexSize++;
- if (keyIndexSize > (keyArray.Length - 1))
- {
- keyIndexSize = 0;
- }
- stringBuilder.Append((char)enc);
- }
- OutputWriter();
- }
- public void OutputWriter()
- {
- txtOutput.Text += "\r\n" + "Encryption Completed";
- txtOutput.Text += "\r\n" + "Your encrypted Output" + "\r\n" + stringBuilder.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement