Form Home Form Kompresi

LAMPIRAN LISTING PROGRAM

1. Form Home

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.Runtime.InteropServices; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1 { InitializeComponent; } private void Form1_Loadobject sender, EventArgs e { } private void compressToolStripMenuItem_Click_1object sender, EventArgs e { Form2 newMDIChild = new Form2; Universitas Sumatera Utara Set the Parent Form of the Child window. newMDIChild.MdiParent = this; Display the new form. newMDIChild.Show; } private void exitToolStripMenuItem_Clickobject sender, EventArgs e { Form5 newMDIChild = new Form5; newMDIChild.MdiParent = this; newMDIChild.Show; } private void decompressToolStripMenuItem_Clickobject sender, EventArgs e { Form3 newMDIChild = new Form3; newMDIChild.MdiParent = this; newMDIChild.Show; } private void aboutMeToolStripMenuItem_Clickobject sender, EventArgs e { Form4 newMDIChild = new Form4; newMDIChild.MdiParent = this; newMDIChild.Show; } private void helpToolStripMenuItem_Clickobject sender, EventArgs e { System.Windows.Forms.Application.Exit; } Universitas Sumatera Utara } }

2. Form Kompresi

using System; using System.IO; 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.Runtime.InteropServices.ComTypes; namespace WindowsFormsApplication1 { public partial class Form2 : Form { public string kalimat; public string nwkalimat; public Form2 { InitializeComponent; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; } Universitas Sumatera Utara private void Form2_Loadobject sender, EventArgs e { } private void button1_Clickobject sender, EventArgs e { DialogResult result = openFileDialog1.ShowDialog; Show the dialog. if result == DialogResult.OK Test result. { string file = openFileDialog1.FileName; textBox1.Text = file; } } public static String readingfiledocString kode { Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application; object miss = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Document docs = word.Documents.Openref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss; string totaltext = ; for int i = 0; i docs.Paragraphs.Count; i++ { totaltext += \r\n + docs.Paragraphs[i + 1].Range.Text.ToString; } string text = totaltext; return text; Universitas Sumatera Utara docs.Close; word.Quit; } private void button2_Clickobject sender, EventArgs e { string target = textBox1.Text; string extension = Path.GetExtensiontarget; if extension == .docx | extension == .txt { string namafolder=Path.GetDirectoryNametarget; string namafile = Path.GetFileNameWithoutExtensiontarget; calling Run inverted elias gamma function on inverted elias gamma clas invertedeliasgamma.runInvertedEliasGammatarget, namafolder, namafile; attach process result to inverted elias gamma text richTextBox1.Text =invertedeliasgamma.kalimatieg; calling Run Capocelli function on capocelli class capocelli.RunCapocelliCompressiontarget, namafolder, namafile; attach process result to capocelli text nwkalimat = capocelli.kalimatcpl; richTextBox3.Text = nwkalimat; } else { string msg = Your file extension are not txt or docx ; kotakpesanmsg; } Universitas Sumatera Utara } private void kotakpesanstring msg { string message = msg; string caption = Warning; MessageBoxButtons buttons = MessageBoxButtons.OK; DialogResult result; Displays the MessageBox. result = MessageBox.Showmessage, caption, buttons; if result == System.Windows.Forms.DialogResult.OK { Closes the parent form. this.Close; } } } public class invertedeliasgamma{ private static int[] fr; private static String cs; public static String kalimatieg; private static String[] egc; private static String[] iegc; public static String GetCharSetString st { { char c = st[i]; if s.ToString.IndexOfc == -1 Universitas Sumatera Utara s.Appendc; } return s.ToString; } private static int CountCharString s, char ch { return s.Splitch.Length - 1; } public static int[] CountFreqString st { String charset = GetCharSetst; int n = charset.Length; int[] freq = new int[n]; for int i = 0; i n; i++ freq[i] = CountCharst, charset[i]; return freq; } public static void InsertionSortint[] freq, String charset { fr = freq; cs = charset; int n = charset.Length; StringBuilder sb = new StringBuildercharset; for int i = 1; i n; i++ for int j = 0; j i; j++ if fr[i] fr[j] { char sbtemp = sb[i]; sb[i] = sb[j]; Universitas Sumatera Utara sb[j] = sbtemp; } cs = sb.ToString; } public static String ReverseString sb { char[] charArray = sb.ToCharArray; Array.ReversecharArray; return new StringcharArray; } public static int BinToDecString bin { StringBuilder sb = new StringBuilderReversebin; int n = 1; int dec = 0; for int i = 0; i sb.Length; i++ { dec = dec + intChar.GetNumericValuesb[i] n; n = n 2; } return dec; } public static String DecToBinint dec { StringBuilder bin = new StringBuilder; int r = dec 2; bin.Insert0, r; dec = dec 2; while dec = 0 { Universitas Sumatera Utara r = dec 2; bin.Insert0, r; dec = dec 2; } return bin.ToString; } converts strings into stringbits public static String StringToStbString st, String c, String[] s { { String z = Char.ToStringst[i]; int k = c.IndexOfz; stb.Appends[k]; } int x = stb.Length 8; int pad = 0; if x = 0 { pad = 8 - x; for int i = 0; i pad; i++ stb.Append0; } String d = DecToBinpad; int y = 8 - d.Length; for int i = 0; i y; i++ stb.Append0; stb.Appendd; return stb.ToString; } private static StringBuilder MultiAppendStringBuilder sb, String s, int t Universitas Sumatera Utara { for int i = 0; i t; i++ sb.Appends; return sb; } private static void InvertedEliasGammaString st { int[] freq = CountFreqst; String charset = GetCharSetst; int t = charset.Length; InsertionSortfreq, charset; freq = fr; charset = cs; egc = new String[t]; iegc = new String[t]; int c = 0; int ic = 0; for int n = 1; n t + 1; n++ { String b = DecToBinn; int M = b.Length; StringBuilder u = new StringBuilder; u = MultiAppendu, 0, M - 1; u.Append1; StringBuilder s1 = new StringBuilder; for int j = 0; j M; j++ { s1.Appendb[j]; s1.Appendu[j]; } String s2 = s1.ToString; String s = s2.Substring1, s2.Length - 1; Universitas Sumatera Utara egc[c] = s; c++; StringBuilder s3 = new StringBuilder; for int j = 0; j s.Length; j++ { if s[j] == 0 s3.Append1; else s3.Append0; } iegc[ic] = s3.ToString; ic++; } } public static void runInvertedEliasGammastring target, string folder, string nama{ string content=Form2.readingfiledoctarget; InvertedEliasGammacontent; String stb = StringToStbcontent, cs, iegc; int uncompressed_bits = target.Length 8; int compressed_bits = stb.Length; double CR = uncompressed_bits 1.0 compressed_bits; double SS = 1.0 - 1.0 CR 100; kalimatieg = String = + content.Length + \n + Char = + cs + \n + Compressed_bits = + compressed_bits + \n + Uncompressed_bits = + uncompressed_bits + \n + Compression Ratio = + CR + : 1 + \n + Space Savings = + SS + + \n Compressi Success 100; string text = stb; string path = folder + +nama+.ieg; System.IO.File.WriteAllTextpath, text; Universitas Sumatera Utara } } end inverted elias gamma class public class capocelli { private static int[] vr; private static String ass; public static String kalimatcpl; private static String[] vc; private static String GetCharSetString st { StringBuilder s = new StringBuilder; int n = st.Length; for int i = 0; i n; i++ { char c = st[i]; if s.ToString.IndexOfc == -1 s.Appendc; } return s.ToString; } private static int CountCharString s, char ch { return s.Splitch.Length - 1; } private static int[] CountvreqString st { String charset = GetCharSetst; int n = charset.Length; int[] vreq = new int[n]; Universitas Sumatera Utara for int i = 0; i n; i++ vreq[i] = CountCharst, charset[i]; return vreq; } private static void InsertionSortint[] vreq, String charset { vr = vreq; ass = charset; int n = charset.Length; StringBuilder sb = new StringBuildercharset; for int i = 1; i n; i++ for int j = 0; j i; j++ if vr[i] vr[j] { int vrtemp = vr[i]; vr[i] = vr[j]; vr[j] = vrtemp; char sbtemp = sb[i]; sb[i] = sb[j]; sb[j] = sbtemp; } ass = sb.ToString; } public static String ReverseString sb { char[] charArray = sb.ToCharArray; Array.ReversecharArray; return new StringcharArray; } private static String DecToBinint dec Universitas Sumatera Utara { StringBuilder bin = new StringBuilder; int r = dec 2; bin.Insert0, r; dec = dec 2; while dec = 0 { r = dec 2; bin.Insert0, r; dec = dec 2; } return bin.ToString; } private static int BinToDecString bin { StringBuilder sb = new StringBuilderReversebin; int n = 1; int dec = 0; for int i = 0; i sb.Length; i++ { dec = dec + intChar.GetNumericValuesb[i] n; n = n 2; } return dec; } converts strings into stringbits public static String StringToStbString st, String c, String[] s { StringBuilder stb = new StringBuilder; for int i = 0; i st.Length; i++ Universitas Sumatera Utara { String z = Char.ToStringst[i]; int k = c.IndexOfz; stb.Appends[k]; } int x = stb.Length 8; int pad = 0; if x = 0 { pad = 8 - x; for int i = 0; i pad; i++ stb.Append0; } String d = DecToBinpad; int y = 8 - d.Length; for int i = 0; i y; i++ stb.Append0; stb.Appendd; return stb.ToString; } private static StringBuilder PadString bin, int bit { StringBuilder sb = new StringBuilder; for int i = 0; i bit - bin.Length; i++ sb.Append0; sb.Appendbin; return sb; } private static void CapocelliString st, int r { Universitas Sumatera Utara int MAX = 20; String charset = GetCharSetst; int t = charset.Length; StringBuilder suffix = new StringBuilder; suffix.Append0; for int i = 0; i r; i++ suffix.Append1; String[] cc = new String[intMath.Pow2, MAX + 1]; cc[0] = suffix.ToString; int prefix_length = 1; int count = 1; while true { for int i = 0; i intMath.Pow2, prefix_length; i++ { StringBuilder prefix = PadDecToBini, prefix_length; if prefix.ToString.Containssuffix.ToString == false cc[count++] = prefix.Appendsuffix.ToString; } prefix_length += 1; if count t break; } vc = new String[t]; for int i = 0; i t; i++ vc[i] = cc[i]; } public static void RunCapocelliCompressionstring target, string folder, string nama { int r = 3; Universitas Sumatera Utara string content=Form2.readingfiledoctarget; int[] vreq =Countvreqcontent; String charset = GetCharSetcontent; int t = charset.Length; InsertionSortvreq, charset; Capocellicontent, r; String stb = StringToStbcontent, ass, vc; int uncompressed_bits = content.Length 8; int compressed_bits = stb.Length; double CR = uncompressed_bits 1.0 compressed_bits; double SS = 1.0 - 1.0 CR 100; kalimatcpl = String = + content.Length + \n + Char = + ass + \n + R = + r + \n + Compressed_bits = + compressed_bits + \n + Uncompressed_bits = + uncompressed_bits + \n + Compression Ratio = + CR + : 1 + \n + Space Savings = + SS + + \n Compressi Success 100; string text = stb; string path = folder + + nama +.cpl; System.IO.File.WriteAllTextpath, text; } } }

3. Form Uncompresi