Analisis dan Implementasi Algoritma Kompresi Subexponential Codes dan Inverted Elias Delta Pada File Teks
LISTING PROGRAM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AplikasiKompresiTeks
{
class ed
{
}
}
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 AplikasiKompresiTeks
Universitas Sumatera Utara
{
public partial class frmHome : Form
{
public frmHome()
{
InitializeComponent();
}
private void panel1_Paint(object sender,
PaintEventArgs e)
{
}
private void button2_Click(object sender,
EventArgs e)
{
//'InvertedEliasDeltaCodes IED = new
InvertedEliasDeltaCodes()
FormCompression frm = new FormCompression();
frm.Show();
this.Hide();
}
Universitas Sumatera Utara
private void button1_Click(object sender,
EventArgs e)
{
}
private void button3_Click(object sender,
EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
this.Hide();
}
private void button4_Click(object sender,
EventArgs e)
{
Form4 frm = new Form4();
frm.Show();
this.Hide();
}
private void button5_Click(object sender,
EventArgs e)
Universitas Sumatera Utara
{
Form5 frm = new Form5();
frm.Show();
this.Hide();
}
private void button6_Click(object sender,
EventArgs e)
{
if (MessageBox.Show("Yakin Untuk Keluar?",
"Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}
}
private void Form1_Load(object sender, EventArgs
e)
{
}
private void button7_Click(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
}
}
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 AplikasiKompresiTeks
{
public partial class FormCompression : Form
{
int waktu=0;
string algort;
public FormCompression()
{
Universitas Sumatera Utara
InitializeComponent();
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
private void button3_Click(object sender,
EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
this.Close();
}
private void button4_Click(object sender,
EventArgs e)
{
Form4 frm = new Form4();
frm.Show();
this.Close();
Universitas Sumatera Utara
}
private void button5_Click(object sender,
EventArgs e)
{
Form5 frm = new Form5();
frm.Show();
this.Close();
}
private void button6_Click(object sender,
EventArgs e)
{
if (MessageBox.Show("Yakin Untuk keluar?",
"Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}
}
private void TextBox1_TextChanged(object sender,
EventArgs e)
{
}
Universitas Sumatera Utara
private void button8_Click(object sender,
EventArgs e)
{
OpenFileDialog openFiledialog1 = new
OpenFileDialog();
openFiledialog1.Filter = "Text Files|*.txt";
if (openFiledialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
pilihfile.Text =
openFiledialog1.FileName;
String aFilename =
openFiledialog1.FileName;
MessageBox.Show("File Teks Telah
Dipilih");
}
}
private void button10_Click(object sender,
EventArgs e)
{
pilihfile.Text = "";
savefile.Text = "";
rc.Text = "";
Universitas Sumatera Utara
cr.Text = "";
ss.Text = "";
tp.Text = "";
}
private void btnCompress_Click(object sender,
EventArgs e)
{
System.Diagnostics.Stopwatch watch = new
System.Diagnostics.Stopwatch();
if (algort != "Subexponential Codes")
{
watch.Start();
TextReader baca = new
StreamReader(pilihfile.Text);
String st = baca.ReadToEnd();
SubexponentialCompression SPC = new
SubexponentialCompression();
SPC.RunSubexponentialCompression(st,
savefile.Text);
double Cratio = SPC.CR;
rc.Text = SPC.RC.ToString();
cr.Text = SPC.CR.ToString();
ss.Text = SPC.SS.ToString();
Universitas Sumatera Utara
watch.Stop();
tp.Text =
watch.Elapsed.TotalSeconds.ToString();
}
else
{
watch.Start();
TextReader baca = new
StreamReader(pilihfile.Text);
String st = baca.ReadToEnd();
InvertedEliasDeltaCodes ed = new
InvertedEliasDeltaCodes();
ed.RunInvertedEliasDelta(st,
savefile.Text);
double Cratio = ed.CR;
rc.Text = ed.RC.ToString();
cr.Text = ed.CR.ToString();
ss.Text = ed.SS.ToString();
watch.Stop();
tp.Text =
watch.Elapsed.TotalSeconds.ToString();
}
}
Universitas Sumatera Utara
private void button7_Click(object sender,
EventArgs e)
{
SaveFileDialog SFD= new SaveFileDialog();
if (algort != "Subexponential Codes")
{
SFD.Filter = "Text Files|*.iedc";
}
else
{
SFD.Filter = "Text Files|*.spc";
}
if (SFD.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
savefile.Text = SFD.FileName;
}
}
private void FormCompression_Load(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void timer1_Tick(object sender, EventArgs
e)
{
waktu += 1;
}
private void
RBSubexponentialCodes_CheckedChanged(object sender,
EventArgs e)
{
algort = "Subexponential Codes";
}
private void
RBInvertedEliasDelta_CheckedChanged(object sender,
EventArgs e)
{
algort = "Inverted Elias Delta";
}
private void GroupBox3_Enter(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void rc_TextChanged(object sender,
EventArgs e)
{
}
}
}
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 AplikasiKompresiTeks
{
public partial class Form4 : Form
{
Universitas Sumatera Utara
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs
e)
{
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
}
}
using System;
Universitas Sumatera Utara
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AplikasiKompresiTeks
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs
e)
{
}
private void label2_Click(object sender,
EventArgs e)
Universitas Sumatera Utara
{
}
private void Label1_Click(object sender,
EventArgs e)
{
}
private void Label4_Click(object sender,
EventArgs e)
{
}
private void Label14_Click(object sender,
EventArgs e)
{
}
private void pictureBox3_Click(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
}
}
public void InvertedEliasDelta(String st) {
int[] freq = CountFreq(st);
String charset = GetCharSet(st);
int t = charset.Length;
InsertionSort(freq, charset);
freq = fr;
charset = cs;
iedc = new String[t];
int c = 0;
for (int n = 1; n < t + 1; n++) {
String b = DecToBin(n);
int M = b.Length;
String Mb = DecToBin(M);
Universitas Sumatera Utara
StringBuilder u = new StringBuilder();
u = MultiAppend(u, "0", Mb.Length - 1);
u.Append(Mb);
String b1 = b.Substring(1, M - 1);
u.Append(b1);
iedc[c] = u.ToString();
c++;
}
for (int i = 0; i < t; i++)
iedc[i] = invert(iedc[i]);
}
public void RunInvertedEliasDelta(String st,String
namaFile) {
InvertedEliasDelta(st);
stb = StringToStb(st, cs, iedc);
//simpan FIle
int numOfBytes = stb.Length / 8;
byte[] bytes = new byte[numOfBytes];
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(stb.Substring(8 * i,
8), 2);
}
File.WriteAllBytes(namaFile , bytes);
Universitas Sumatera Utara
int uncompressed_bits = st.Length * 8;
int compressed_bits = stb.Length;
RC = uncompressed_bits / compressed_bits;
CR = (compressed_bits * 100) / uncompressed_bits;
SS = (uncompressed_bits - compressed_bits) / 4;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace AplikasiKompresiTeks
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Universitas Sumatera Utara
Application.Run(new frmHome());
}
}
}
private static void SubexponentialCodes(String st) {
int MAX = 64;
String charset = GetCharSet(st);
int t = charset.Length;
String[] suffix = new String[MAX];
suffix[0] = "00";
suffix[1] = "01";
suffix[2] = "10";
suffix[3] = "11";
suffix[4] = "00";
suffix[5] = "01";
suffix[6] = "10";
suffix [7] = "11";
suffix[8] = "000";
suffix[9] = "001";
suffix[10] = "010";
suffix[11] = "011";
Universitas Sumatera Utara
suffix[12] = "100";
suffix[13] = "101";
suffix[14] = "110";
suffix[15] = "111";
suffix[16] = "0000";
suffix[17] = "0001";
suffix[18] = "0010";
suffix[19] = "0011";
suffix[20] = "0100";
suffix[21] = "0101";
suffix[22] = "0110";
suffix[23] = "0111";
suffix[24] = "1000";
suffix[25] = "1001";
suffix[26] = "1010";
suffix[27] = "1011";
suffix[28] = "1100";
suffix[29] = "1101";
suffix[30] = "1110";
suffix[31] = "1111";
for (int i = 0; i < 32; i++)
Universitas Sumatera Utara
suffix[32 + i] = Pad(DecToBin(i),
5).ToString();
String[] sc = new String[MAX];
for (int i = 0; i < MAX; i++) {
StringBuilder prefix = new StringBuilder();
if (i < 4)
prefix = new StringBuilder("0");
else if (i >= 4 && i < 8)
prefix = new StringBuilder("10");
else if (i >= 8 && i < 16)
prefix = new StringBuilder("110");
else if (i >= 16 && i < 32)
prefix = new StringBuilder("1110");
else if (i >= 32 && i < 64)
prefix = new StringBuilder("11110");
sc[i] = prefix + suffix[i];
}
ccc = new String[t];
for (int i = 0; i < t; i++)
ccc[i] = sc[i];
}
Universitas Sumatera Utara
public void RunSubexponentialCompression(String st,
String namaFile)
{
int[] freq = CountFreq(st);
String charset = GetCharSet(st);
int t = charset.Length;
InsertionSort(freq, charset);
SubexponentialCodes(st);
String stb = StringToStb(st, cs, ccc);
int uncompressed_bits = st.Length * 8;
int compressed_bits = stb.Length;
int numOfBytes = stb.Length / 8;
byte[] bytes = new byte[numOfBytes];
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(stb.Substring(8 * i,
8), 2);
}
File.WriteAllBytes(namaFile, bytes);
RC = uncompressed_bits / compressed_bits;
CR = (compressed_bits * 100) / uncompressed_bits;
SS = (uncompressed_bits - compressed_bits) / 4;
}
}
Universitas Sumatera Utara
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AplikasiKompresiTeks
{
class ed
{
}
}
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 AplikasiKompresiTeks
Universitas Sumatera Utara
{
public partial class frmHome : Form
{
public frmHome()
{
InitializeComponent();
}
private void panel1_Paint(object sender,
PaintEventArgs e)
{
}
private void button2_Click(object sender,
EventArgs e)
{
//'InvertedEliasDeltaCodes IED = new
InvertedEliasDeltaCodes()
FormCompression frm = new FormCompression();
frm.Show();
this.Hide();
}
Universitas Sumatera Utara
private void button1_Click(object sender,
EventArgs e)
{
}
private void button3_Click(object sender,
EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
this.Hide();
}
private void button4_Click(object sender,
EventArgs e)
{
Form4 frm = new Form4();
frm.Show();
this.Hide();
}
private void button5_Click(object sender,
EventArgs e)
Universitas Sumatera Utara
{
Form5 frm = new Form5();
frm.Show();
this.Hide();
}
private void button6_Click(object sender,
EventArgs e)
{
if (MessageBox.Show("Yakin Untuk Keluar?",
"Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}
}
private void Form1_Load(object sender, EventArgs
e)
{
}
private void button7_Click(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
}
}
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 AplikasiKompresiTeks
{
public partial class FormCompression : Form
{
int waktu=0;
string algort;
public FormCompression()
{
Universitas Sumatera Utara
InitializeComponent();
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
private void button3_Click(object sender,
EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
this.Close();
}
private void button4_Click(object sender,
EventArgs e)
{
Form4 frm = new Form4();
frm.Show();
this.Close();
Universitas Sumatera Utara
}
private void button5_Click(object sender,
EventArgs e)
{
Form5 frm = new Form5();
frm.Show();
this.Close();
}
private void button6_Click(object sender,
EventArgs e)
{
if (MessageBox.Show("Yakin Untuk keluar?",
"Exit", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Exit();
}
}
private void TextBox1_TextChanged(object sender,
EventArgs e)
{
}
Universitas Sumatera Utara
private void button8_Click(object sender,
EventArgs e)
{
OpenFileDialog openFiledialog1 = new
OpenFileDialog();
openFiledialog1.Filter = "Text Files|*.txt";
if (openFiledialog1.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
pilihfile.Text =
openFiledialog1.FileName;
String aFilename =
openFiledialog1.FileName;
MessageBox.Show("File Teks Telah
Dipilih");
}
}
private void button10_Click(object sender,
EventArgs e)
{
pilihfile.Text = "";
savefile.Text = "";
rc.Text = "";
Universitas Sumatera Utara
cr.Text = "";
ss.Text = "";
tp.Text = "";
}
private void btnCompress_Click(object sender,
EventArgs e)
{
System.Diagnostics.Stopwatch watch = new
System.Diagnostics.Stopwatch();
if (algort != "Subexponential Codes")
{
watch.Start();
TextReader baca = new
StreamReader(pilihfile.Text);
String st = baca.ReadToEnd();
SubexponentialCompression SPC = new
SubexponentialCompression();
SPC.RunSubexponentialCompression(st,
savefile.Text);
double Cratio = SPC.CR;
rc.Text = SPC.RC.ToString();
cr.Text = SPC.CR.ToString();
ss.Text = SPC.SS.ToString();
Universitas Sumatera Utara
watch.Stop();
tp.Text =
watch.Elapsed.TotalSeconds.ToString();
}
else
{
watch.Start();
TextReader baca = new
StreamReader(pilihfile.Text);
String st = baca.ReadToEnd();
InvertedEliasDeltaCodes ed = new
InvertedEliasDeltaCodes();
ed.RunInvertedEliasDelta(st,
savefile.Text);
double Cratio = ed.CR;
rc.Text = ed.RC.ToString();
cr.Text = ed.CR.ToString();
ss.Text = ed.SS.ToString();
watch.Stop();
tp.Text =
watch.Elapsed.TotalSeconds.ToString();
}
}
Universitas Sumatera Utara
private void button7_Click(object sender,
EventArgs e)
{
SaveFileDialog SFD= new SaveFileDialog();
if (algort != "Subexponential Codes")
{
SFD.Filter = "Text Files|*.iedc";
}
else
{
SFD.Filter = "Text Files|*.spc";
}
if (SFD.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
savefile.Text = SFD.FileName;
}
}
private void FormCompression_Load(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void timer1_Tick(object sender, EventArgs
e)
{
waktu += 1;
}
private void
RBSubexponentialCodes_CheckedChanged(object sender,
EventArgs e)
{
algort = "Subexponential Codes";
}
private void
RBInvertedEliasDelta_CheckedChanged(object sender,
EventArgs e)
{
algort = "Inverted Elias Delta";
}
private void GroupBox3_Enter(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void rc_TextChanged(object sender,
EventArgs e)
{
}
}
}
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 AplikasiKompresiTeks
{
public partial class Form4 : Form
{
Universitas Sumatera Utara
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs
e)
{
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
}
}
using System;
Universitas Sumatera Utara
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AplikasiKompresiTeks
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs
e)
{
}
private void label2_Click(object sender,
EventArgs e)
Universitas Sumatera Utara
{
}
private void Label1_Click(object sender,
EventArgs e)
{
}
private void Label4_Click(object sender,
EventArgs e)
{
}
private void Label14_Click(object sender,
EventArgs e)
{
}
private void pictureBox3_Click(object sender,
EventArgs e)
{
Universitas Sumatera Utara
}
private void button1_Click(object sender,
EventArgs e)
{
frmHome frm = new frmHome();
frm.Show();
this.Close();
}
}
}
public void InvertedEliasDelta(String st) {
int[] freq = CountFreq(st);
String charset = GetCharSet(st);
int t = charset.Length;
InsertionSort(freq, charset);
freq = fr;
charset = cs;
iedc = new String[t];
int c = 0;
for (int n = 1; n < t + 1; n++) {
String b = DecToBin(n);
int M = b.Length;
String Mb = DecToBin(M);
Universitas Sumatera Utara
StringBuilder u = new StringBuilder();
u = MultiAppend(u, "0", Mb.Length - 1);
u.Append(Mb);
String b1 = b.Substring(1, M - 1);
u.Append(b1);
iedc[c] = u.ToString();
c++;
}
for (int i = 0; i < t; i++)
iedc[i] = invert(iedc[i]);
}
public void RunInvertedEliasDelta(String st,String
namaFile) {
InvertedEliasDelta(st);
stb = StringToStb(st, cs, iedc);
//simpan FIle
int numOfBytes = stb.Length / 8;
byte[] bytes = new byte[numOfBytes];
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(stb.Substring(8 * i,
8), 2);
}
File.WriteAllBytes(namaFile , bytes);
Universitas Sumatera Utara
int uncompressed_bits = st.Length * 8;
int compressed_bits = stb.Length;
RC = uncompressed_bits / compressed_bits;
CR = (compressed_bits * 100) / uncompressed_bits;
SS = (uncompressed_bits - compressed_bits) / 4;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace AplikasiKompresiTeks
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Universitas Sumatera Utara
Application.Run(new frmHome());
}
}
}
private static void SubexponentialCodes(String st) {
int MAX = 64;
String charset = GetCharSet(st);
int t = charset.Length;
String[] suffix = new String[MAX];
suffix[0] = "00";
suffix[1] = "01";
suffix[2] = "10";
suffix[3] = "11";
suffix[4] = "00";
suffix[5] = "01";
suffix[6] = "10";
suffix [7] = "11";
suffix[8] = "000";
suffix[9] = "001";
suffix[10] = "010";
suffix[11] = "011";
Universitas Sumatera Utara
suffix[12] = "100";
suffix[13] = "101";
suffix[14] = "110";
suffix[15] = "111";
suffix[16] = "0000";
suffix[17] = "0001";
suffix[18] = "0010";
suffix[19] = "0011";
suffix[20] = "0100";
suffix[21] = "0101";
suffix[22] = "0110";
suffix[23] = "0111";
suffix[24] = "1000";
suffix[25] = "1001";
suffix[26] = "1010";
suffix[27] = "1011";
suffix[28] = "1100";
suffix[29] = "1101";
suffix[30] = "1110";
suffix[31] = "1111";
for (int i = 0; i < 32; i++)
Universitas Sumatera Utara
suffix[32 + i] = Pad(DecToBin(i),
5).ToString();
String[] sc = new String[MAX];
for (int i = 0; i < MAX; i++) {
StringBuilder prefix = new StringBuilder();
if (i < 4)
prefix = new StringBuilder("0");
else if (i >= 4 && i < 8)
prefix = new StringBuilder("10");
else if (i >= 8 && i < 16)
prefix = new StringBuilder("110");
else if (i >= 16 && i < 32)
prefix = new StringBuilder("1110");
else if (i >= 32 && i < 64)
prefix = new StringBuilder("11110");
sc[i] = prefix + suffix[i];
}
ccc = new String[t];
for (int i = 0; i < t; i++)
ccc[i] = sc[i];
}
Universitas Sumatera Utara
public void RunSubexponentialCompression(String st,
String namaFile)
{
int[] freq = CountFreq(st);
String charset = GetCharSet(st);
int t = charset.Length;
InsertionSort(freq, charset);
SubexponentialCodes(st);
String stb = StringToStb(st, cs, ccc);
int uncompressed_bits = st.Length * 8;
int compressed_bits = stb.Length;
int numOfBytes = stb.Length / 8;
byte[] bytes = new byte[numOfBytes];
for (int i = 0; i < numOfBytes; ++i)
{
bytes[i] = Convert.ToByte(stb.Substring(8 * i,
8), 2);
}
File.WriteAllBytes(namaFile, bytes);
RC = uncompressed_bits / compressed_bits;
CR = (compressed_bits * 100) / uncompressed_bits;
SS = (uncompressed_bits - compressed_bits) / 4;
}
}
Universitas Sumatera Utara