Implementasi Algoritma Vernam Cipher dalam Skema Three-Pass Protocol untuk Pengamanan Citra Bitmap Berbasis Android

A-1

LISTING PROGRAM
Menu Proses
package com.example.skripsii;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

java.io.File;
java.io.FileInputStream;
java.io.FileNotFoundException;

java.io.FileOutputStream;
java.io.IOException;
java.io.OutputStreamWriter;
java.text.SimpleDateFormat;
java.util.ArrayList;
java.util.Date;
java.util.Random;
android.app.Activity;
android.app.AlertDialog;
android.content.DialogInterface;
android.content.Intent;
android.database.Cursor;
android.graphics.Bitmap;
android.graphics.Bitmap.Config;
android.graphics.BitmapFactory;
android.graphics.Color;
android.graphics.drawable.BitmapDrawable;
android.net.Uri;
android.os.Bundle;
android.os.Environment;

android.provider.MediaStore;
android.util.Log;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.ImageView;
android.widget.Toast;

public class Sender extends Activity implements
View.OnClickListener {
public int SELECT_PICTURE = 1;
public String selectedImagePath;
public double mse1,psnr1;
ArrayList kunci1,kunci2;
ImageView img, imgc1, imgc2, imgc3, imgdekrip;
Bitmap bmp;
Integer baris,kolom;
EditText nama, size1, size2, mse, psnr;

Button btn_pilih, btn_kunci1, btn_kunci2, btn_proses1,
btn_proses2, btn_proses3, btn_dekrip, btn_reset;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sender);
img = (ImageView)findViewById(R.id.image_pilih);
imgc1 = (ImageView)findViewById(R.id.img_c1);
imgc2 = (ImageView)findViewById(R.id.img_c2);

Universitas Sumatera Utara

A-2

imgc3 = (ImageView)findViewById(R.id.img_c3);
imgdekrip = (ImageView)findViewById(R.id.img_dekripsi);
nama = (EditText)findViewById(R.id.et_nama);
size1 = (EditText)findViewById(R.id.et_size1);
size2 = (EditText)findViewById(R.id.et_size2);
mse = (EditText)findViewById(R.id.et_mse);

psnr = (EditText)findViewById(R.id.et_psnr);
btn_pilih = (Button)findViewById(R.id.button_pilih);
btn_pilih.setOnClickListener(this);
btn_kunci1 = (Button)findViewById(R.id.button_kpengirim);
btn_kunci1.setOnClickListener(this);
btn_kunci2 = (Button)findViewById(R.id.button_kpenerima);
btn_kunci2.setOnClickListener(this);
btn_proses1 = (Button)findViewById(R.id.button_c1);
btn_proses1.setOnClickListener(this);
btn_proses2 = (Button)findViewById(R.id.button_c2);
btn_proses2.setOnClickListener(this);
btn_proses3 = (Button)findViewById(R.id.button_c3);
btn_proses3.setOnClickListener(this);
btn_dekrip = (Button)findViewById(R.id.button_dekripsi);
btn_dekrip.setOnClickListener(this);
btn_reset = (Button)findViewById(R.id.button_reset);
btn_reset.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
nama.setText(selectedImageUri.toString());
try {
File f = new File(selectedImagePath);
bmp = BitmapFactory.decodeStream(new
FileInputStream(f));
if (f.getPath().endsWith(".bmp")) {
img.setImageBitmap(bmp);
}
else {
nama.setText("");
size1.setText("");

size2.setText("");
img.setImageBitmap(null);
Toast.makeText(getBaseContext(), "Silahkan
pilih gambar dengan ekstensi .bmp",
Toast.LENGTH_SHORT).show();
}
Integer x = bmp.getWidth();
Integer y = bmp.getHeight();

Universitas Sumatera Utara

A-3

size1.setText(x.toString());
size2.setText(y.toString());
if ((bmp.getWidth() > 1000) && (bmp.getHeight() >
1000 )) {
nama.setText("");
size1.setText("");
size2.setText("");

img.setImageBitmap(null);
Toast.makeText(getBaseContext(), "Resolusi Gambar
diatas 1000x1000 piksel, silahkan pilih gambar
yang lebih kecil dari 1000x1000 piksel",
Toast.LENGTH_SHORT).show();
}
}
catch (FileNotFoundException e){
e.printStackTrace();
}
}
}
}
public String getPath(Uri uri) {
if( uri == null ) {
return null;
}
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null,
null, null);

if( cursor != null ){
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Medi
a.DATA);
cursor.moveToFirst();
String path = cursor.getString(column_index);
cursor.close();
return path;
}
return uri.getPath();
}
public void onClick(View v) {
if (v == btn_pilih) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Sele
ct Picture"), SELECT_PICTURE);
}
else if(v == btn_kunci1)

{
kunci1 = new ArrayList();
Random rand = new Random();
Bitmap bitmap =
((BitmapDrawable)img.getDrawable()).getBitmap();
for(int i=0; i