L1 LAMPIRAN Lampiran1 :Bitplane.java package com.kevin.stego.service; import android.util.Log; public class Bitplane { private boolean[][] bitplane; private double complexity = -1; private static final boolean[][] conjugator = { {true, false, true, false, true, false, true, false}, {false, true, false, true, false, true, false, true}, {true, false, true, false, true, false, true, false}, {false, true, false, true, false, true, false, true}, {true, false, true, false, true, false, true, false}, {false, true, false, true, false, true, false, true}, {true, false, true, false, true, false, true, false}, {false, true, false, true, false, true, false, true}, }; public Bitplane (boolean[][] bitplane) { this.bitplane = bitplane; } private void countComplexity () { double total = 0; for (int i = 0; i < Bpcs.SIZE; ++i) { for (int j = 0; j < Bpcs.SIZE; ++j) { if (bitplane[i][j]) { if (i - 1 >= 0 && (!bitplane[i - 1][j])) { ++total; } if (i + 1 < Bpcs.SIZE&& (!bitplane[i + 1][j])) { ++total; } if (j - 1 >= 0 && (!bitplane[i][j - 1])) { ++total; } if (j + 1 < Bpcs.SIZE&& (!bitplane[i][j + 1])) { ++total; } } } } complexity = (double)(Math.round((total / 112.d) * 100.d) / 100.d); } L2 public void conjugate () { for (int i = 0; i < Bpcs.SIZE; ++i) { for (int j = 0; j < Bpcs.SIZE; ++j) { if (conjugator[i][j] != bitplane[i][j]) { bitplane[i][j] = true; } else { bitplane[i][j] = false; } } } } public double getComplexity () { if (complexity < 0) { countComplexity(); } return complexity; } public byte[] toBytes () { byte[] bytes = new byte[Bpcs.SIZE]; for (int i = 0; i < Bpcs.SIZE; ++i) { byte b = 0; for (int j = 0; j < Bpcs.SIZE; ++j) { if (bitplane[i][j]) { b |= 128 >> j; } } bytes[i] = b; } return bytes; } public boolean isNoise () { countComplexity(); return this.complexity > Bpcs.THRESHOLD; } public static Bitplane fromByteArray (byte[] bytes) { boolean[][] bitplane = new boolean[Bpcs.SIZE][Bpcs.SIZE]; for (int i = 0; i < Bpcs.SIZE; ++i) { String bin = ""; for (int j = 0; j < Bpcs.SIZE; ++j) { if ((bytes[i] & (128 >> j)) > 0) { bitplane[i][j] = true; bin += "1"; L3 } else { bin += "0"; } } Log.d(bytes[i] + "", bin); } return new Bitplane(bitplane); } } Lampiran 2: BitPlaneSlicing.java package com.kevin.stego.service; public class BitPlaneSlicing { public Bitplane slice (int[][] cgc, int column) { boolean[][] bitplane = new boolean[8][8]; int pointer = 1 << column; for (int i = 0; i < Bpcs.SIZE; ++i) { for (int j = 0; j < Bpcs.SIZE; ++j) { if ((cgc[i][j] & pointer) > 0) { bitplane[i][j] = true; } } } return new Bitplane(bitplane); } } Lampiran 3: BpcsDecoder.java packagecom.kevin.stego.service; importandroid.content.SharedPreferences; importandroid.graphics.Bitmap; importandroid.graphics.Color; public class BpcsDecoder { privateSharedPreferencespref; privatePbcToCgcptc; privateCgcToPbcctp; privateBitPlaneSlicing slicing; privateBitplaneToStringtoString; privateConjugationMapReader reader; publicBpcsDecoder ( SharedPreferencespref, PbcToCgcptc, CgcToPbcctp, BitPlaneSlicing slicing, L4 BitplaneToStringtoString, ConjugationMapReader reader) { this.pref = pref; this.ptc = ptc; this.ctp = ctp; this.slicing = slicing; this.toString = toString; this.reader = reader; } public String decode (Bitmap image) { int colors[] = new int[image.getWidth() * image.getHeight()]; image.getPixels(colors, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight()); String key = ""; for (inti = 0; i<Bpcs.LENGTH; ++i) { key += Color.red(colors[i]); } int[][] pbc = new int[image.getWidth() / (image.getWidth() / 8)][image.getHeight() / (image.getHeight() / 8)]; int[][] cgc = ptc.process(pbc); Bitplane plane = slicing.slice(cgc, 0); reader.read(plane); Bitplane[] planes = new Bitplane[]{plane}; pbc = ctp.convert(pbc, cgc); toString.getString(planes); returnpref.getString(key, "Tidakadapesanrahasiapadagambar."); } static public BpcsDecoder create (SharedPreferencespref) { PbcToCgcptc = new PbcToCgc(); CgcToPbcctp = new CgcToPbc(); BitPlaneSlicing slicing = new BitPlaneSlicing(); BitplaneToStringtoString = new BitplaneToString(); ConjugationMapReader reader = new ConjugationMapReader(); return new BpcsDecoder(pref, ptc, ctp, slicing, toString, reader); } } Lampiran 4: BpcsEncoder.java packagecom.kevin.stego.service; importandroid.graphics.Bitmap; importandroid.graphics.Color; public class BpcsEncoder { privateCgcToPbcctp; privateBitPlaneSlicing slicing; L5 privateBitplaneSwapper swapper; privateStringToBitplanetoBitplane; privatePbcToCgcptc; publicBpcsEncoder ( CgcToPbcctp, BitPlaneSlicing slicing, BitplaneSwapper swapper, StringToBitplanetoBitplane, PbcToCgcptc) { this.ctp = ctp; this.slicing = slicing; this.swapper = swapper; this.toBitplane = toBitplane; this.ptc = ptc; } public Bitmap encode (Bitmap image, String message) { Bitmap encodedImage; byte[] bytes = message.getBytes(); int pixels[] = new int[image.getWidth() * image.getHeight()]; image.getPixels(pixels, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight()); int[][] pbc = new int[pixels.length / (pixels.length / 8)][pixels.length / (pixels.length / 8)]; int[][] cgc = ptc.process(pbc); slicing.slice(pbc, 0); Bitplane[] oldPlanes = new Bitplane[pixels.length / 8]; Bitplane[] newPlanes = toBitplane.create(message); oldPlanes = swapper.swap(oldPlanes, newPlanes); pbc = ctp.convert(pbc, cgc); for (inti = 0; i<bytes.length; ++i) { int a = Color.alpha(pixels[i]); int r = bytes[i]; int g = Color.green(pixels[i]); int b = Color.blue(pixels[i]); pbc[i % pbc.length][0] |= ~32; pixels[i] = Color.argb(a, r, g, b); } encodedImage = Bitmap.createBitmap(pixels, image.getWidth(), image.getHeight(), image.getConfig()); returnencodedImage; } static public BpcsEncoder create () { BitPlaneSlicing slicing = new BitPlaneSlicing(); BitplaneSwapper swapper = new BitplaneSwapper(); L6 StringToBitplanetoBitplane = new StringToBitplane(); CgcToPbcctp = new CgcToPbc(); PbcToCgcptc = new PbcToCgc(); return new BpcsEncoder(ctp, slicing, swapper, toBitplane, ptc); } } Lampiran 5: PbcToCgc.java package com.kevin.stego.service; import android.util.Log; public class PbcToCgc { public PbcToCgc () { } public int[][] process (int[][] pbc) { int cgc[][] = new int[Bpcs.SIZE][Bpcs.SIZE]; for (int i = 0; i < Bpcs.SIZE; ++i) { for (int j = 0; j < Bpcs.SIZE; ++j) { cgc[i][j] = process(pbc[i][j]); } } return cgc; } public int process (int channel) { return (channel ^ (channel >> 1)); } } Lampiran6: CgcToPbc.java package com.kevin.stego.service; public class CgcToPbc { public int[][] convert (int[][] realPbc, int[][] cgc) { for (int i = 0; i < realPbc.length; ++i) { for (int j = 0; j < realPbc[i].length; ++j) { realPbc[i][j] = convert(realPbc[i][j], cgc[i][j]); } } return realPbc; } public int convert (int pbc, int cgc) { return cgc ^ (pbc >> 1); } } L7 Lampiran 7: ConjugationMapReader,java package com.kevin.stego.service; publicclass ConjugationMapReader { publicint read (Bitplane firstBitplane) { byte[] bytes = firstBitplane.toBytes(); return getFirstLine(firstBitplane) | bytes[2] << 8; } publicint getFirstLine (Bitplane plane) { byte[] bytes = plane.toBytes(); return (int)bytes[0]; } } Lampiran 8: StringToBitplane.java packagecom.kevin.stego.service; importjava.util.ArrayList; public class StringToBitplane { publicBitplane[] create (String message) { int length = (int)Math.ceil((float)message.length() / (float)Bpcs.SIZE); Bitplane[] planes = new Bitplane[length]; byte[] old = message.getBytes(); byte[] real = new byte[length * Bpcs.SIZE]; for (inti = 0; i<old.length; ++i) { real[i] = old[i]; } for (inti = 0; i < length; ++i) { planes[i] = Bitplane.fromByteArray(Arrays.copyOfRange(real, i * Bpcs.SIZE, (i + 1) * Bpcs.SIZE)); } return planes; } } Lampiran 9: BitplaneToString.java package com.kevin.stego.service; publicclass BitplaneToString { public String getString (Bitplane[] planes) { String string = ""; for (int i = 0; i < planes.length; ++i) { string += new String(planes[i].toBytes()); } return string; L8 } } Lampiran 10: SdCardImageReader.java packagecom.kevin.stego.service; importjava.io.FileNotFoundException; public class SdCardImageReader { privateContentResolvercontentResolver; publicSdCardImageReader (ContentResolvercontentResolver) { this.contentResolver = contentResolver; } publicArrayList<Uri>getAllImageUris () { ArrayList<Uri>uris = new ArrayList<Uri>(); Cursor cursor = contentResolver.query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor.moveToFirst()) { do { intcolumnIndex cursor.getColumnIndex(MediaStore.Images.Media._ID); intimageId = cursor.getInt(columnIndex); Uri imageUri Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageId + ""); uris.add(imageUri); } while (cursor.moveToNext()); } returnuris; } } Lampiran 11: EncodeActivity.java packagecom.kevin.stego.activity; importjava.io.FileNotFoundException; public class EncodeActivity extends Activity { private Button doEncodeButton; privateEditText message; privateImageViewencodeImage; private Uri imageUri; = = L9 public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.encode); encodeImage = (ImageView)findViewById(R.id.encodeImage); Bundle extras = getIntent().getExtras(); if (extras != null) { imageUri = (Uri)extras.get("imageUri"); encodeImage.setImageURI(imageUri); } doEncodeButton = (Button)findViewById(R.id.doEncodeButton); doEncodeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { EncodeActivityencodeActivity EncodeActivity.this; encodeActivity.validate(); = String message = encodeActivity.message.getText().toString(); // Todo encode the image with bpcs algorithm BpcsEncoder encoder = BpcsEncoder.create(); ContentResolver resolver = encodeActivity.getContentResolver(); InputStream is = null; try { is = resolver.openInputStream(imageUri); } catch (FileNotFoundException e) { } Bitmap image = BitmapFactory.decodeStream(is); Bitmap encodedImage = encoder.encode(image, message); String resultUri = MediaStore.Images.Media.insertImage(resolver, encodedImage, "rand.jpg", "encoded image."); Uri result = Uri.parse(resultUri); int colors[]; try { is = resolver.openInputStream(result); } catch (FileNotFoundException e) { } Bitmap saved = BitmapFactory.decodeStream(is); colors = new int[saved.getWidth() * saved.getHeight()]; L 10 saved.getPixels(colors, 0, saved.getWidth(), 0, 0, saved.getWidth(), saved.getHeight()); SharedPreferences settings = encodeActivity.getSharedPreferences("vinStego", 0); SharedPreferences.Editor editor = settings.edit(); String key = ""; for (inti = 0; i<Bpcs.LENGTH; ++i) { key += Color.red(colors[i]); } Log.d("key", key); editor.putString(key, message); editor.commit(); AlertDialog.Builder builder = new AlertDialog.Builder(EncodeActivity.this); builder.setMessage("Pesanrahasiaberhasil di buat !!") .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); EncodeActivity.this.finish(); } }); builder.create().show(); } catch (MessageEmptyException e) { AlertDialog.Builder builder = AlertDialog.Builder(EncodeActivity.this); builder.setMessage(e.getMessage()) .setCancelable(false) .setPositiveButton("Ok", DialogInterface.OnClickListener() { public onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.create().show(); } } }); } new new void L 11 private void validate () { message = (EditText)findViewById(R.id.message); if (message.getText().toString().equals("")) { throw new MessageEmptyException(); } } } Lampiran 12: DecodeActivity.java package com.kevin.stego.activity; import java.util.ArrayList; public class DecodeActivity extends Activity { LinearLayout imagePlaceholder; TextView selectImageMessage; public void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.select_image); imagePlaceholder (LinearLayout)findViewById(R.id.imagePlaceholder); selectImageMessage (TextView)findViewById(R.id.selectImageMessage); selectImageMessage.setText("Pilih gambar stego :"); SdCardImageReader reader = SdCardImageReader(getContentResolver()); ArrayList<Uri> imageUris = reader.getAllImageUris(); = = new for (final Uri imageUri:imageUris) { ImageView child = new ImageView(this); child.setImageURI(imageUri); imagePlaceholder.addView(child); child.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(DecodeActivity.this, ShowMessageActivity.class); intent.putExtra("imageUri", imageUri); startActivity(intent); } }); } } } L 12 Lampiran 13: bpcs.java package com.kevin.stego.service; publicclass Bpcs { publicfinalstaticintSIZE = 8; publicfinalstaticfloatTHRESHOLD = 0.3f; publicfinalstaticintLENGTH = 128; }