1 LAMPIRAN A: SOURCE CODE PROGRAM CLASS METODE package steganalisis; import java.io.ioexception; public class Metode { public String bitmapinputname; ...
LAMPIRAN A: SOURCE CODE PROGRAM CLASS METODE package steganalisis; import java.io.IOException; public class Metode { public String bitmapInputName; public String bitmapOutputName; public int[] buffer; public int panjangPesan; public String pesan; public int bitmapMsgSize; public String bitmapMsg; private int c, j, p; private int hasil; private int posisi; public void EnhancedLSB() throws IOException { Bitmap bmpimg = new Bitmap(); bmpimg.readBitmapFile(this.bitmapInputName); int[] data = bmpimg.getPixelData(); for(int i = 0, n = data.length; i < n; i++) { int curData = bmpimg.getCurrentByte(i); int newCurData = this.cekLSB(curData); bmpimg.setCurrentByte(i, newCurData); } bmpimg.saveBitmapFile(this.bitmapInputName + "analysis.bmp"); } private int cekLSB(int aData) { if (aData % 2 == 0) { return 0; } else { return 255; } } public String Ekstraksi() throws IOException { Bitmap bmpimg = new Bitmap(); bmpimg.readBitmapFile(this.bitmapInputName); buffer = bmpimg.getPixelData(); posisi = 0; panjangPesan = 0; // ambil panjang pesan for (j = 0; j < 8; j++) { this.ambilPanjangPesan(); } pesan = ""; for (int i = 0; i < panjangPesan && posisi < buffer.length; i++) {
Universitas Sumatera Utara
this.bacaPesan(); } return pesan; } private void ambilPanjangPesan() { int t = buffer[posisi]; // data bitmap di posisi yg sesuai int bit = ((t & 1) == 1 ? 1 : 0); // apakah bit ke-j bernilai 1 atau 0 panjangPesan += bit << j; ++posisi; // ke posisi berikutnya } private void bacaPesan() { char karakter = 0; for (j = 0; j < 8 && posisi < buffer.length; j++) { int t = buffer[posisi]; // data bitmap di posisi yg sesuai int bit = ((t & 1) == 1 ? 1 : 0); // apakah bit ke-j bernilai 1 atau 0 karakter += bit << j; ++posisi; // ke posisi berikutnya } pesan += karakter; } public boolean apakahBitmap24BitNoCompress() throws IOException { Bitmap bmpimg = new Bitmap(); bmpimg.readBitmapFile(this.bitmapInputName); int[] buf = bmpimg.buffer; //bitmap BM if (buf[0x0] == 0x42 && buf[0x1] == 0x4D) { // bitmap 24bit int bitPerPiksel = buf[0x1C] + (buf[0x1D] << 8); if (bitPerPiksel == 24) { //bitmap tidak terkompresi if ((buf[0x1E] + (buf[0x1F] << 8) + (buf[0x20] << 16) + (buf[0x21] << 24)) == 0) { //bitmap tdk terkompresi return true; } else { //bitmap terkompresi return false; } } else { // bitmap bukan 24 bit return false; } } else { // bukan bitmap return false; } } public boolean SisipLSB() throws IOException { Bitmap bmpImg = new Bitmap();
Universitas Sumatera Utara
bmpImg.readBitmapFile(this.bitmapInputName); buffer = bmpImg.getPixelData(); int imgSize = bmpImg.bfSize; int curP = 0; if((bitmapMsgSize*8+8) <= imgSize) { //simpan panjang pesan for (j = 0, p = 0; j < 8 && p < buffer.length; j++, p++){ this.sisipPanjangPesan(); int aData = hasil; bmpImg.setCurrentByte(p, aData); ++curP; //ke posisi berikutnya } for (int i = 0; i < bitmapMsgSize; i++) { // 1 karakter pada pesan, terdiri dari 8 bit c = bitmapMsg.charAt(i); // 8 bit pada 1 karakter pesan tersebut ditempatkan ke dalam 8 byte data bitmap for (j = 0, p = curP; j < 8 && p < buffer.length; j++, p++) { this.sisipPesan(); int aData = hasil; // tulis ke BMP output bmpImg.setCurrentByte(p, aData); ++curP; // ke posisi berikutnya } } bmpImg.saveBitmapFile(this.bitmapOutputName); return true; } else { // tempat tidak cukup return false; } } private int sisipPanjangPesan() { int t = buffer[p]; // data bitmap di posisi yg sesuai int bit = ((bitmapMsgSize & (1 << j)) == (1 << j) ? 1 : 0); // apakah bit ke-j bernilai 1 atau 0 hasil = (bit == 1 ? (t | 0x1) : (t & (0xFF << 1))); // sisipkan ke LSB return hasil; } private int sisipPesan() { int t = buffer[p]; // data bitmap di posisi yg sesuai int bit = ((c & (1 << j)) == (1 << j) ? 1 : 0); // apakah bit ke-j pada pesan bernilai 1 atau 0 hasil = (bit == 1 ? (t | 0x1) : (t & (0xFF << 1))); // sisipkan ke LSB return hasil; } }
Universitas Sumatera Utara
LAMPIRAN B: SOURCE CODE PROGRAM CLASS BITMAP package steganalisis; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Bitmap { FileInputStream fin; FileOutputStream fout; int[] buffer; int[] biHeader; int[] bfHeader; int[] bufData; // Bitmap file header int bfSize; public void getFileHeader() { bfSize = buffer[0x2] + (buffer[0x3] << 8) + (buffer[0x4] << 16) + (buffer[0x5] << 24); bfHeader = new int[14]; for(int a = 0, b = 14; a < b; a++) { bfHeader[a] = buffer[a]; } } public void getInfoHeader() { biHeader = new int[40]; for(int a = 14, b = 54, c = 0; a < b; a++, c++) { biHeader[c] = buffer[a]; } } public int[] getPixelData() { bufData = new int[buffer.length - 54]; for(int a = 54, b = buffer.length, c = 0; a < b; a++, c++) { bufData[c] = buffer[a]; } return bufData; } public void setFileHeader() throws IOException { for(int a = 0, b = bfHeader.length; a < b; a++) { fout.write(bfHeader[a]); } } public void setInfoHeader() throws IOException { for(int a = 0, b = biHeader.length; a < b; a++) { fout.write(biHeader[a]); }
Universitas Sumatera Utara
} public void setPixelData() throws IOException { for(int a = 0, b = bufData.length; a < b; a++) { fout.write(bufData[a]); } } public int getCurrentByte(int ke) { int hasil = bufData[ke]; return hasil; } public void setCurrentByte(int ke, int newData) { bufData[ke] = newData; } public void readBitmapFile(String inputName) throws IOException { fin = new FileInputStream(inputName); buffer = new int[fin.available()]; for (int a = 0, b = buffer.length; a < b; a++) { buffer[a] = fin.read(); } getFileHeader(); getInfoHeader(); getPixelData(); if (fin != null) { fin.close(); } fin = null; } public void saveBitmapFile(String outputName) throws IOException { fout = new FileOutputStream(outputName); setFileHeader(); setInfoHeader(); setPixelData(); if (fout != null) { fout.close(); } fout = null; } }