LISTING PROGRAM
Kode Program frmUtama.cs
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;
namespace EnkDekGUI {
public partial class frmUtama : Form {
public frmUtama() {
InitializeComponent(); }
private void kompToolStripMenuItem_Click(object sender, EventArgs e) {
frmKompresi komp = new frmKompresi(); komp.ShowDialog();
}
private void dekompresiToolStripMenuItem_Click(object sender, EventArgs e) {
frmDekompresi komp = new frmDekompresi(); komp.ShowDialog();
}
private void enkripsiToolStripMenuItem1_Click(object sender, EventArgs e) {
enk.ShowDialog(); }
private void dekripsiToolStripMenuItem_Click(object sender, EventArgs e) {
frmDekripsi dek = new frmDekripsi(); dek.ShowDialog();
}
private void tentangToolStripMenuItem_Click(object sender, EventArgs e) {
frmTentang ttg = new frmTentang(); ttg.ShowDialog();
} } }
Kode Program frmUtama.Designer.cs
namespace EnkDekGUI {
partial class frmUtama {
/// <summary>
/// Required designer variable. /// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used. /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose(); }
}v
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary>
private void InitializeComponent() {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmUtama));
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.enkripsiToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.enkripsiToolStripMenuItem1 = new
System.Windows.Forms.ToolStripMenuItem();
this.dekripsiToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.kompresiToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.kompToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dekompresiToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.tentangToolStripMenuItem = new
System.Windows.Forms.ToolStripMenuItem();
this.label8 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout();
//
// menuStrip1 //
this.kompresiToolStripMenuItem, this.tentangToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(689, 24); this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1"; //
// enkripsiToolStripMenuItem //
this.enkripsiToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.enkripsiToolStripMenuItem1, this.dekripsiToolStripMenuItem});
this.enkripsiToolStripMenuItem.Name = "enkripsiToolStripMenuItem"; this.enkripsiToolStripMenuItem.Size = new System.Drawing.Size(75, 20); this.enkripsiToolStripMenuItem.Text = "Kriptografi";
//
// enkripsiToolStripMenuItem1 //
this.enkripsiToolStripMenuItem1.Name = "enkripsiToolStripMenuItem1"; this.enkripsiToolStripMenuItem1.Size = new System.Drawing.Size(116, 22); this.enkripsiToolStripMenuItem1.Text = "Enkripsi";
this.enkripsiToolStripMenuItem1.Click += new
System.EventHandler(this.enkripsiToolStripMenuItem1_Click); //
// dekripsiToolStripMenuItem //
this.dekripsiToolStripMenuItem.Name = "dekripsiToolStripMenuItem"; this.dekripsiToolStripMenuItem.Size = new System.Drawing.Size(116, 22); this.dekripsiToolStripMenuItem.Text = "Dekripsi";
this.dekripsiToolStripMenuItem.Click += new
System.EventHandler(this.dekripsiToolStripMenuItem_Click); //
// kompresiToolStripMenuItem //
this.kompresiToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.kompToolStripMenuItem,
this.dekompresiToolStripMenuItem});
this.kompresiToolStripMenuItem.Text = "Kompresi"; //
// kompToolStripMenuItem //
this.kompToolStripMenuItem.Name = "kompToolStripMenuItem";
this.kompToolStripMenuItem.Size = new System.Drawing.Size(137, 22); this.kompToolStripMenuItem.Text = "Kompresi";
this.kompToolStripMenuItem.Click += new
System.EventHandler(this.kompToolStripMenuItem_Click); //
// dekompresiToolStripMenuItem //
this.dekompresiToolStripMenuItem.Name = "dekompresiToolStripMenuItem"; this.dekompresiToolStripMenuItem.Size = new System.Drawing.Size(137, 22); this.dekompresiToolStripMenuItem.Text = "Dekompresi";
this.dekompresiToolStripMenuItem.Click += new
System.EventHandler(this.dekompresiToolStripMenuItem_Click); //
// tentangToolStripMenuItem //
this.tentangToolStripMenuItem.Name = "tentangToolStripMenuItem"; this.tentangToolStripMenuItem.Size = new System.Drawing.Size(63, 20); this.tentangToolStripMenuItem.Text = "Tentang";
this.tentangToolStripMenuItem.Click += new
System.EventHandler(this.tentangToolStripMenuItem_Click); //
// label8 //
this.label8.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label8.Location = new System.Drawing.Point(79, 379); this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(530, 22); this.label8.TabIndex = 22;
this.label8.Text = "2015";
this.label8.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
// label7 //
this.label7.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(530, 22); this.label7.TabIndex = 21;
this.label7.Text = "MEDAN";
this.label7.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
// label6 //
this.label6.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label6.Location = new System.Drawing.Point(79, 335); this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(530, 22); this.label6.TabIndex = 20;
this.label6.Text = "UNIVERSITAS SUMATERA UTARA";
this.label6.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
// label5 //
this.label5.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label5.Location = new System.Drawing.Point(79, 313); this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(530, 22); this.label5.TabIndex = 19;
this.label5.Text = "FAKULTAS ILMU KOMPUTER DAN TEKNOLOGI INFORMASI"; this.label5.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
// label4 //
this.label4.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(123, 291); this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(442, 22); this.label4.TabIndex = 18;
this.label4.Text = "PROGRAM STUDI EKSTENSI S1 ILMU KOMPUTER"; this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(18, 40); this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(653, 62); this.label1.TabIndex = 17;
this.label1.Text = "PERANCANGAN PERANGKAT LUNAK PENGAMANAN FILE TEXT MENGGUNAKAN ALGORITMA EL GAMAL D" +
"AN KOMPRESI FILE TEXT MENGGUNAKAN ALGORITMA HUFFMAN\r\n"; this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter; //
// pictureBox1 //
this.pictureBox1.Image =
((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(263, 116); this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(163, 163);
this.pictureBox1.SizeMode =
System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.pictureBox1.TabIndex = 16;
this.pictureBox1.TabStop = false; //
// frmUtama //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(689, 409); this.Controls.Add(this.label8);
this.Controls.Add(this.label7); this.Controls.Add(this.label6); this.Controls.Add(this.label5); this.Controls.Add(this.label4); this.Controls.Add(this.label1); this.Controls.Add(this.pictureBox1); this.Controls.Add(this.menuStrip1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MainMenuStrip = this.menuStrip1;
this.MaximizeBox = false; this.Name = "frmUtama";
this.Text = "Enkripsi Menggunakan El Gamal dan Kompresi Menggunakan Huffman";
this.Load += new System.EventHandler(this.frmUtama_Load); this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem enkripsiToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem kompresiToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem enkripsiToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem dekripsiToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem kompToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem dekompresiToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem tentangToolStripMenuItem; private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label1;
private System.Windows.Forms.PictureBox pictureBox1; }
}
Kode Program frmEnkripsi.cs
using System;
using System.Drawing; using System.Linq; using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word; using System.IO;
using System.Numerics; using System.Diagnostics; using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace EnkDekGUI {
public partial class frmEnkripsi : Form {
//bilangan
public frmEnkripsi() {
stirng InitializeComponent(a); }
List<string> listk = new List<string>();
//fungsi tombol browse file
private void btnBrowseInput_Click(object sender, EventArgs e) {
//deklarasi variabel result: dialog = dialog buka file DialogResult result = openFileDialog1.ShowDialog(); //jika result = OK
if (result == DialogResult.OK) {
//textbox txtfile = namafile
txtFile.Text = openFileDialog1.FileName; //kosongkan textbox txtread
txtRead.Text = "";
//deklarasi formatfile:string = ekstensi dari namafile
string formatfile = Path.GetExtension(@txtFile.Text).Replace(".","");
//jika txt
if (txtFile.Text != ""){
if (formatfile == "txt") { listk.Add("1");
}else if (formatfile == "docx") { listk.Add("2");
}else if(formatfile == "doc") { listk.Add("3");
}
using (FileStream fsInput = new FileStream(@txtFile.Text, FileMode.Open))
{
int data2;
while ((data2 = fsInput.ReadByte()) != -1) {
txtRead.AppendText(data2.ToString()); if (data2 == 0) {
data2 = 256; }
listk.Add(data2.ToString());
} } }
//jika tidak ada
else //textbox txtread dikosongkan txtRead.Text = "";
//label lblpanjanginput = panjang karakter dari textbox read lblPanjangInput.Text = txtRead.Text.Length.ToString(); }
}
//fungsi tombol simpan hasil enkripsi
private void button2_Click(object sender, EventArgs e) {
//coba lakukan try
{
//deklarasi variabel result: dialog = dialog simpan file DialogResult result = saveFileDialog1.ShowDialog(); //jika result = OK
{
//simpan textbox hasil menjadi filename
File.WriteAllText(@saveFileDialog1.FileName, txtHasil.Text); //tampilkan pesan berhasil
MessageBox.Show("File berhasil disimpan!"); }
}
//jika terdapat error catch (Exception err) {
//tampilkan pesan error
MessageBox.Show(err.Message.ToString(), "Error"); }
}
//fungsi tombol reset form
private void button3_Click(object sender, EventArgs e) {
//kembalikan textbox ke nilai awal txtGGamal.Text = "0";
txtPGamal.Text = "0"; txtYGamal.Text = "0"; txtXGamal.Text = "0"; txtFile.Text = ""; txtHasil.Text = ""; txtRead.Text = ""; }
private void btnHitKunciGamal_Click(object sender, EventArgs e) {
if (txtPGamal.Text == "" || txtGGamal.Text == "" || txtXGamal.Text == "") {
MessageBox.Show("g/X/P harus diisi!"); }
else {
if (int.Parse(txtPGamal.Text) > 0 && int.Parse(txtGGamal.Text) > 0 && int.Parse(txtXGamal.Text) > 0)
{
if (int.Parse(txtGGamal.Text) >= int.Parse(txtPGamal.Text)) {
MessageBox.Show("nilai G harus lebih kecil dari P!"); }
else {
if (int.Parse(txtXGamal.Text) >= int.Parse(txtPGamal.Text))
{
MessageBox.Show("nilai X harus lebih kecil dari P!"); }
else {
//deklarasi variabel p : BigInteger = textbox txtP dikonversi ke BigInteger
BigInteger pGamal = BigInteger.Parse(txtPGamal.Text);
//cek apakah p bilangan prima atau tidak if (!Utility.IsPrime(pGamal))
{
//jika tidak, tampilkan pesan
MessageBox.Show("p bukan bilangan prima!");
} else {
BigInteger gGamal =
BigInteger.Parse(txtGGamal.Text);
BigInteger xGamal =
BigInteger.Parse(txtXGamal.Text);
BigInteger YGamal = BigInteger.ModPow(gGamal, xGamal, pGamal);
txtYGamal.Text = YGamal.ToString(); }
MessageBox.Show("P harus lebih dari 256!"); }
} else {
MessageBox.Show("g/X/P harus lebih dari 0!"); }
} }
private void btnEnkGamal_Click(object sender, EventArgs e) {
if (txtYGamal.Text != "") {
BigInteger gGamal = BigInteger.Parse(txtGGamal.Text); BigInteger xGamal = BigInteger.Parse(txtXGamal.Text); BigInteger YGamal = BigInteger.Parse(txtYGamal.Text); BigInteger pGamal = BigInteger.Parse(txtPGamal.Text); BigInteger kGamal, ghitGamal, yhitGamal;
//Deklarasi variabel str:string = txtRead
int pCount, k_int, j,f,g;
pCount = pGamal.ToString().Length;
string gstr, ystr, temp1, temp2, temp3 = ""; Stopwatch sw = Stopwatch.StartNew();
string[] arrayb = listk.ToArray();
//Deklarasi variabel hit: array BigInteger = konversi array finalValue dari string menjadi BigInteger
BigInteger[] hit = Array.ConvertAll(arrayb, BigInteger.Parse);
temp1 = ""; temp2 = ""; temp3 = "";
for (j = 0; j < arrayb.Length; j++) {
kGamal = Utility.RandomIntegerBelow(pGamal);
yhitGamal = BigInteger.Multiply(BigInteger.Pow(YGamal, k_int), hit[j]) % pGamal;
gstr = ghitGamal.ToString(); ystr = yhitGamal.ToString();
while (gstr.Length < pCount) {
temp1 = "0" + gstr; gstr = temp1; }
while (ystr.Length < pCount) {
temp2 = "0" + ystr; ystr = temp2; }
temp3 = temp3 + gstr + ystr; temp1 = "";
temp2 = ""; }
//tampilkan string hasenk ke textbox txtHasil txtHasil.Text = temp3;
lblPanjangKar.Text = txtHasil.Text.Length.ToString(); //sw stop
sw.Stop();
//mengambil waktu dalam satuan ms kemudian tampilkan ke textbox lblwaktu
lblWaktu.Text = sw.Elapsed.Milliseconds.ToString() + " ms";
} else {
MessageBox.Show("Klik tombol hitung terlebih dahulu."); }
}
private void txtRead_TextChanged(object sender, EventArgs e) {
private void button1_Click(object sender, EventArgs e) {
string[] arrayb = listk.ToArray();
txtHasil.Text = String.Join("", arrayb); MessageBox.Show("Selesai");
}
private void txtGGamal_TextChanged(object sender, EventArgs e) {
}
private void txtXGamal_TextChanged(object sender, EventArgs e) {
}
} }
Kode Program frmEnkripsi.Designer.cs
namespace EnkDekGUI {
partial class frmEnkripsi {
/// <summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used. /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose(); }
base.Dispose(disposing); }
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary>
private void InitializeComponent() {
this.button3 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.lblPanjangInput = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.txtFile = new System.Windows.Forms.TextBox(); this.btnBrowseInput = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label();
this.txtRead = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.txtHasil = new System.Windows.Forms.TextBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.lblWaktu = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.label10 = new System.Windows.Forms.Label(); this.txtYGamal = new System.Windows.Forms.TextBox(); this.btnHitKunciGamal = new System.Windows.Forms.Button(); this.label9 = new System.Windows.Forms.Label();
this.txtPGamal = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); this.txtXGamal = new System.Windows.Forms.TextBox(); this.txtGGamal = new System.Windows.Forms.TextBox(); this.btnEnkGamal = new System.Windows.Forms.Button(); this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout(); this.SuspendLayout();
//
// button3 //
this.button3.Location = new System.Drawing.Point(516, 308); this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(94, 26); this.button3.TabIndex = 167;
this.button3.Text = "Reset";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click); //
// groupBox2 //
this.groupBox2.Controls.Add(this.lblPanjangInput); this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.txtFile);
this.groupBox2.Controls.Add(this.btnBrowseInput); this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.txtRead);
this.groupBox2.Location = new System.Drawing.Point(12, 12); this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(385, 226); this.groupBox2.TabIndex = 166;
this.groupBox2.TabStop = false; this.groupBox2.Text = "Input"; //
//
this.lblPanjangInput.AutoSize = true;
this.lblPanjangInput.Location = new System.Drawing.Point(70, 199); this.lblPanjangInput.Name = "lblPanjangInput";
this.lblPanjangInput.Size = new System.Drawing.Size(13, 13); this.lblPanjangInput.TabIndex = 172;
this.lblPanjangInput.Text = "0"; //
// label7 //
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(6, 199); this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(52, 13); this.label7.TabIndex = 171;
this.label7.Text = "Panjang :"; //
// label1 //
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 24); this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 13); this.label1.TabIndex = 14;
this.label1.Text = "File Teks :"; //
// txtFile //
this.txtFile.Location = new System.Drawing.Point(73, 19); this.txtFile.Name = "txtFile";
this.txtFile.Size = new System.Drawing.Size(199, 20); this.txtFile.TabIndex = 13;
//
// btnBrowseInput //
this.btnBrowseInput.Location = new System.Drawing.Point(278, 17); this.btnBrowseInput.Name = "btnBrowseInput";
this.btnBrowseInput.Size = new System.Drawing.Size(94, 26); this.btnBrowseInput.TabIndex = 14;
this.btnBrowseInput.Text = "Browse";
this.btnBrowseInput.Click += new System.EventHandler(this.btnBrowseInput_Click);
// // label3 //
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 47); this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(42, 13); this.label3.TabIndex = 11;
this.label3.Text = "Isi File :"; //
// txtRead //
this.txtRead.Location = new System.Drawing.Point(73, 49); this.txtRead.Multiline = true;
this.txtRead.Name = "txtRead";
this.txtRead.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtRead.Size = new System.Drawing.Size(299, 145);
this.txtRead.TabIndex = 15;
this.txtRead.TextChanged += new
System.EventHandler(this.txtRead_TextChanged); //
// button2 //
this.button2.Location = new System.Drawing.Point(516, 276); this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(94, 26); this.button2.TabIndex = 166;
this.button2.Text = "Simpan";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); //
// label4 //
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(14, 251); this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 13); this.label4.TabIndex = 163;
// txtHasil //
this.txtHasil.Location = new System.Drawing.Point(56, 244); this.txtHasil.Multiline = true;
this.txtHasil.Name = "txtHasil";
this.txtHasil.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtHasil.Size = new System.Drawing.Size(454, 74);
this.txtHasil.TabIndex = 162; //
// openFileDialog1 //
this.openFileDialog1.Filter = "All Files |*.txt;*.doc;*.docx"; //
// saveFileDialog1 //
this.saveFileDialog1.DefaultExt = "elgmc"; this.saveFileDialog1.FileName = "hasil";
this.saveFileDialog1.Filter = "File Enkripsi El Gamal|*.elgmc"; //
// lblWaktu //
this.lblWaktu.AutoSize = true;
this.lblWaktu.Location = new System.Drawing.Point(336, 321); this.lblWaktu.Name = "lblWaktu";
this.lblWaktu.Size = new System.Drawing.Size(29, 13); this.lblWaktu.TabIndex = 171;
this.lblWaktu.Text = "0 ms"; //
// lblPanjangKar //
this.lblPanjangKar.AutoSize = true;
this.lblPanjangKar.Location = new System.Drawing.Point(473, 321); this.lblPanjangKar.Name = "lblPanjangKar";
this.lblPanjangKar.Size = new System.Drawing.Size(13, 13); this.lblPanjangKar.TabIndex = 170;
this.lblPanjangKar.Text = "0"; //
// label18 //
this.label18.AutoSize = true;
this.label18.Size = new System.Drawing.Size(91, 13); this.label18.TabIndex = 169;
this.label18.Text = "Waktu Eksekusi :"; //
// label17 //
this.label17.AutoSize = true;
this.label17.Location = new System.Drawing.Point(380, 321); this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(95, 13); this.label17.TabIndex = 168;
this.label17.Text = "Panjang Karakter :"; //
// groupBox3 //
this.groupBox3.Controls.Add(this.label10); this.groupBox3.Controls.Add(this.txtYGamal);
this.groupBox3.Controls.Add(this.btnHitKunciGamal); this.groupBox3.Controls.Add(this.label9);
this.groupBox3.Controls.Add(this.txtPGamal); this.groupBox3.Controls.Add(this.label5); this.groupBox3.Controls.Add(this.label8); this.groupBox3.Controls.Add(this.txtXGamal); this.groupBox3.Controls.Add(this.txtGGamal);
this.groupBox3.Location = new System.Drawing.Point(403, 12); this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(207, 226); this.groupBox3.TabIndex = 172;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Pembangkit Kunci"; //
// label10 //
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(12, 136); this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(14, 13); this.label10.TabIndex = 210;
this.label10.Text = "Y"; //
this.txtYGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtYGamal.Location = new System.Drawing.Point(44, 133);
this.txtYGamal.Name = "txtYGamal";
this.txtYGamal.Size = new System.Drawing.Size(142, 20); this.txtYGamal.TabIndex = 209;
this.txtYGamal.Text = "0"; //
// btnHitKunciGamal //
this.btnHitKunciGamal.Location = new System.Drawing.Point(92, 99); this.btnHitKunciGamal.Name = "btnHitKunciGamal";
this.btnHitKunciGamal.Size = new System.Drawing.Size(94, 26); this.btnHitKunciGamal.TabIndex = 208;
this.btnHitKunciGamal.Text = "Hitung";
this.btnHitKunciGamal.UseVisualStyleBackColor = true;
this.btnHitKunciGamal.Click += new
System.EventHandler(this.btnHitKunciGamal_Click); //
// label9 //
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(12, 75); this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(14, 13); this.label9.TabIndex = 207;
this.label9.Text = "P"; //
// txtPGamal //
this.txtPGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtPGamal.Location = new System.Drawing.Point(44, 72);
this.txtPGamal.Name = "txtPGamal";
this.txtPGamal.Size = new System.Drawing.Size(142, 20); this.txtPGamal.TabIndex = 206;
this.txtPGamal.Text = "0"; //
// label5 //
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 49); this.label5.Name = "label5";
this.label5.TabIndex = 205; this.label5.Text = "X"; //
// label8 //
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(12, 23); this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(13, 13); this.label8.TabIndex = 204;
this.label8.Text = "g"; //
// txtXGamal //
this.txtXGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtXGamal.Location = new System.Drawing.Point(44, 46);
this.txtXGamal.Name = "txtXGamal";
this.txtXGamal.Size = new System.Drawing.Size(142, 20); this.txtXGamal.TabIndex = 203;
this.txtXGamal.Text = "0";
this.txtXGamal.TextChanged += new
System.EventHandler(this.txtXGamal_TextChanged); //
// txtGGamal //
this.txtGGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtGGamal.Location = new System.Drawing.Point(44, 20);
this.txtGGamal.Name = "txtGGamal";
this.txtGGamal.Size = new System.Drawing.Size(142, 20); this.txtGGamal.TabIndex = 202;
this.txtGGamal.Text = "0";
this.txtGGamal.TextChanged += new
System.EventHandler(this.txtGGamal_TextChanged); //
// btnEnkGamal //
this.btnEnkGamal.Location = new System.Drawing.Point(516, 244); this.btnEnkGamal.Name = "btnEnkGamal";
this.btnEnkGamal.Size = new System.Drawing.Size(94, 26); this.btnEnkGamal.TabIndex = 173;
this.btnEnkGamal.Text = "Enkripsi";
this.btnEnkGamal.Click += new System.EventHandler(this.btnEnkGamal_Click); //
// frmEnkripsi //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(620, 360);
this.Controls.Add(this.btnEnkGamal); this.Controls.Add(this.groupBox3); this.Controls.Add(this.lblWaktu); this.Controls.Add(this.lblPanjangKar); this.Controls.Add(this.label18); this.Controls.Add(this.label17); this.Controls.Add(this.button3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.button2); this.Controls.Add(this.label4); this.Controls.Add(this.txtHasil);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false;
this.Name = "frmEnkripsi"; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Enkripsi ELGMAL";
this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.ResumeLayout(false); this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button3; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtFile; private System.Windows.Forms.Button btnBrowseInput; private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox txtHasil;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.Label lblWaktu;
private System.Windows.Forms.Label lblPanjangKar; private System.Windows.Forms.Label label18; private System.Windows.Forms.Label label17;
private System.Windows.Forms.Label lblPanjangInput; private System.Windows.Forms.Label label7;
private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox txtYGamal; private System.Windows.Forms.Button btnHitKunciGamal; private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtPGamal; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label8; private System.Windows.Forms.TextBox txtXGamal; private System.Windows.Forms.TextBox txtGGamal; private System.Windows.Forms.Button btnEnkGamal; }
}
Kode Program frmDekripsi.cs
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;
using System.Diagnostics;
namespace EnkDekGUI {
public partial class frmDekripsi : Form {
public frmDekripsi() {
InitializeComponent(); }
string exte = "";
List<byte> listk = new List<byte>();
//fungsi tombol browse file
private void btnBrowseInput_Click(object sender, EventArgs e) {
//deklarasi variabel result: dialog = dialog buka file DialogResult result = openFileDialog1.ShowDialog(); //jika result = OK
if (result == DialogResult.OK) {
//textbox txtfile = namafile
txtFile.Text = openFileDialog1.FileName; //kosongkan textbox txtread
txtRead.Text = "";
//textbox txtread diisi text dari txtFile
txtRead.AppendText(File.ReadAllText(@txtFile.Text)); lblPanjangInput.Text = txtRead.Text.Length.ToString(); }
}
//fungsi tombol reset form
private void button3_Click(object sender, EventArgs e) {
//kembalikan textbox ke nilai awal txtPGamal.Text = "0";
}
//fungsi tombol simpan hasil dekripsi
private void button2_Click(object sender, EventArgs e) {
//coba lakukan try
{
if (exte == "txt") {
saveFileDialog1.Filter = "File Teks |*.txt"; }else if(exte == "docx"){
saveFileDialog1.Filter = "File Docx|*.docx"; }
else if (exte == "doc") {
saveFileDialog1.Filter = "File Doc|*.doc"; }
//deklarasi variabel result: dialog = dialog simpan file DialogResult result = saveFileDialog1.ShowDialog(); //jika result = OK
if (result == DialogResult.OK) {
//simpan textbox hasil menjadi filename tipe txt
byte[] arrayb = listk.ToArray();
using (FileStream fsOutput = new
FileStream(@saveFileDialog1.FileName, FileMode.Create)) {
int j = 0;
while (j < arrayb.Length) {
fsOutput.WriteByte((byte)arrayb[j]); j++;
} }
//tampilkan pesan berhasil
}
//jika terdapat error catch (Exception err) {
//tampilkan pesan error
MessageBox.Show(err.Message.ToString(), "Error"); }
}
//===========================================fungsi dekripsi RSA===============================================
private void button1_Click(object sender, EventArgs e) {
//deklarasi variabel sw : stopwatch -> menghitung waktu proses Stopwatch sw = Stopwatch.StartNew();
BigInteger xGamal = BigInteger.Parse(txtXGamal.Text); BigInteger pGamal = BigInteger.Parse(txtPGamal.Text); BigInteger aGamal, bGamal,fGamal;
int x_int, p_int, pCount,j,p1x; x_int = int.Parse(xGamal.ToString()); p_int = int.Parse(pGamal.ToString()); pCount = pGamal.ToString().Length; string str = txtRead.Text;
string temps = "";
aGamal = BigInteger.Parse(str.Substring(0, pCount)); bGamal = BigInteger.Parse(str.Substring(pCount, pCount)); p1x = p_int - 1 - x_int;
fGamal = BigInteger.Multiply(BigInteger.Pow(aGamal, p1x) % p_int, bGamal) % p_int;
exte = fGamal.ToString(); if (exte == "1")
{
else if (exte == "2") {
exte = "docx"; }
else if (exte == "3") {
exte = "doc"; }
j = (pCount * 2); while ( j < str.Length) {
aGamal = BigInteger.Parse(str.Substring(j, pCount));
bGamal = BigInteger.Parse(str.Substring(j + (int)(pCount), pCount)); p1x = p_int - 1 - x_int;
fGamal = BigInteger.Multiply(BigInteger.Pow(aGamal, p1x) % p_int, bGamal) % p_int;
if (fGamal == 256) { fGamal = 0; }
listk.Add((byte)fGamal);
temps = temps + int.Parse(fGamal.ToString()); j = j + (pCount * 2);
}
//tampilkan textbox dari ps txtHasil.Text = temps; //sw stop
sw.Stop();
//mengambil waktu dalam satuan ms kemudian tampilkan ke textbox lblwaktu
lblWaktu.Text = sw.Elapsed.Milliseconds.ToString() + " ms";
//tampilkan ke textbox lblPanjangKar = panjang karakter dari txtHasil (dekripsi)
lblPanjangKar.Text = txtHasil.Text.Length.ToString(); }
private void txtRead_TextChanged(object sender, EventArgs e) {
private void button4_Click(object sender, EventArgs e) {
MessageBox.Show(txtRead.Text.Substring(1, 4)); }
private void frmDekripsi_Load(object sender, EventArgs e) {
}
//=========================================== end of fungsi dekripsi RSA===============================================
} }
Kode Program frmDekripsi.Designer.cs
namespace EnkDekGUI {
partial class frmDekripsi {
/// <summary>
/// Required designer variable. /// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used. /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose(); }
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary>
private void InitializeComponent() {
this.button3 = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.lblPanjangInput = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label(); this.txtFile = new System.Windows.Forms.TextBox(); this.btnBrowseInput = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label();
this.txtRead = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.label4 = new System.Windows.Forms.Label(); this.txtHasil = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.lblWaktu = new System.Windows.Forms.Label();
this.lblPanjangKar = new System.Windows.Forms.Label(); this.label18 = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.label9 = new System.Windows.Forms.Label(); this.txtPGamal = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.txtXGamal = new System.Windows.Forms.TextBox(); this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout(); this.SuspendLayout();
//
// button3 //
this.button3.Location = new System.Drawing.Point(516, 308); this.button3.Name = "button3";
this.button3.Text = "Reset";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click); //
// groupBox2 //
this.groupBox2.Controls.Add(this.lblPanjangInput); this.groupBox2.Controls.Add(this.label7);
this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.txtFile);
this.groupBox2.Controls.Add(this.btnBrowseInput); this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.txtRead);
this.groupBox2.Location = new System.Drawing.Point(12, 12); this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(385, 226); this.groupBox2.TabIndex = 173;
this.groupBox2.TabStop = false; this.groupBox2.Text = "Input"; //
// lblPanjangInput //
this.lblPanjangInput.AutoSize = true;
this.lblPanjangInput.Location = new System.Drawing.Point(70, 200); this.lblPanjangInput.Name = "lblPanjangInput";
this.lblPanjangInput.Size = new System.Drawing.Size(13, 13); this.lblPanjangInput.TabIndex = 174;
this.lblPanjangInput.Text = "0"; //
// label7 //
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(6, 200); this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(52, 13); this.label7.TabIndex = 173;
this.label7.Text = "Panjang :"; //
// label1 //
this.label1.AutoSize = true;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(69, 13); this.label1.TabIndex = 14;
this.label1.Text = "File Enkripsi :"; //
// txtFile //
this.txtFile.Location = new System.Drawing.Point(73, 19); this.txtFile.Name = "txtFile";
this.txtFile.Size = new System.Drawing.Size(199, 20); this.txtFile.TabIndex = 13;
//
// btnBrowseInput //
this.btnBrowseInput.Location = new System.Drawing.Point(278, 17); this.btnBrowseInput.Name = "btnBrowseInput";
this.btnBrowseInput.Size = new System.Drawing.Size(94, 26); this.btnBrowseInput.TabIndex = 14;
this.btnBrowseInput.Text = "Browse";
this.btnBrowseInput.UseVisualStyleBackColor = true;
this.btnBrowseInput.Click += new
System.EventHandler(this.btnBrowseInput_Click); //
// label3 //
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 47); this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(42, 13); this.label3.TabIndex = 11;
this.label3.Text = "Isi File :"; //
// txtRead //
this.txtRead.Location = new System.Drawing.Point(73, 49); this.txtRead.Multiline = true;
this.txtRead.Name = "txtRead";
this.txtRead.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtRead.Size = new System.Drawing.Size(299, 139);
this.txtRead.TabIndex = 15;
this.txtRead.TextChanged += new
//
// button2 //
this.button2.Location = new System.Drawing.Point(516, 276); this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(94, 26); this.button2.TabIndex = 165;
this.button2.Text = "Simpan";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); //
// label4 //
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(14, 251); this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 13); this.label4.TabIndex = 170;
this.label4.Text = "Hasil :"; //
// txtHasil //
this.txtHasil.Location = new System.Drawing.Point(56, 244); this.txtHasil.Multiline = true;
this.txtHasil.Name = "txtHasil";
this.txtHasil.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtHasil.Size = new System.Drawing.Size(454, 75);
this.txtHasil.TabIndex = 169; //
// button1 //
this.button1.Location = new System.Drawing.Point(516, 244); this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(94, 26); this.button1.TabIndex = 164;
this.button1.Text = "Dekripsi";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); //
// openFileDialog1 //
this.openFileDialog1.Filter = "File Enkripsi El Gamal |*.elgmc"; //
// lblWaktu //
this.lblWaktu.AutoSize = true;
this.lblWaktu.Location = new System.Drawing.Point(331, 321); this.lblWaktu.Name = "lblWaktu";
this.lblWaktu.Size = new System.Drawing.Size(29, 13); this.lblWaktu.TabIndex = 177;
this.lblWaktu.Text = "0 ms"; //
// lblPanjangKar //
this.lblPanjangKar.AutoSize = true;
this.lblPanjangKar.Location = new System.Drawing.Point(468, 321); this.lblPanjangKar.Name = "lblPanjangKar";
this.lblPanjangKar.Size = new System.Drawing.Size(13, 13); this.lblPanjangKar.TabIndex = 176;
this.lblPanjangKar.Text = "0"; //
// label18 //
this.label18.AutoSize = true;
this.label18.Location = new System.Drawing.Point(242, 321); this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(91, 13); this.label18.TabIndex = 175;
this.label18.Text = "Waktu Eksekusi :"; //
// label17 //
this.label17.AutoSize = true;
this.label17.Location = new System.Drawing.Point(375, 321); this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(95, 13); this.label17.TabIndex = 174;
this.label17.Text = "Panjang Karakter :"; //
// groupBox3 //
this.groupBox3.Controls.Add(this.label5); this.groupBox3.Controls.Add(this.txtXGamal);
this.groupBox3.Location = new System.Drawing.Point(410, 12); this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 226); this.groupBox3.TabIndex = 178;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Pembangkit Kunci"; //
// label9 //
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(14, 48); this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(14, 13); this.label9.TabIndex = 207;
this.label9.Text = "P"; //
// txtPGamal //
this.txtPGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtPGamal.Location = new System.Drawing.Point(46, 45);
this.txtPGamal.Name = "txtPGamal";
this.txtPGamal.Size = new System.Drawing.Size(142, 20); this.txtPGamal.TabIndex = 206;
this.txtPGamal.Text = "0"; //
// label5 //
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(14, 22); this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(14, 13); this.label5.TabIndex = 205;
this.label5.Text = "X"; //
// txtXGamal //
this.txtXGamal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtXGamal.Location = new System.Drawing.Point(46, 19);
this.txtXGamal.Name = "txtXGamal";
this.txtXGamal.TabIndex = 203; this.txtXGamal.Text = "0"; //
// frmDekripsi //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(619, 352);
this.Controls.Add(this.groupBox3); this.Controls.Add(this.lblWaktu); this.Controls.Add(this.lblPanjangKar); this.Controls.Add(this.label18); this.Controls.Add(this.label17); this.Controls.Add(this.button3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.button2); this.Controls.Add(this.label4); this.Controls.Add(this.txtHasil); this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false;
this.Name = "frmDekripsi"; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Dekripsi ELGAMAL";
this.Load += new System.EventHandler(this.frmDekripsi_Load); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); this.ResumeLayout(false); this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox txtRead; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox txtHasil; private System.Windows.Forms.Button button1;
private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.Label lblWaktu;
private System.Windows.Forms.Label lblPanjangKar; private System.Windows.Forms.Label label18; private System.Windows.Forms.Label label17; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox txtPGamal; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox txtXGamal; private System.Windows.Forms.Label lblPanjangInput; private System.Windows.Forms.Label label7;
} }
Kode Program frmKompresi.cs
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;
using System.Collections; using System.Diagnostics;
public partial class frmKompresi : Form {
public frmKompresi() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
this.OpenFD.FileName = "";
this.OpenFD.Filter = "File Enkripsi El Gamal|*.elgmc"; this.OpenFD.Title = "Buka File Enkripsi El Gamal"; bool flag = this.OpenFD.ShowDialog() == DialogResult.OK; if (flag)
{
textBox1.Text = this.OpenFD.FileName; }
}
private void button2_Click(object sender, EventArgs e) {
if (textBox1.Text.Length > 0) {
string sumber = "";
string filename = textBox1.Text;
string newfilename = filename.Replace(".elgmc", ".hmc");
if (File.Exists(Path.GetTempPath().ToString() + Path.GetFileName(filename).ToString()))
{
File.Delete(Path.GetTempPath().ToString() + Path.GetFileName(filename).ToString());
}
File.Copy(this.OpenFD.FileName, Path.GetTempPath().ToString() + Path.GetFileName(filename).ToString());
StreamReader streamReader = new StreamReader(filename); sumber = streamReader.ReadToEnd();
streamReader.Close();
Stopwatch sw = Stopwatch.StartNew();
huffmanTree.Build(sumber);
BitArray bit_array = huffmanTree.Encode(sumber);
byte[] bytes = new byte[bit_array.Length / 8 + (bit_array.Length % 8 == 0 ? 0 : 1)];
bit_array.CopyTo(bytes, 0);
File.WriteAllBytes(newfilename, bytes);
sw.Stop();
lblWaktu.Text = sw.Elapsed.Milliseconds.ToString() + " ms"; MessageBox.Show("Kompresi selesai!\n" + newfilename); }
else {
MessageBox.Show("Pilih file terlebih dahulu!"); }
}
} }
Kode Program frmKompresi.Designer.cs
namespace EnkDekGUI {
partial class frmKompresi {
/// <summary>
/// Required designer variable. /// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used. /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) {
components.Dispose(); }
base.Dispose(disposing); }
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary>
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.OpenFD = new System.Windows.Forms.OpenFileDialog(); this.lblWaktu = new System.Windows.Forms.Label();
this.label18 = new System.Windows.Forms.Label(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout();
//
// button1 //
this.button1.Location = new System.Drawing.Point(236, 12); this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(111, 35); this.button1.TabIndex = 0;
this.button1.Text = "Browse";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); //
// OpenFD //
this.OpenFD.FileName = "openFileDialog1"; //
// lblWaktu //
this.lblWaktu.AutoSize = true;
this.lblWaktu.Location = new System.Drawing.Point(101, 47); this.lblWaktu.Name = "lblWaktu";
this.lblWaktu.Text = "0 ms"; //
// label18 //
this.label18.AutoSize = true;
this.label18.Location = new System.Drawing.Point(12, 47); this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(91, 13); this.label18.TabIndex = 172;
this.label18.Text = "Waktu Eksekusi :"; //
// textBox1 //
this.textBox1.BackColor = System.Drawing.SystemColors.ControlLightLight; this.textBox1.Location = new System.Drawing.Point(12, 20);
this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(218, 20); this.textBox1.TabIndex = 174;
//
// button2 //
this.button2.Location = new System.Drawing.Point(353, 12); this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(111, 35); this.button2.TabIndex = 175;
this.button2.Text = "Kompresi";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); //
// frmKompresi //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(487, 78);
this.Controls.Add(this.button2); this.Controls.Add(this.textBox1); this.Controls.Add(this.lblWaktu); this.Controls.Add(this.label18); this.Controls.Add(this.button1);
this.Name = "frmKompresi"; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Kompresi Menggunakan Huffman";
this.ResumeLayout(false); this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.OpenFileDialog OpenFD; private System.Windows.Forms.Label lblWaktu;
private System.Windows.Forms.Label label18; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button2; }