• Tidak ada hasil yang ditemukan

Implementasi Hybrid Cryptosystem dengan Algoritma One Time Pad dan Algoritma Rabin Cryptosystem dalam Pengamanan Data Teks

N/A
N/A
Protected

Academic year: 2019

Membagikan "Implementasi Hybrid Cryptosystem dengan Algoritma One Time Pad dan Algoritma Rabin Cryptosystem dalam Pengamanan Data Teks"

Copied!
19
0
0

Teks penuh

(1)

LISTING PROGRAM

1.

Bahasa Python

1.1.

Module

gate.py

import sys

sys.path.append("C:\skrip")

import pythonA

def gerbang(fungsi):

if(fungsi == "bangkitKunci"):

from pythonA import bangkitkanKunci

a = str(sys.argv[1]) global b

b = int(sys.argv[2]) global c

c = int(sys.argv[3]) global d

(2)

global e

e = str(sys.argv[5]) gerbang(a)

1.2.

Module

pythonA.py

import random, time

class Timer(object): '''

timer starts with class initialisation '''

def __init__(self): self.t1= time.time() self.t2= time.time()

def getElapsedlTime(self):

# gets total elapsed from class initialsation self.delta=time.time()-self.t1

return '{0:.3f}'.format(self.delta)

def getTimeDifference(self):

# gets time elapsed from previous reading (for first reading this is equal to total time elapsed getElapsedlTime()

self.delta=time.time()-self.t2 self.t2 = time.time()

return '{0:.3f}'.format(self.delta)

def differentRandom(n): x = []

for i in range(0, len(str(n))): a = random.randint(2,n-1) while a in x:

a = random.randint(2,n-1) x.append(a)

return x

def toBin(x):

return "{0:b}".format(x)

def ntobin(n):

return toBin(n-1)

def modExpSAM(x, y, z): b = toBin(y)

t = len(b) result = 1

for i in range(0, t):

result = (result * result) % z

(3)

def moduloEks(acak, y, bil):

syarat_tdk_terpenuhi = True while syarat_tdk_terpenuhi: p = random.randint(3,10000) if (p % 4 == 3) and isPrime(p): syarat_tdk_terpenuhi = False

syarat_tdk_terpenuhi = True while syarat_tdk_terpenuhi: q = random.randint(3,10000)

if (q != p) and (q % 4 == 3) and isPrime(q): syarat_tdk_terpenuhi = False

n = p * q return p, q, n

def cekKunci(key1, key2):

if (key1 % 4 == 3) and isPrime(key1) and (key2 % 4 == 3) and isPrime(key2) and (key1 != key2):

return "T" else:

(4)

def enkripsi(P, n): if P < n:

C = modExpSAM(P,2,n) return C

return False

def encryptAll(P, n): C = []

def programEnkripsi(plaintext, kunciPublik): measure=Timer()

P = str(plaintext) n = int(kunciPublik) C = encryptAll(P, n)

C.append(measure.getElapsedlTime()) return C

def autoDekripsi(C, p, q):

mp = modExpSAM(C, (p+1)//4, p)

(5)

P1 = (x + y) % n

def decryptCiphertext2(C, p, q): measure=Timer()

C = convertListStringCToInt(C) P = []

for i in range(0, len(C)):

minP = autoDekripsi(C[i], p , q) P.append(chr(minP))

stringP = ''.join(P)

et = measure.getElapsedlTime() cetak = []

cetak.append(stringP) cetak.append(et)

temp = tulisHasilDekripsi(stringP) return cetak

def decryptCiphertext(C, p, q): measure=Timer()

et = measure.getElapsedlTime() cetak = []

cetak.append(stringP) cetak.append(et)

(6)

for i in range(len(L)): temp += str(L[i]) if(i < len(L)-1): temp += ',' return temp

def toDec(self, P): temp = []

for i in range(len(P)): temp.append(ord(P[i])) return temp

def toASCII(self, string): string = self.toLI(string) temp = ""

for e in string: temp += chr(e) return temp

#hasil = isPrime(100) #print(hasil)

2.

Bahasa C#

2.1.

Fungsi Pembangkit Kunci pada

FormPembangkitKunci.cs

public void runPythonBangkitKunci(){

ProcessStartInfo p = new ProcessStartInfo();

p.FileName = "c:\\Python33\\python.exe";

p.RedirectStandardOutput = true;

p.UseShellExecute = false;

p.Arguments = "c:\\skrip\\gate.py "+ "bangkitKunci 0 0 'x' 'x'"; // 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.Split(new char[]{' '});

textBoxKunciP.Text = r[0].ToString();

textBoxKunciQ.Text = r[1].ToString();

(7)

}

}

