• Tidak ada hasil yang ditemukan

Implementasi Algoritma One Time Pad pada Mikrokontroler Atmega32 untuk Keamanan Password Sistem Kendali Pintu Berbasis Android

N/A
N/A
Protected

Academic year: 2017

Membagikan "Implementasi Algoritma One Time Pad pada Mikrokontroler Atmega32 untuk Keamanan Password Sistem Kendali Pintu Berbasis Android"

Copied!
13
0
0

Teks penuh

(1)

Listing Program

A. Hardware

void main(void) {

PORTA.0=0;

//Tampilan Home lcd_gotoxy(0,0);

lcd_puts("Doorlock System"); lcd_gotoxy(0,1);

lcd_puts("One Time Pad"); delay_ms(3000);

goto awal; awal:;

//Tampilan Status DoorLock lcd_clear();

lcd_gotoxy(0,0); if(flag==0){

PORTA.0=0;

lcd_puts("--LOCKED--"); delay_ms(5000);

}else if(flag==1){ PORTA.0=1;

lcd_puts("--UNLOCKED--"); delay_ms(5000);

}

delay_ms(100); while (1)

{

scanf("%s",req);

if(strcmp(req, "lock")==0){ //lock();

lcd_clear(); lcd_gotoxy(0,0); lcd_puts("Key :"); lcd_gotoxy(0,1);

lcd_puts("Password :"); delay_ms(1000);

//Input Key dan Password scanf("%s", kunci); scanf("%s", pass); lcd_clear();

//Tampilkan Key dan Password lcd_gotoxy(0,0);

lcd_puts(kunci); lcd_gotoxy(0,1); lcd_puts(pass); delay_ms(1000);

//Simpan password ke EEPROM for(i=0;i<sizeof(pass);i++){

password[i]= pass[i];

lcd_buff[i]= (char) password[i]; }

(2)

//Tampilkan Passsword dari EEPROM lcd_clear();

lcd_gotoxy(0,0); lcd_puts(lcd_buff); delay_ms(1000); */

//Simpan Key ke EEPROM

for(i=0;i<sizeof(kunci);i++){ key[i]= kunci[i];

lcd_buff[i]= (char) key[i]; }

/*

//Tampilkan Key dari EEPROM lcd_clear();

lcd_gotoxy(0,0); lcd_puts(lcd_buff); delay_ms(1000); */

//Status Lock flag=0;

goto awal;

}else if(strcmp(req, "unlock")==0){ //unlock();

lcd_gotoxy(0,0);

lcd_puts("Password :"); delay_ms(1000);

scanf("%s",cipher); lcd_puts(cipher); delay_ms(1000); lcd_clear();

//Ambil Key dari EEPROM for(i=0;i<10;i++){

kunci[i] = (char) key[i]; lcd_buff[i]=kunci[i]; }

/*lcd_gotoxy(1,0); lcd_puts(lcd_buff); delay_ms(3000); lcd_clear();*/

//Dekripsi Cipherteks for(i=0;i<10;i++){

temp=0;

if(cipher[i]<126){

temp= cipher[i]+126-31; }

plain[i] =(char) (temp - key[i]); lcd_buff[i]=plain[i];

}

//Hasil Dekripsi lcd_gotoxy(0,0); lcd_puts(lcd_buff); delay_ms(3000); lcd_clear();

(3)

for(i=0;i<10;i++){

pass[i] = (char )password[i]; lcd_buff[i]=pass[i];

} /*

lcd_gotoxy(0,0); lcd_puts(lcd_buff); delay_ms(3000); */

//Cek Kecocokan Password for(i=0;i<10;i++){

if(plain[i]== pass[i]){ stat=1;

}else{ stat=0; break; }

}

if (stat==1){

//Password Benar flag=1;

}else{

//Salah Password lcd_clear();

lcd_puts("Wrong Password"); delay_ms(1000);

}

goto awal; }else{

//Salah Menu lcd_gotoxy(0,0);

lcd_puts("Tidak ada pilihan"); delay_ms(500);

} } }

B. Android

public class LockActivity extends Activity {

//SecureRandom randomGenerator = new SecureRandom(); BBSprng BBS = new BBSprng();

//BigInteger rand = BBS.generatorBBS(2); //keytxt.setText(rand.toString());

int bbs=0;

//Random randomGenerator = new Random(); for (int i = 1; i<=10; i++)

{

/*long seed = System.nanoTime();

long randomInt = (seed * seed *

randomGenerator.nextInt(10000)); if(randomInt<0){

randomInt = - randomInt; }*/

(4)

if(bbs < 0){ bbs = -bbs; }

int y = bbs % 26;

key= key + (char) (65 + y); }

//plaintxt.setText(Integer.toString(bbs)); keytxt.setText(key);

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter == null)

