User:RavynousHunter/GEP/Source/1.1

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO;

namespace GEP_1._1 {   public partial class Form1 : Form {       public Form1 {           InitializeComponent; }

private void mnuAbout_Click(object sender, EventArgs e)       { string dialog;

dialog = "GEP v1.1\n"; dialog += "======\n"; dialog += "by RavynousHunter\n\n"; dialog += "Generic Encryption Program (GEP) provides an\n"; dialog += "easy-to-use, simple GUI for the encryption and\n"; dialog += "decryption of various files.\n\n"; dialog += "Please note that all encrypted files are saved\n"; dialog += "with a *.RH0 extension.\n\n"; dialog += "Report any problems, questions, or suggestions\n to this page:\n"; dialog += "guildwars.wikia.com/wiki/User_talk:RavynousHunter/GEP";

MessageBox.Show(dialog, "Generic Encryption Program (GEP) v1.1"); }

private void cmdEncOpen_Click(object sender, EventArgs e)       { txtEncIn.Text = OpenFileEnc("C:\\"); }

public string OpenFileEnc(string initialDirectory) {           OpenFileDialog ofd = new OpenFileDialog; ofd.Filter = "All Files (*.*)|*.*"; ofd.InitialDirectory = initialDirectory; ofd.Title = "Select a file to encrypt"; return (ofd.ShowDialog == DialogResult.OK) ? ofd.FileName : null; }

public string OpenFileDec(string initialDirectory) {           OpenFileDialog ofd = new OpenFileDialog; ofd.Filter = "RH0 Files (*.RH0)|*.RH0"; ofd.InitialDirectory = initialDirectory; ofd.Title = "Select a *.RH0 file to decrypt"; return (ofd.ShowDialog == DialogResult.OK) ? ofd.FileName : null; }

public string OpenDirectory {           FolderBrowserDialog fbd = new FolderBrowserDialog; return (fbd.ShowDialog == DialogResult.OK) ? fbd.SelectedPath : null; }

private void cmdDecOpen_Click(object sender, EventArgs e)       { txtDecIn.Text = OpenFileDec("C:\\"); }

private void cmdEncrypt_Click(object sender, EventArgs e)       { lblEncStatus.Text = "Generating input stream..."; FileStream in_stream = new FileStream(txtEncIn.Text, FileMode.Open); lblEncStatus.Text = "Success! Generating output destination..."; string out_dest = txtEncDest.Text + txtEncFilename.Text + ".RH0"; lblEncStatus.Text = "Success! Generating output stream..."; FileStream out_stream = new FileStream(out_dest, FileMode.OpenOrCreate | FileMode.Append); lblEncStatus.Text = "Success! Generating encrypted file...";

byte in_byte; int xor_byte = 0x80; // 128

for (int i = 0; i < in_stream.Length; i++) {               in_byte  = Convert.ToByte(in_stream.ReadByte); byte xor = Convert.ToByte(in_byte ^ Convert.ToByte(xor_byte));

out_stream.WriteByte(xor); }           lblEncStatus.Text = "Success! Closing file streams...";

in_stream.Close; out_stream.Close;

lblEncStatus.Text = "Success! Your file has been encrypted!"; }

private void cmdEncOpenDest_Click(object sender, EventArgs e)       { txtEncDest.Text = OpenDirectory; }

private void cmdDecrypt_Click(object sender, EventArgs e)       { lblDecStatus.Text    = "Generating input file stream..."; FileStream in_stream = new FileStream(txtDecIn.Text, FileMode.Open); lblDecStatus.Text    = "Success! Generating output destination..."; string out_dest      = txtDecDest.Text + txtDecFilename.Text; lblDecStatus.Text    = "Success! Generating output file stream..."; FileStream out_stream = new FileStream(out_dest, FileMode.OpenOrCreate | FileMode.Append); lblDecStatus.Text    = "Success! Generating decrypted file...";

byte in_byte; int xor_byte = 0x80; // 128

for (int i = 0; i < in_stream.Length; i++) {               in_byte  = Convert.ToByte(in_stream.ReadByte); byte xor = Convert.ToByte(in_byte ^ Convert.ToByte(xor_byte));

out_stream.WriteByte(xor); }           lblDecStatus.Text = "Success! Closing file streams...";

in_stream.Close; out_stream.Close;

lblDecStatus.Text = "Success! Your file has been decrypted!"; }

private void cmdDecOpenDest_Click(object sender, EventArgs e)       { txtDecDest.Text = OpenDirectory; }   } }