splash.java BuatPesan.java

LAMPIRAN A : LISTING PROGRAM

1. splash.java

import android.app.Activity; import android.os.Bundle; import android.content.Intent; import android.content.pm.ActivityInfo; import android.view.Window; public class Splash extends Activity { protected int splash_ = 1000; Override protected void onCreateBundle savedInstanceState { super.onCreatesavedInstanceState; this.requestWindowFeatureWindow.FEATURE_NO_TITLE; setContentViewR.layout.activity_splash; getSupportActionBar.hide; setRequestedOrientationActivityInfo.SCREEN_ORIENTATION_PORTRAIT; setSplash; } public void setSplash { new Thread { public void run { try { Thread.sleep2000; } catch Exception e { } Intent i = new IntentSplash.this, MainActivity.class; Splash.this.finish; startActivityi; } }.start; } }

2. BuatPesan.java

import android.app.Activity; import android.content.ContentValues; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.telephony.SmsManager; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.util.Random; public class BuatPesan extends Activity { EditText nomorKontak, text, hasilencrypt, kunci_p_enk, kunci_q_enk, kuncihill_enk, hasilencryptkunci; TextView pubkey, nilaiK; contact picker private static final int CONTACT_PICKER_RESULT = 1001; private long waktumulaihill, waktuakhirhill, selisihhill, waktumulairabin; phonecontact public void doLaunchContactPickerView view { Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; Universitas Sumatera Utara Intent contactPickerIntent = new IntentIntent.ACTION_PICK, uri; startActivityForResultcontactPickerIntent, CONTACT_PICKER_RESULT; } protected void onActivityResultint requestCode, int resultCode, Intent data { String phone = ; Cursor contacts = null; try { if resultCode == RESULT_OK { switch requestCode { case CONTACT_PICKER_RESULT: gets the uri of selected contact Uri result = data.getData; get the contact id from the Uri last part is contact id String id = result.getLastPathSegment; queries the contacts DB for phone no contacts = getContentResolver.query ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone._ID + =?, new String[]{id}, null; gets index of phone no int phoneIdx = contacts.getColumnIndexPhone.DATA; if contacts.moveToFirst { gets the phone no phone = contacts.getStringphoneIdx; EditText phoneTxt = EditText findViewByIdR.id.nomorHp; assigns phone no to EditText field phone number phoneTxt.setTextphone; } else { Toast.makeTextthis, error, Toast.LENGTH_LONG.show; } break; } } else { gracefully handle failure Toast.makeTextBuatPesan.this, R.string.belumdipilih, Toast.LENGTH_SHORT.show; } } catch Exception e { Toast.makeTextthis, e.getMessage, Toast.LENGTH_LONG.show; } finally { if contacts = null { contacts.close; } } } public String toBinarylong n { if n == 0 { return 0; } String binary = ; while n 0 { long rem = n 2; binary = rem + binary; n = n 2; } return binary; } public long toDecimallong binary { long decimal = 0; long power = 0; while true { if binary == 0 { break; } else { Universitas Sumatera Utara long temp = binary 10; decimal += temp Math.pow2, power; binary = binary 10; power++; } } return decimal; } public boolean fermatint p { boolean hasil = true; Random rand = new Random; int a = rand.nextInt20 + 1; if a p == 0 { hasil = false; } else if modExpa, p - 1, p = 1 { hasil = false; } return hasil; } public static int modExpint a, int b, int n { if b == 0 return 1; long t = modExpa, b 2, n; long c = t t n; if b 2 == 1 c = c a n; return int c; } Override public void onCreatefinal Bundle savedInstanceState { super.onCreatesavedInstanceState; this.setTitleEncrypt Message; setContentViewR.layout.buatpesan; final Button send = Button findViewByIdR.id.send; final Button encrypt = Button findViewByIdR.id.encrypt; final Button encryptkunci = Button findViewByIdR.id.encryptkunci; text = EditText findViewByIdR.id.smsBox; nomorKontak = EditText findViewByIdR.id.nomorHp; hasilencrypt = EditText findViewByIdR.id.hasilEncrypt; hasilencryptkunci = EditText findViewByIdR.id.hasilEncryptkunci; kunci_p_enk = EditText findViewByIdR.id.kunci_p_enk; kunci_q_enk = EditText findViewByIdR.id.kunci_q_enk; kuncihill_enk = EditText findViewByIdR.id.KunciHill_enk; pubkey = TextView findViewByIdR.id.pubkey; nilaiK = TextView findViewByIdR.id.Kvalues; Intent i = getIntent; if i.getStringExtramessage = null { text.setTexti.getStringExtramessage; } encryptkunci.setOnClickListenernew OnClickListener { Override public void onClickView arg0 { TODO Auto-generated method stub waktumulairabin = System.currentTimeMillis; String enkunciaes = ; String keyx = kuncihill_enk.getText.toString; String p = kunci_p_enk.getText.toString; String q = kunci_q_enk.getText.toString; try { if TextUtils.isEmptykeyx { kuncihill_enk.setErrorYour key is Empty; } else if TextUtils.isEmptyp { kunci_p_enk.setErrorPrivate Keys cannot Empty; } else if TextUtils.isEmptyq { kunci_q_enk.setErrorPrivate Keys cannot Empty; } else if p.matches[0-9] { kunci_p_enk.setErrorPrivate Keys must be a Number; Universitas Sumatera Utara } else if q.matches[0-9] { kunci_q_enk.setErrorPrivate Keys must be a Number; } else if p.equalsq { kunci_p_enk.setErrorPrivate Keys must be Different; } else if fermatInteger.parseIntp { kunci_p_enk.setErrorPrivate Key must be a Prime Number; } else if fermatInteger.parseIntq { kunci_q_enk.setErrorPrivate Key must be a Prime Number; } else if Integer.parseIntp 4 = 3 { kunci_p_enk.setErrorPrivate Keys must have modulus 3 when devide by 4; } else if Integer.parseIntq 4 = 3 { kunci_q_enk.setErrorPrivate Keys must have modulus 3 when devide by 4; } else { long startTime = System.currentTimeMillis; int uvw = Integer.parseIntp; int xyz = Integer.parseIntq; long publickey = uvw xyz; pubkey.setTextpublic key : + publickey; tabelEnc obj1 = new tabelEnc; for int i = 0; i keyx.length; ++i { Toast.makeTextgetApplicationContext, ke: +i+ms, Toast.LENGTH_LONG.show; char b = keyx.charAti; int plain = tabelEnc.getIndexb; String double_text = toBinaryplain + toBinaryplain; long double_dectext = Long.parseLongdouble_text; long m = toDecimaldouble_dectext; long k = m - m publickey publickey; nilaiK.setTextnilaiK.getText + + k; SimpanKunci.setKkeyString.valueOfk; long c = long Math.powm, 2 publickey; SimpanKunci.setCipherkeyString.valueOfc; hasilencryptkunci.setTexthasilencryptkunci.getText + + c; } obj2 = new simpanVariabel; long endTime = System.currentTimeMillis; long duration = endTime - startTime; Toast.makeTextgetApplicationContext, Encryption Time: + duration + ms, Toast.LENGTH_LONG.show; } } catch Exception e1 { Toast.makeTextBuatPesan.this, enkunciaes, Toast.LENGTH_LONG.show; e1.printStackTrace; } hasilencryptkunci.setTextenkunciaes; } }; encrypt.setOnClickListenernew OnClickListener { Override public void onClickView e { String ambilKata = text.getText.toString; String kunci_enk_hill = kuncihill_enk.getText.toString; String enKata = ; try { if kuncihill_enk.getText.toString.equals || text.getText.toString.equals { Toast.makeTextBuatPesan.this, Pesan ataupun kunci tidak boleh kosong, Toast.LENGTH_SHORT.show; } else { String hasil1=null; Universitas Sumatera Utara waktumulaihill = System.currentTimeMillis; hillCipher obj = new hillCipher; double sq = Math.sqrtkunci_enk_hill.length; System.out.printlnini double + sq + ini long + long sq + ini int + int sq; if sq = long sq System.out.printlnpanjang kunci salah; 0+3TLeT9[I.MV5hk1zz mOTRQBU else { int s = int sq; if obj.checkkunci_enk_hill, s { System.out.printlnResult:; obj.divideambilKata, s; pakai kunci ASCII dari 32-126 System.out.printlnini ya guys : + obj.hasilenkripsi; Log.iKata Asal, ambilKata; enKata = obj.hasilenkripsi; Log.iKata Hasil, enKata; obj.cofactobj.keymatrix, s; System.out.printinversi key + obj.invkey; } } hasilencrypt.setTextenKata; waktuakhirhill = System.currentTimeMillis; selisihhill = waktuakhirhill - waktumulaihill; Toast.makeTextBuatPesan.this, lama enkripsi Hill Cipher + Long.toStringselisihhill, Toast.LENGTH_SHORT.show; } } catch Exception e1 { e1.printStackTrace; } } }; send.setOnClickListenernew OnClickListener { public void onClickView v { String pesan = hasilencrypt.getText.toString; String nomor = nomorKontak.getText.toString; if pesan.length 0 nomor.length 0 { try { proses kirim sms SmsManager sms = SmsManager.getDefault; sms.sendTextMessagenomor, null, pesan, null, null; proses simpan sms yang terkirim ContentValues values = new ContentValues; values.putaddress, nomor; values.putbody, pesan; getContentResolver.insert Uri.parsecontent:smssent, values; Toast.makeTextBuatPesan.this, Pesan berhasil dikirim, Toast.LENGTH_SHORT .show; finish; } catch Exception e { Toast.makeTextBuatPesan.this, Pesan gagal dikirim, Toast.LENGTH_SHORT.show; e.printStackTrace; } } else { Toast.makeTextBuatPesan.this, Nomor atau Isi Pesan Masing Kosong, Toast.LENGTH_SHORT.show; } } }; } } Universitas Sumatera Utara

3. LihatPesan.java