{

Label.setText("No bluetooth adapter available"); }

if(!mBluetoothAdapter.isEnabled()) {

Intent enableBluetooth = new

Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableBluetooth, 0); }

}

// On Start Activity @Override

public void onStart() {

super.onStart();

if(D) Log.e(TAG, "ON START"); //Open Connection

ButtonOpen.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

try {

SearchBT(); OpenBT();

sendData("lock"); }

catch (IOException ex) { } }

});

//Send plain and Key

ButtonLocked.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

try {

//Encriypt teks

String key = keytxt.getText().toString(); String plain = plaintxt.getText().toString(); if(plain.length()<=10)

{

DatabaseHandler db = new

(5)

db.addKey(cipher, key); sendData(key);

sendData(plain); }else{

Toast.makeText(getApplicationContext(), "Panjang PlainTeks Harus 10", Toast.LENGTH_LONG).show();

} }

catch (Exception ex) { } }

});

//Close Connection

ButtonClose.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

try {

closeBT(); }

catch (IOException ex) { } }

}); }

void SearchBT() {

if(D) Log.d(TAG, "Cari BT");

Set<BluetoothDevice> pairedDevices =

mBluetoothAdapter.getBondedDevices(); if(pairedDevices.size() > 0) {

for(BluetoothDevice device : pairedDevices) {

if(device.getName().equals("HC-05")) {

mmDevice = device;

Label.setText("Slave Client Found"); //break;

} else {

Label.setText("Slave Client Not Found"); }

// Register the BroadcastReceiver

/*IntentFilter filter = new

IntentFilter(BluetoothDevice.ACTION_FOUND);

registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy*/

} } }

// Untuk memulai melakukan koneksi dengan client bluetooth void OpenBT() throws IOException

{

if(D) Log.d(TAG, "Buka BT");

UUID uuid =

(6)

SerialPortService ID

mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); mmSocket.connect();

mmOutputStream = mmSocket.getOutputStream(); mmInputStream = mmSocket.getInputStream(); ListenForData();

Label.setText("Bluetooth Opened");

//Toast.makeText(this, "Bluetooth Dibuka", Toast.LENGTH_LONG).show();

}

// Background thread untuk menerima data dari client bluetooth void ListenForData()

{

if(D) Log.d(TAG, "Listen Data");

final byte delimiter = 13; //atau Carriage Return (CR), di gunakan untuk mendeteksi akhir dari text

stopWorker = false; readBufferPosition = 0; Buffer = new byte[1024];

Thread workerThread = new Thread(new Runnable() {

@Override

public void run() {

while(!Thread.currentThread().isInterrupted() && !stopWorker)

{

//Do work try

{

int bytesAvailable = mmInputStream.available(); if(bytesAvailable > 0)

{

byte[] packetBytes = new byte[bytesAvailable]; mmInputStream.read(packetBytes);

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

byte b = packetBytes[i]; if(b == delimiter)

{

byte[] encodedBytes = new

byte[readBufferPosition];

System.arraycopy(Buffer, 0,

encodedBytes, 0, encodedBytes.length);

final String data = new

String(encodedBytes, "US-ASCII");

readBufferPosition = 0; Message m = new Message(); Bundle bund = new Bundle(); bund.putString("My Key", data); m.setData(bund);

h.sendMessage(m); }

else {

Buffer[readBufferPosition++] = b; }

(7)

}

catch (IOException ex) {

stopWorker = true; }

} } });

workerThread.start(); }

// Untuk mengirim data ke client bluetooth void sendData(String m) throws IOException {

if(D) Log.d(TAG, "Kirim Data"); m += "\n\r";

mmOutputStream.write(m.getBytes()); Label.setText("Data Sent");

//Toast.makeText(this, “Data Terkirim“,

Toast.LENGTH_LONG).show(); }

//Untuk Ekripsi One Time Pad

void Enkripsi(String key, String plain) throws IOException {

cipher=""; int temp=0; char c; //int sum;

for(int i= 0; i<key.length();i++) {

temp = key.charAt(i) + plain.charAt(i); if(temp>126){

temp=(temp-126)+31; }

c= (char) temp; cipher=cipher + c;

//Toast.makeText(getApplicationContext(), cipher ,Toast.LENGTH_LONG).show();

}

/*sum = 67 ^ 68; c= (char) sum; cipher=cipher+ c;*/ }

}