catch{

MessageBox.Show("Gagal melakukan pembangkit kunci.", "Kesalahan Proses Pembangkit Kunci",

MessageBoxButtons.OK, MessageBoxIcon.Error);

}

}

void ButtonGenerateClick(object sender, EventArgs e)

{

if(!string.IsNullOrWhiteSpace(textBoxKunciP.Text) & !string.IsNullOrWhiteSpace(textBoxKunciQ.Text)){

if(MessageBox.Show("Kunci yang anda tulis sebelumnya akan terhapus. Yakin untuk melanjutkan?", "Peringatan:

Pembangkitan Kunci", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK){

runPythonBangkitKunci();

}

}

else{

runPythonBangkitKunci();

}

}

2.2.

Fungsi Cek Kunci pada

FormPembangkitKunci.cs

void ButtonCekKunciClick(object sender, EventArgs e){

if(string.IsNullOrWhiteSpace(textBoxKunciP.Text) | string.IsNullOrWhiteSpace(textBoxKunciQ.Text)){

MessageBox.Show("Pasangan kunci tidak boleh ada yang kosong.", "Kesalahan Kunci", MessageBoxButtons.OK,

(8)

textBoxKunciN.Text = "";

}

else if(!string.IsNullOrWhiteSpace(textBoxKunciP.Text) & !string.IsNullOrWhiteSpace(textBoxKunciQ.Text)){

string hasil = runPythonCekKunci();

if(String.Equals(hasil, "T")){

int a = int.Parse(textBoxKunciP.Text);

int b = int.Parse(textBoxKunciQ.Text);

int c = a*b;

textBoxKunciN.Text = c.ToString();

}

else{

MessageBox.Show("Kunci tidak memenuhi syarat.", "Kesalahan Kunci", MessageBoxButtons.OK, MessageBoxIcon.Error);

textBoxKunciN.Text = "";

}

}

}

public string runPythonCekKunci(){

string hasil;

int kunci1 = int.Parse(textBoxKunciP.Text);

int kunci2 = int.Parse(textBoxKunciQ.Text);

ProcessStartInfo p = new ProcessStartInfo();

p.FileName = "c:\\Python33\\python.exe";

p.RedirectStandardOutput = true;

p.UseShellExecute = false;

p.Arguments = "c:\\skrip\\gate.py "+ "cekKunci " + kunci1 + " " + kunci2 + " 'x' 'x'";

try{

(9)

StreamReader s = exeProc.StandardOutput;

String output = s.ReadToEnd();

string []r = output.Split(new char[]{' '});

hasil = r[0][0].ToString();

}

}

catch{

MessageBox.Show("Gagal dalam melakukan cek kunci.", "Kesalahan Cek Kunci", MessageBoxButtons.OK,

MessageBoxIcon.Error);

hasil = "";

}

return hasil;

}

2.3.Fungsi Enkrip Pesan

void Button1EnkripsiClick(object sender, EventArgse)

{

if(string.IsNullOrWhiteSpace(textBox1plaintext.Text) | stri

ng.IsNullOrWhiteSpace(textBox1keyotp.Text)){

MessageBox.Show("Kunci OTP atau Pesan tidak boleh

kosong.", "Kesalahan

Dekripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);

}else{

textBox2chiphertext.Text="";

//ambilplainteks

string plain=textBox1plaintext.Text;

//ambilpanjangplainteks

int panjangplain=textBox1plaintext.Text.Length;

//ambilkunci

string kunci=textBox1keyotp.Text;

(10)

int pk=kunci.Length;

string cipher="";

//cekpanjangkuncidgnplain

kunciotp= "";

if(pk<panjangplain){

//contohkunci=abc

//plain:farid

//kunciotp=abc

kunciotp +=kunci;

string tempplain=Regex.Replace(plain, @"\s+", "");

int pjgtempplain=tempplain.Length;

for(int i = 0; i<(panjangplain-pjgtempplain);i++){

//kunciotp=abcfa

tempplain+= (char)tempplain[i];

}

//MessageBox.Show(tempplain);

//proses menyamakan kunci == plain

//perulangan sesuai kurangnya kunci

for(int i = 0; i<(panjangplain-pk);i++){

//kunciotp=abcfa

kunciotp+= (char)tempplain[i];

}

}else{

kunciotp = kunci;

}

DateTime startTime = DateTime.Now;

MessageBox.Show("panjang karakter :

"+panjangplain.ToString());

//algoritma otp

for(int i=0; i<panjangplain;i++){

cipher+=(char) (plain[i] + kunciotp[i]);

}

(11)

void Button1EnkripkeyClick(object sender, EventArgs e) {

//cek kunci

if(string.IsNullOrWhiteSpace(textBoxkeyRabin.Text)){ MessageBox.Show("Kunci publik belum ada.", "Kesalahan

Enkripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//cek plain

else if(string.IsNullOrEmpty(textBox1keyotp.Text)){ MessageBox.Show("Tidak ada pesan (plaintext) yang

terdeteksi.", "Kesalahan Enkripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);

} else{

//jika ada

string cipherText = runPythonEnkripsi(); }

textBox1cipherkey.Copy();

public string runPythonEnkripsi(){ string hasil;

string hasil2; //ambil kunci

int n = int.Parse(textBoxkeyRabin.Text); //ambil pesan

string plaintext =kunciotp; //ambil pnjang kunci

int pjgPlaintext = kunciotp.Length;

//

string pltxt1 = plaintext.Replace("\"","\\\""); int temporary = 0;

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 = "c:\\skrip\\gate.py "+ "enkripsi " + n + " " + temporary + " \"" + pltxt1 + "\" 'x'";

try{

using(Process exeProc = Process.Start(p)){ StreamReader s = exeProc.StandardOutput; String output = s.ReadToEnd();

string r = output; // get the parameter hasil = r.ToString();

hasil2 = hasil.Replace(" ",",");

(12)

string elapsedTime = hasil2.Split(',').Last();

hasil2 = hasil2.Remove((hasil2.Length - elapsedTime.Length), elapsedTime.Length);

hasil2 = hasil2.Remove(hasil2.Length-1,1);

if(hasil2 == "False"){

MessageBox.Show("Kunci publik tidak memenuhi syarat.", "Kesalahan Melakukan Enkripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);

hasil2 = ""; }

else{

textBox1cipherkey.Text = hasil2.ToString(); //Untuk menampilkan ASCII

try{

string kode = textBox1cipherkey.Text.ToString(); List<string> listHasilSplit = new

List<string>(kode.Split(','));

List<Int32> ci = listHasilSplit.ConvertAll(x => Convert.ToInt32(x));

List<char> liChar = new List<char>(ci.ConvertAll(x => Convert.ToChar(x)));

string charToString = string.Join("", liChar.ToArray());

kode = charToString;

} catch{

}

//End Tampil ASCII

MessageBox.Show("Berhasil melakukan enkripsi (" + elapsedTime + " detik)", "Informasi", MessageBoxButtons.OK,

MessageBoxIcon.Information); }

}

2.5.

Program dekripsi Kunci Pesan

void Button1dekripkeyotpClick(object sender, EventArgs e) {

if(string.IsNullOrWhiteSpace(kp.Text)|string.IsNullOrWhiteSpace(kq .Text)){

MessageBox.Show("Kunci private tidak boleh kosong.", "Kesalahan Dekripsi", MessageBoxButtons.OK,

(13)

else if(string.IsNullOrEmpty(ctotp.Text)){

MessageBox.Show("Tidak ada ciphertext terdeteksi.", "Kesalahan Dekripsi", MessageBoxButtons.OK,

MessageBoxIcon.Error); }

else{ try{

string ciphertext = ctotp.Text.ToString(); string[] bufferS = new

string[ctotp.Text.ToString().Length]; bufferS = ubahKeInt();

string result = ConvertStringArrayToStringJoin(bufferS);

List<string> listHasilSplit = new List<string>(ciphertext.Split(','));

List<Int32> ci =

listHasilSplit.ConvertAll(x => Convert.ToInt32(x));

List<char> liChar = new List<char>(ci.ConvertAll(x => Convert.ToChar(x)));

string charToString = string.Join("", liChar.ToArray());

ciphertext = charToString;

string plaintext = runPythonDekripsi(ciphertext); }

catch{

//MessageBox.Show("Ciphertext harus berupa angka yang dipisah dengan koma.", "Kesalahan melakukan dekripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);

string ciphertext = ctotp.Text.ToString();

string plaintext = runPythonDekripsi(ciphertext); }

}

}

public string ConvertStringArrayToStringJoin(string[] array){ string result = string.Join(",", array);

return result; }

string[] ubahKeInt(){

string C = ctotp.Text.ToString(); char[] charArr = C.ToCharArray(); int val;

string[] bufferS = new string[charArr.Length]; for(int i = 0; i < charArr.Length; i++){

(14)

}

return bufferS; }

public string runPythonDekripsi(string strIntC){ string hasil;

string hasil2;

int kunciP = int.Parse(kp.Text); int kunciQ = int.Parse(kq.Text);

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 = "c:\\skrip\\gate.py "+ "dek " + kunciP + " " + kunciQ + " " + "\"" + strIntC + "\" 'x'"; // 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

hasil = r.ToString();

string[] parts = hasil.Split(' ');

string elapsedTime = parts[parts.Length - 2];

hasil2 = hasil.Remove((hasil.Length - elapsedTime.Length), elapsedTime.Length);

hasil2 = hasil2.Remove(hasil2.Length-1,1);

hasil2 =

hasil2.Remove(hasil2.Length-1,1); // menghilangkan spasi di akhir kalimat

kotp.Text = hasil2.ToString();

int pjgPesanAsli = hasil2.Length;

MessageBox.Show("Berhasil melakukan dekripsi (" + elapsedTime + " detik)", "Informasi",

MessageBoxButtons.OK, MessageBoxIcon.Information); }

(15)

catch{

//throw;

strIntC = ctotp.Text.ToString();

p.FileName = "c:\\Python33\\python.exe"; p.RedirectStandardOutput = true;

p.UseShellExecute = false; // make sure we can read the output from stdout

p.Arguments = "c:\\skrip\\gate.py "+ "dek2 " + kunciP + " " + kunciQ + " " + "\"" + strIntC + "\" 'x'"; // 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

hasil = r.ToString();

string[] parts = hasil.Split(' ');

string elapsedTime = parts[parts.Length - 2];

hasil2 = hasil.Remove((hasil.Length - elapsedTime.Length), elapsedTime.Length);

hasil2 = hasil2.Remove(hasil2.Length-1,1);

hasil2 =

hasil2.Remove(hasil2.Length-1,1); // menghilangkan spasi di akhir kalimat

kotp.Text = hasil2; int pjgPesanAsli = hasil2.Length;

MessageBox.Show("Berhasil melakukan dekripsi (" + elapsedTime + " detik)", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);

} }

catch{

//throw;

(16)

p.FileName = "c:\\Python33\\python.exe";

p.RedirectStandardOutput = true; p.UseShellExecute = false; // make sure we can read the output from stdout

p.Arguments = "c:\\skrip\\gate.py "+ "dek2 " + kunciP + " " + kunciQ + " " + "\"" + strIntC + "\" 'x'"; // 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

hasil = r.ToString();

string[] parts = hasil.Split(' ');

string elapsedTime = parts[parts.Length - 2];

hasil2 = hasil.Remove((hasil.Length - elapsedTime.Length), elapsedTime.Length);

hasil2 = hasil2.Remove(hasil2.Length-1,1);

hasil2 =

hasil2.Remove(hasil2.Length-1,1); // menghilangkan spasi di akhir kalimat

kotp.Text = hasil2; int pjgPesanAsli = hasil2.Length;

MessageBox.Show("Berhasil melakukan dekripsi (" + elapsedTime + " detik)", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);

} }

catch{

(17)

MessageBox.Show("Kesalahan melakukan dekripsi.", "Kesalahan", MessageBoxButtons.OK,

MessageBoxIcon.Error);

hasil2 = ""; }

} }

return hasil2; }

2.6.

Perogram dekripsi pesan

void Button2dekripsiClick(object sender, EventArgs e) {

if(string.IsNullOrWhiteSpace(textBox1cipher.Text) | string.IsNullOrWhiteSpace(textBox1cipherkey.Text)){

MessageBox.Show("Kunci OTP dan Pesan Cipher tidak boleh kosong.", "Kesalahan Dekripsi", MessageBoxButtons.OK, MessageBoxIcon.Error);}

else{

//ambil cipher

string cipher=textBox1cipher.Text; //panjang cipher

int panjang= textBox1cipher.Text.Length; //ambil kunci

string kunci = kotp.Text; string pesan="";

DateTime waktuawal = DateTime.Now; //algoritma otp

for(int i=0; i<panjang;i++){

pesan += (char)(cipher[i]-kunci[i]); //MessageBox.Show(pesan.ToString()); }

MessageBox.Show("panjang : "+panjang.ToString()); MessageBox.Show("tes");

DateTime waktuakhir = DateTime.Now;

/*MessageBox.Show("Time : " + elapsed.Hours.ToString("00") + ":" +elapsed.Minutes.ToString("00") + ":" +

elapsed.Seconds.ToString("00") + "." +elapsed.Milliseconds.ToString("000"));*/

pesanbox.Text=pesan;

TimeSpan selisihwaktu = waktuakhir.Subtract(waktuawal); MessageBox.Show("Time : "

+selisihwaktu.Hours.ToString()+"

(18)

CURRICULUM VITAE

Nama

: Alfrid Iskandar Ramadhany Panggabean

Alamat Sekarang

: Jln. Umar Said No.1C Binjai

Alamat Orang Tua

: Jln. Umar Said No.1C Binjai

Telp/ Hp

: 087768644343

Email

: [email protected]

Riwayat Pendidikan

2010

2014

: S-1 Ilmu Komputer Universitas Sumatera Utara, Medan

2007

2010

: SMA Negeri 1, Binjai

2004

2007

: SMP Negeri 2, Binjai

1998

2004

: SD 020261, Binjai

Keahlian

Bahasa

: Indonesia, Inggris

Bahasa Pemrograman : C#.NET, Python.

Database

: Microsoft Access.

Design

: Photoshop, Corel Draw, Ilustrator

Pengalaman Organisasi

[2008

2009] OSIS SMA Negeri 1 Binjai

[2007

2009] Paskibraka SMA Negeri 1 Binjai

[2012

2013] Anggota Kemahasiswaan IMILKOM 2012 - 2013

(19)

Pengalaman Kepanitiaan

[2010]

Anggota D

okumentasi Seminar Teknologi Informasi “ The

Development Of Modern Operating

System Technology”

[2012]

Ketua Bidang Dana dan Usaha PORSENI IMILKOM 2012

Referensi

Dokumen terkait

Kolom KBeaufort pada tabel 4.10 merupakan kunci enkripsi dan dekripsi yang digunakan untuk algoritma Beaufort Cipher, kolom C1 merupakan hasil enkripsi pertama dengan menggunakan

Dalam penelitian ini algoritma Rijndael berfungsi untuk enkripsi plainteks dan dekripsi cipherteks dengan menggunakan kunci simetris (sessionkey), sedangkan pasangan kunci

Penerapan sistem kriptografi rsa banyak kunci untuk prototipe autentikasi pengguna pada web.. Universitas

- Pada penelitian sebelumnya telah dilakukan penelitian untuk keamanan data dengan kriptografi yang berjudul Implementasi Algoritma Affine Cipher dan Algoritma

Algoritma Rabin Cryptosystem merupakan algoritma kriptografi kunci publik maka enkripsi di lakukan hanya dengan menggunakan kunci publik yang dapat di ketahui oleh

OTP (pad = kertas blocknote) berisi deretan karakter-karakter kunci yang dibangkitkan secara acak[1]. Teknik enkripsi ini menggunakan pasangan plaintext dengan sebuah kunci

Algoritma Enigma digunakan untuk mengamankan teks pesan dan Algoritma Rabin-Williams untuk mengamankan kunci dari pesan yang telah dienkripsi.. Dalam hal ini Algoritma

yang akan dienkripsi. Label digunakan untuk judul ‘Kunci Simetris’. Textboxt berfungsi untuk menginput kunci simetris. Label digunakan untuk judul ‘Ciphertext’. Rich Text Box