A1 LISTING PROGRAM 1. Module SkripsiUmri.py import sys, operator, codecs, time class Timer(object): def init (self): self.t1= time.time() def getelapsedltime(self): # gets total elapsed from class initialsation self.delta=time.time()-self.t1 return '{0:.3f'.format(self.delta) def tobin(x): return "{0:b".format(x) def getfrequence(string): karakter = [] for elemen in string: if elemen not in karakter: karakter.append(elemen) frekuensi = [] for elemen in karakter: hitung = 0 for e in string: if e == elemen: hitung += 1 frekuensi.append(hitung) pairing = [] for i in range(len(karakter)): pairing.append((karakter[i], frekuensi[i])) pairing.sort(key=operator.itemgetter(1), reverse=true) return karakter, frekuensi, pairing def levensteincode(n): nbin = tobin(n) kiri = nbin[0] kanan = nbin[1:] i = 1 M = len(kanan) C = kanan while(m!= 0): nbin = tobin(m) kiri = nbin[0] kanan = nbin[1:] kanan = '0' C = kanan + C M = len(kanan)
A2 i += 1 C = '0' + C for x in range(i): C = '1' + C return C def generatorkodelevenstein(jumlahvariasi): LCode = [] for i in range(1, jumlahvariasi+1): LCode.append(levensteinCode(i)) return LCode def levenstein(pairing): lenlcode = len(pairing) LCode = generatorkodelevenstein(lenlcode) sortedchar = [] for i in range(len(pairing)): sortedchar.append(pairing[i][0]) return LCode, sortedchar def readtxt(path): f = codecs.open(path, 'r', encoding = 'UTF-8') data = f.read() return data #print("\ngagal membaca file.") return False def readtxt2(path): '''if (".txt" not in path): path += ".txt"''' f = open(path, 'r') data = f.read() return data #print("\ngagal membaca file.") return False def encodelevenstein(pesan): measure = Timer() karakter, frekuensi, pairing = getfrequence(pesan) LCode, sortedchar = levenstein(pairing) #LCode = LCode[:7] #print(lcode) encoding = [] for e in Pesan: i = sortedchar.index(e) encoding.append(lcode[i]) kode = ''.join(encoding) i = 0 while len(kode) % 7!= 0: kode = kode + '0' i += 1 if i!= 0:
A3 bitflag = tobin(i) while len(bitflag) % 7!= 0: bitflag = '0' + bitflag kode = kode + bitflag else: kode = kode + '0000000' charkompresi = '' awal = 0 for i in range(7, len(kode)+1, 7): charkompresi += chr(int(kode[awal:i],2)) awal = i elapsedtime = measure.getelapsedltime() return sortedchar, charkompresi, elapsedtime def tulishasilencode(path, encode, listkarakter): # encode = char hasil kompresi # listkarakter = karakter yang sudah tersusun encode = "#*#" + encode for i in range(len(listkarakter)-1, -1, -1): encode = listkarakter[i] + encode with codecs.open(path, "w", encoding = "utf-8") as file: file.write(encode) file.close() #print(path) return len(encode) #print("kesalahan: hasil encode tidak dapat disimpan.") return False def decodelevenstein(karakter, charkompresi): measure = Timer() LCode = generatorkodelevenstein(len(karakter)) biner = '' for e in charkompresi: e = tobin(ord(e)) while len(e) < 7: e = '0' + e biner += e jumlahpenambahan = int(biner[len(biner)-7:],2) biner = biner[:len(biner)-7] if jumlahpenambahan!= 0: for i in range(jumlahpenambahan): biner = biner[:len(biner)] kemungkinan = '' hasil = '' for e in biner: kemungkinan += e if kemungkinan in LCode: hasil += karakter[lcode.index(kemungkinan)] kemungkinan = '' elapsedtime = measure.getelapsedltime() return hasil, elapsedtime
A4 def bacafiletext(path, tampilkan): f = open(path, 'r') data = f.read() if(tampilkan == True): print("-------------------------------------------------- FOF--------------------------------------------------") print(data) print("-------------------------------------------------- EOF--------------------------------------------------") return data print("\ngagal membaca file.") def bacatext(): path = str(input("nama file = ")) '''if ('\\' not in path): path = "D:\\K U L I A H\\Skripsi\\Belajar\\program python\\kriptografi\\plaintext\\" + path''' '''if (".txt" not in path): path += ".txt"''' return bacafiletext(path, True) pass def readtxtcodec(path): f = codecs.open(path, 'r', encoding = 'UTF-8') data = f.read() return data print("\ngagal membaca file.") def elias_split(value): binary = tobin(value) highest_bit = len(binary) - 1 remaining_bits = binary[1:] return highest_bit, remaining_bits #1-7 def eliasdeltacode(rank): biner = tobin(rank) c = biner [1:] rank = len(biner) biner = tobin(rank) c = biner + c rank = len(biner) - 1 for i in range(rank): c = '0' + c return c
A5 def generatorkodeelias(jumlahvariasi): Code = [] for i in range(1, jumlahvariasi+1): Code.append(eliasDeltaCode(i)) return Code def elias(pairing): lencode = len(pairing) #if lencode > 7: # lencode = 7 Code = generatorkodeelias(lencode) sortedchar = [] for i in range(len(pairing)): sortedchar.append(pairing[i][0]) return Code, sortedchar def encodeelias(pesan): measure = Timer() karakter, frekuensi, pairing = getfrequence(pesan) Code, sortedchar = elias(pairing) #print(code) encoding = [] for e in Pesan: i = sortedchar.index(e) encoding.append(code[i]) kode = ''.join(encoding) #print(kode) i = 0 while len(kode) % 7!= 0: kode = '0' + kode i += 1 if i!= 0: bitflag = tobin(i) while len(bitflag) % 7!= 0: bitflag = '0' + bitflag kode = kode + bitflag else: kode = kode + '0000000' #print(kode) charkompresi = '' awal = 0 for i in range(7, len(kode)+1, 7): charkompresi += chr(int(kode[awal:i],2)) awal = i elapsedtime = measure.getelapsedltime() return sortedchar, charkompresi, elapsedtime #underconstruction def decodeelias(karakter, charkompresi): measure = Timer() Code = generatorkodeelias(len(karakter)) #print(code) #print(karakter) biner = ''
A6 for e in charkompresi: e = tobin(ord(e)) while len(e) < 7: e = '0' + e biner += e #print(biner) #print() jumlahpenambahan = int(biner[len(biner)-7:],2) biner = biner[:len(biner)-7] #print(biner, jumlahpenambahan) #print() #print(jumlahpenambahan) if jumlahpenambahan!= 0: biner = biner[jumlahpenambahan:] #print() #print(biner) kemungkinan = '' hasil = '' for e in biner: kemungkinan += e if kemungkinan in Code: hasil += karakter[code.index(kemungkinan)] kemungkinan = '' elapsedtime = measure.getelapsedltime() return hasil, elapsedtime def tulishasildecode(path, hasil): with codecs.open(path, "w", encoding = "utf-8") as file: file.write(hasil) file.close() return hasil #print("kesalahan: hasil encode tidak dapat disimpan.") return False def dekompres(path): f = codecs.open(path, 'r', encoding = 'UTF-8') data = f.read() #print(data) #f = open(path, 'r') #data = f.read() for i in range(len(data)): if data[i] == '#' and data[i+1] == '*' and data[i+2] == '#': karakter = data[:i] charkompresi = data[i+3:] #print(karakter) break algoritma = path[len(path)-3:] if algoritma == 'lev': hasil, elapsedtime = decodelevenstein(karakter, charkompresi) return hasil, elapsedtime elif algoritma == 'eld': hasil, elapsedtime = decodeelias(karakter, charkompresi)
A7 return hasil, elapsedtime #print("\ngagal membaca file.") return False def gerbang(f): if f == 'encodelev': data = readtxt(a) if data == False: data = A sizedata = len(data)/1024 sortedchar, charkompresi, elapsedtime = encodelevenstein(data) sizeafter = tulishasilencode(b, charkompresi, sortedchar) #print(sizeafter) sizeafter = sizeafter/1024 #print(len(data), sizedata, sizeafter) RC = sizedata / sizeafter CR = sizeafter / sizedata * 100 R = 100 - CR hasil = str(elapsedtime) + '/' + str(round(rc,3)) + '/' + str(round(cr,3)) + '/' + str(round(r,3)) print(hasil) elif f == 'encodeelias': data = readtxt(a) if data == False: data = A sizedata = len(data)/1024 sortedchar, charkompresi, elapsedtime = encodeelias(data) sizeafter = tulishasilencode(b, charkompresi, sortedchar) sizeafter = sizeafter/1024 RC = sizedata / sizeafter CR = sizeafter / sizedata * 100 R = 100 - CR hasil = str(elapsedtime) + '/' + str(round(rc,3)) + '/' + str(round(cr,3)) + '/' + str(round(r,3)) print(hasil) elif f == 'decode': hasil, elapsedtime = dekompres(a) teks = tulishasildecode(b, hasil) decode = hasil + '/' + elapsedtime print(decode) global f f = str(sys.argv[1]) global A A = str(sys.argv[2]) global B B = str(sys.argv[3]) gerbang(f) 2. Fungsi Kompresi Levenstein pada MainForm.cs public void runpythonkompreslevenstein(string data, string lokasisimpan){
A8 ProcessStartInfo p = new ProcessStartInfo(); p.filename = "c:\\python33\\python.exe"; p.redirectstandardoutput = true; p.useshellexecute = false; // make sure we can read the output from stdout p.arguments = "skripsiumri.py "+ "encodelev " + "\"" + data + "\" " + "\"" + lokasisimpan + "\""; // start the python program with two parameters try{ using(process exeproc = Process.Start(p)){ StreamReader s = exeproc.standardoutput; String output = s.readtoend(); string r = output; // get the parameter string hasil = r.tostring(); string[] parts = hasil.split('/'); string waktu = parts[0]; string rc = parts[1]; string cr = parts[2]; string redudancy = parts[3]; textboxtimeofcompression.text = waktu + " detik"; textboxcompressionratio.text = cr + " %"; textboxratioofcompression.text = rc; textboxredudancy.text = redudancy + " %"; catch{ //log //throw; MessageBox.Show("Kesalahan melakukan kompresi", "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error); 3. Fungsi Kompresi Elias Delta Code pada MainForm.cs public void runpythonkompreselias(string data, string lokasisimpan){ ProcessStartInfo p = new ProcessStartInfo(); p.filename = "c:\\python33\\python.exe"; p.redirectstandardoutput = true; p.useshellexecute = false; // make sure we can read the output from stdout p.arguments = "skripsiumri.py "+ "encodeelias " + "\"" + data + "\" " + "\"" + lokasisimpan + "\""; // start the python program with two parameters try{ using(process exeproc = Process.Start(p)){ StreamReader s = exeproc.standardoutput; String output = s.readtoend(); string r = output; // get the parameter string hasil = r.tostring(); string[] parts = hasil.split('/'); string waktu = parts[0];
A9 detik"; string rc = parts[1]; string cr = parts[2]; string redudancy = parts[3]; textboxtimeofcompression.text = waktu + " textboxcompressionratio.text = cr + " %"; textboxratioofcompression.text = rc; textboxredudancy.text = redudancy + " %"; catch{ //log //throw; MessageBox.Show("Kesalahan melakukan kompresi", "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error); /* * Ratio of Compression : Sebelum / Sesudah * Compession Ratio : ukuran data sebelum / sesudah * 100% * Redudancy : 100% dikurang compression ratio atau 1 - RC (pake percent) * * */ 4. Fungsi Kompres pada MainForm.cs void ButtonKompresiClick(object sender, EventArgs e) { if(string.isnullorwhitespace(textboxsavekompresi.text)){ MessageBox.Show("Destinasi penyimpanan file belum dipilih.", "Kesalahan Kompresi", MessageBoxButtons.OK, MessageBoxIcon.Error); else{ string filesourcepath = textboxfilepath.text.tostring(); string filedestinationpath = textboxsavekompresi.text.tostring(); if(radiobuttonkompresilevenstein.checked){ string ekstensifile = ".lev"; filedestinationpath += ekstensifile; //filedestinationpath = "teslev.txt"; //MessageBox.Show(fileDestinationPath); //runpythonkompres(richtextbox1.text.tostring(), filedestinationpath); runpythonkompreslevenstein(filesourcepath, filedestinationpath); else if(radiobuttonkompresieliasdelta.checked){ string ekstensifile = ".eld"; filedestinationpath += ekstensifile;
A10 runpythonkompreselias(filesourcepath, filedestinationpath); else{ MessageBox.Show("Jenis kompresi belum dipilih.", "Kesalahan Kompresi", MessageBoxButtons.OK, MessageBoxIcon.Error); 4. Fungsi Dekompres pada MainForm.cs public void runpythondekompresi(string file, string lokasisimpan){ ProcessStartInfo p = new ProcessStartInfo(); p.filename = "c:\\python33\\python.exe"; p.redirectstandardoutput = true; p.useshellexecute = false; // make sure we can read the output from stdout p.arguments = "skripsiumri.py "+ "decode " + "\"" + file + "\" " + "\"" + lokasisimpan + "\""; // start the python program with two parameters try{ using(process exeproc = Process.Start(p)){ StreamReader s = exeproc.standardoutput; String output = s.readtoend(); string r = output; // get the parameter string hasil = r.tostring(); //MessageBox.Show(hasil); string waktu = hasil.split('/').last(); textboxtimedecode.text = waktu + " detik"; richtextboxdecode.text = hasil.remove(hasil.length - 8, 8); //File.WriteAllText(lokasiSimpan, hasil.remove(hasil.length - 8, 8)); catch{ //log //throw; MessageBox.Show("Kesalahan melakukan dekompresi", "Kesalahan", MessageBoxButtons.OK, MessageBoxIcon.Error);
B1 CURRICULUM VITAE umri.erdiansyah umriye -------------------------------------------------------------------------------------------------------- Data Pribadi Nama : Umri Erdiansyah Tempat/Tanggal Lahir : Binjai / 13 Oktober 1992 Tinggi/Berat Badan : 174 cm / 88 kg Agama : Islam Kewarganegaraan : Indonesia Alamat Sekarang : Jl. GB Yosua No. 82 A Jati Karya Binjai 20746 Alamat Orang Tua : Jl. GB Yosua No. 82 A Jati Karya Binjai 20746 Telp/ Hp : 0896 1322 1112 Email : umrierdiansyah13@gmail.com -------------------------------------------------------------------------------------------------------- Riwayat Pendidikan [2010 2014] : S1 Ilmu Komputer, Medan [2007 2010] : SMA Negeri 1 Binjai [2004 2007] : SMP Negeri 1 Binjai [1998 2004] : SD Negeri 023898 Binjai -------------------------------------------------------------------------------------------------------- Keahlian/Kursus Keahlian Bahasa : [2007 2009] : Kursus Bahasa Inggris GETS Keahlian Komputer : Pemrograman : Python, C# Database : MysQL
B2 Perkantoran : Microsoft Office -------------------------------------------------------------------------------------------------------- Pengalaman Organisasi [2008 2009] OSIS SMA Negeri 1 Binjai [2007 2009] Bengkel Sastra Bianglala SMA Negeri 1 Binjai [2010 2011] Anggota Kewirausahaan BKM Al-Khuwarizmi 2010-2011 [2012 2013] Anggota Kemahasiswaan IMILKOM 2012-2013 -------------------------------------------------------------------------------------------------------- Pengalaman Kepanitiaan [2010] Ketua Buka Bersama dan Sahur on the Road BKM Al-Khuwarizmi [2012] Anggota Acara PORSENI IMILKOM 2012 [2012] Anggota Acara PMB IMILKOM 2012 -------------------------------------------------------------------------------------------------------- Seminar [2014] Seminar Nasional Literasi Informasi SENARAI