public class UnlockActivity extends Activity { try{

DatabaseHandler db = new

DatabaseHandler(getApplicationContext());

String key = db.getDetails().get("key"); String plain = db.getDetails().get("plain"); String cipher="";

Enkripsi(key, plain);

cipher=Ciphertxt.getText().toString(); Dekripsi(key, cipher);

(8)

}

//Send Cipher

ButtonUnlocked.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

try {

DatabaseHandler db = new

DatabaseHandler(getApplicationContext());

String key = db.getDetails().get("key");

String cipher = db.getDetails().get("cipher"); if(cipher.length()>=10)

{

Ciphertxt.setText(cipher); //Dekripsi(key, cipher); //Send Cipher

sendData(cipher); }else{

Toast.makeText(getApplicationContext(), "Panjang Cipherteks Harus 10", Toast.LENGTH_LONG).show();

} }

catch (IOException ex) { } }

}); }

// Mencari Client Bluetooth yg sudah paired dengan nama “nutscientist“ void SearchBT()

{

if(D) Log.d(TAG, "Cari BT");

Set<BluetoothDevice> pairedDevices =

mBluetoothAdapter.getBondedDevices(); if(pairedDevices.size() > 0) {

for(BluetoothDevice device : pairedDevices) {

if(device.getName().equals("HC-05")) {

mmDevice = device;

Label.setText("Slave Client Found"); //break;

} else {

Label.setText("Slave Client Not Found"); }

// Register the BroadcastReceiver

/*IntentFilter filter = new

IntentFilter(BluetoothDevice.ACTION_FOUND);

registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy*/

} } }

(9)

{

if(D) Log.d(TAG, "Buka BT");

UUID uuid =

UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); //Standard SerialPortService ID

mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); mmSocket.connect();

mmOutputStream = mmSocket.getOutputStream(); mmInputStream = mmSocket.getInputStream(); ListenForData();

Label.setText("Bluetooth Opened");

//Toast.makeText(this, "Bluetooth Dibuka", Toast.LENGTH_LONG).show();

}

// Background thread untuk menerima data dari client bluetooth void ListenForData()

{

if(D) Log.d(TAG, "Listen Data");

final byte delimiter = 13; //atau Carriage Return (CR), di gunakan untuk mendeteksi akhir dari text

stopWorker = false; readBufferPosition = 0; Buffer = new byte[1024];

Thread workerThread = new Thread(new Runnable() {

@Override

public void run() {

while(!Thread.currentThread().isInterrupted() && !stopWorker)

{

//Do work try

{

int bytesAvailable = mmInputStream.available(); if(bytesAvailable > 0)

{

byte[] packetBytes = new byte[bytesAvailable]; mmInputStream.read(packetBytes);

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

byte b = packetBytes[i]; if(b == delimiter)

{

byte[] encodedBytes = new

byte[readBufferPosition];

System.arraycopy(Buffer, 0,

encodedBytes, 0, encodedBytes.length);

final String data = new

String(encodedBytes, "US-ASCII");

readBufferPosition = 0; Message m = new Message(); Bundle bund = new Bundle(); bund.putString("My Key", data); m.setData(bund);

h.sendMessage(m); }

else {

(10)

} } } }

catch (IOException ex) {

stopWorker = true; }

} } });

workerThread.start(); }

// Untuk mengirim data ke client bluetooth void sendData(String m) throws IOException {

if(D) Log.d(TAG, "Kirim Data"); m += "\n\r";

mmOutputStream.write(m.getBytes()); Label.setText("Data Sent");

//Toast.makeText(this, “Data Terkirim“,

Toast.LENGTH_LONG).show(); }

//Untuk Ekripsi One Time Pad

//www.life0fpentester.blogspot.com/2014/03/one-time-pad-encryptio n-decryption.html

void Enkripsi(String key, String plain) throws IOException {

String cipher=""; int temp=0;

char c; //int sum;

for(int i= 0; i<key.length();i++) {

temp = key.charAt(i) + plain.charAt(i); if(temp>126){

temp=(temp-126)+31; }

c= (char) temp; cipher=cipher + c;

//Toast.makeText(getApplicationContext(), cipher ,Toast.LENGTH_LONG).show();

}

/*sum = 67 ^ 68; c= (char) sum; cipher=cipher+ c;*/

Ciphertxt.setText(cipher); }

