Implementasi Algoritma Trithemius dengan Algoritma Rice Dalam Pengamanan dan Kompresi File Teks

A-1
Listing Program
About
public partial class about : Form
{
public about()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
MainForm home = new MainForm();
home.Show();
this.Hide();
}
}
}

Help
public partial class help : Form
{

public help()
{
InitializeComponent();
}
void Button1Click(object sender, EventArgs e)
{
MainForm home = new MainForm();
home.Show();
this.Hide();
}
}
}

Form 2 (Form Enkripsi + Dekripsi)
using
using
using
using
using
using

using

System;
System.Diagnostics;
System.Drawing;
System.IO;
System.Text;
System.Threading;
System.Windows.Forms;

using CSUsingOpenXmlPlainText;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;

namespace TriRice
{

Universitas Sumatera Utara

A-2

public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
GetWordPlainText getWordPlainText;
void Button1Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if(open.ShowDialog() == DialogResult.OK)
{
string metode = open.FileName.Substring
(open.FileName.Length-4,4);
if(metode=="docx")
{
textBox4.Text = open.FileName.ToString();
try
{
getWordPlainText

= new GetWordPlainText(open.FileName);
textBox1.Text =
getWordPlainText.ReadWordDocument();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxB
uttons.OK, MessageBoxIcon.Warning);
}
finally
{
if (getWordPlainText != null)
{
getWordPlainText.Dispose();
}
}
}
else
{
MessageBox.Show("File yang anda pilih salah");

}
}
}
public string ReadWordDocument()
{
StringBuilder sb = new StringBuilder();
return sb.ToString();
}
public string GetPlainText(OpenXmlElement element)
{
StringBuilder PlainTextInWord = new StringBuilder();
foreach (OpenXmlElement section in element.Elements())
{
switch (section.LocalName)
{

Universitas Sumatera Utara

A-3
case "t":

PlainTextInWord.Append(section.InnerText);
break;
case "cr":
// Carriage return
case "br":
// Page break
PlainTextInWord.Append(Environment.NewLine);
break;

// Tab
case "tab":
PlainTextInWord.Append("\t");
break;

// Paragraph
case "p":
PlainTextInWord.Append(GetPlainText(section));
PlainTextInWord.AppendLine(Environment.NewLine);
break;


default:
PlainTextInWord.Append(GetPlainText(section));
break;
}
}

return PlainTextInWord.ToString();
}

public bool enc;
void Button3Click(object sender, EventArgs e)
{
Stopwatch watch1 = new Stopwatch();
watch1.Start();
enc = true;
//Thread.Sleep(1000);
Trithemius tw = new Trithemius();
watch1.Stop();
textBox2.Text = tw.encryption(textBox1.Text,textBox3.Text);
label7.Text = "Running time =

" + Math.Round(Convert.ToDecimal(watch1.ElapsedMilliseconds),8).ToString()+
" ms";
}
void Button4Click(object sender, EventArgs e)
{
MainForm home = new MainForm();
home.Show();
this.Hide();
}
void Button5Click(object sender, EventArgs e)
{
if(enc){
SaveFileDialog save = new SaveFileDialog();

Universitas Sumatera Utara

A-4
save.Filter = "Encrypt File Trithemius|*.ttm";
save.FileName = "*.ttm";
if(save.ShowDialog() == DialogResult.OK)

{
FileStream fs
= new FileStream(save.FileName,FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
SeekOrigin sk = new SeekOrigin();
sw.BaseStream.Seek(0,sk);
sw.WriteLine(textBox2.Text);
sw.Flush();
sw.Close();
}
}
else{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Compress File Rice Code|*.rc";
save.FileName = "*.rc";
if(save.ShowDialog() == DialogResult.OK)
{
FileStream fs
= new FileStream(save.FileName,FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);

SeekOrigin sk = new SeekOrigin();
sw.BaseStream.Seek(0,sk);
sw.Write(code);
sw.Flush();
sw.Close();
string filename =
save.FileName.Substring(0,save.FileName.Length-3) + ".dat";
FileStream fstream
= new FileStream(filename, FileMode.OpenOrCreate);
StreamWriter sww = new StreamWriter(fstream);
SeekOrigin seekorigin = new SeekOrigin();
sww.BaseStream.Seek(0, seekorigin);
sww.Write(cs+"~");
for(int n=0; n