void Dekripsi(String key, String cipher) throws IOException {

String plain=""; int temp=0; char c; //int sum;

(11)

{

temp = cipher.charAt(i) - key.charAt(i); if(temp<126){

temp=(temp+126)-31; }

c= (char) temp; plain=plain + c;

//Toast.makeText(getApplicationContext(), cipher ,Toast.LENGTH_LONG).show();

}

/*sum = 67 ^ 68; c= (char) sum; cipher=cipher+ c;*/ Label.setText(plain); }

(12)

D

AFTAR

R

IWAYAT

H

IDUP

C

URRICULUM

V

ITAE

PERSONAL DATA

Full Name

: Agung Putu Yoga

Nick Name

: Agung

Place/ Date of Birth : Binjai/May 26

th

1993

Sex

: Male

Religion

: Islam

Nationality

: Indonesia

Address

: Jalan Kenanga Raya, Psr VI, Gang Wirya, No. 7. Medan

Selayang

Mobile Phone

: 087748838867

E-mail

: agungputuyoga26@gmail.com

Marital Statu

: unmarried / married

EDUCATION

Bachelor of Computer Science

University of Sumatera Utara, Medan

2011-Present

Higher Secondary Education

SMAN 1 TANJUNG PURA

2008-2011

Secondary Education

SMPN 1 HINAI

2005-2008

Primary Education

SDN 056011 BATU MALENGGANG

1999-2005

Programming : Pascal, C, C++, Java, PHP, C#

Database

: MySQL

IDE

: CodeBlock, Free Pascal, Dev C++, Geany, JCreator, NetBeans,

Sharp Develope, eclipse, Visual Studio

Other

:

(13)

Android Application Doa Harian Islam

System Information Application Laundry

System Information Application Manga Shop

System Information Application Parking

Android Aplication Inventaris Bussiness Support Pertamina

Android Aplication Doorlock

Windows Phone Application Help!

Windows Phone Application WinBike

ORGANIZATIONAL EXPERIENCES

No Organization

Position

Year

1

OSIS SMAN 1 Tanjung Pura

Anggota Bid. Bela

Negara

2009-2010

2

WADOKAI Tanjung Pura

Ketua Umum

2009-2010

3

UKMI Al-Khuwarizmi

Anggota Bid.

Ristek

2012-2013

4

UKMI Al-Khuwarizmi

Kabid. Aprof

2013-2014

5

Relawan TIK Komisariat USU

Koordinator

Pengkaderan

2013-2014

6

IKLC USU

Anggota pelatihan

dan Pendidikan

2013-2014

7

IKLC USU

Koordinator

Informasi

2013-2015

8

Pema Fasilkom-TI USU

Kadept. Ristek

2014-2015

SEMINARS

No

.

Seminar

Year

1

Seminar BimTek

2010

2

Using Linux

2011

3

Smartfren

2012

4

Seminar Imagine Cup 2013

2012

“I hereby declare that all information above is true and correct to the best of my

knowledge.”

Medan, Desember I8

th

2015

Referensi

Dokumen terkait

“buffer” untuk pengentasan kemiskinan dan pengangguran. Sayangnya, berbagai penelitian sebelumnya menjelaskan bahwa keberadaan usaha jenis ini selain fungsi dan perannya sangat

Murabahah merupakan salah satu bentuk penghimpun dana yang dilakukan oleh perbankan syariah, baik untuk kegiatan usaha. secara umum, nasabah pada perbankan syariah

Ciri- cirinya menurut Worrel dan Stillwell (dalam Song and Hill, 2007) antara lain: (a) tanggung jawab (mereka yang memiliki motivasi belajar merasa bertanggung

Informan Kalau itu sebenarnya kenapa, karena strategi marketnya udah benar kenapa kita masuk pasar LCGC intinya sih secara keseluruhan dulu itu logo Nissan sama dengan logo

Sejarah kajian hadis dari masa ke masa mengalamai perkembangan yang sangat signifikan, mulanya kajian hadis dari lisan ke lisan berkembang menjadi tulisan, perubahan tersebut tak

imunisasi pada penelitian ini didukung oleh penelitian Prusty et al yang menemukan alasan ketidaklengkapan imunisasi anak yang paling banyak diutarakan responden secara

Mahasiswa dapat menganalisis Bagaimana perusahaan dan para pebisnis menanggapi tantangan- tantangan baru terhadap Bisnis dan Etika 2 Kompetensi Dasar : Mahasiswa dapat

ABDUL WAHAB Lulus A SWIBER OFFSHORE PTE LTD Sudah Jadi.. 9 009/KPT/13 SIDIK DIYONO Lulus PRIBADI