Marquee

WELCOME TO MY KINGDOM!! ENJOY :D

Laman

20 Desember 2011

Steganografi


Steganografi adalah seni dan ilmu komunikasi dengan menyembunyikan inti komunikasi. Tujuan steganografi adalah menyembunyikan pesan ke dalam pesan lainnya dengan maksud tidak mengizinkan pihak asing untuk mendeteksi keberadaan pesan rahasia. Pada file gambar, pesan dapat disembunyikan dengan menyisipkan pada bit rendah (LSB) di dalam data pixel yang menyusun file gambar.

Pada tugas kali ini, akan dijelaskan pembuatan steganografi menggunakan matlab yang terdiri dari proses menyisipkan pesan ke dalam gambar dan proses mengekstrak pesan dari gambar.


1.  Proses Menyisipkan Pesan ke Gambar


Di bawah ini adalah kodingannya:

Koding:
function varargout = Sisipan(varargin)
% SISIPAN MATLAB code for Sisipan.fig
%      SISIPAN, by itself, creates a new SISIPAN or raises the existing
%      singleton*.
%
%      H = SISIPAN returns the handle to a new SISIPAN or the handle to
%      the existing singleton*.
%
%      SISIPAN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SISIPAN.M with the given input arguments.
%
%      SISIPAN('Property','Value',...) creates a new SISIPAN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Sisipan_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Sisipan_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Sisipan

% Last Modified by GUIDE v2.5 19-Dec-2011 12:45:49

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Sisipan_OpeningFcn, ...
                   'gui_OutputFcn',  @Sisipan_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Sisipan is made visible.
function Sisipan_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Sisipan (see VARARGIN)

% Choose default command line output for Sisipan
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Sisipan wait for user response (see UIRESUME)
% uiwait(handles.figsisipan);


% --- Outputs from this function are returned to the command line.
function varargout = Sisipan_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in btnstego.
function btnstego_Callback(hObject, eventdata, handles)
% hObject    handle to btnstego (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.GbrAsli,'Userdata');
pesan=get(proyek.listbox1,'Userdata');

pesan=[pesan 'QQQQ'];
% 'QQQQ' tanda akhir dari suatu pesan
teksbin=str2bin(pesan);
gbr2=stegolsb(I,teksbin);

set(proyek.figsisipan,'CurrentAxes',proyek.GbrStego);
set(imshow(gbr2));
set(proyek.GbrStego,'Userdata',gbr2);

% --- Executes on button press in btnsimpangbr.
function btnsimpangbr_Callback(hObject, eventdata, handles)
% hObject    handle to btnsimpangbr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
[namafile,direktori]=uiputfile('*.bmp','Simpan Gambar');
gbr2=get(proyek.GbrStego,'Userdata');
imwrite(gbr2,namafile);

% --- Executes on button press in btnbukagbr.
function btnbukagbr_Callback(hObject, eventdata, handles)
% hObject    handle to btnbukagbr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata (gcbo);
[namafile,direktori]=uigetfile({'*.jpg';'*.bmp';...
    '*.png';'*.tif'}, 'Buka Gambar');
I=imread(namafile);
set (proyek.figsisipan,'CurrentAxes',proyek.GbrAsli);
set (imshow(I));
set (proyek.GbrAsli,'Userdata',I);

% --- Executes on button press in btnbukateks.
function btnbukateks_Callback(hObject, eventdata, handles)
% hObject    handle to btnbukateks (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
[namafile,direktori]=uigetfile('*.txt','Buka Teks');
teks=fopen(namafile,'r');
charteks=fread(teks,'uint8=>char');
fclose(teks);
pesan=sprintf(charteks);

set(proyek.listbox1,'string',pesan);
set(proyek.listbox1,'Userdata',pesan);

% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function proses_Callback(hObject, eventdata, handles)
% hObject    handle to proses (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function sisipan_Callback(hObject, eventdata, handles)
% hObject    handle to sisipan (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function ekstraksi_Callback(hObject, eventdata, handles)
% hObject    handle to ekstraksi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
ekstrak

% --------------------------------------------------------------------
function brshgbr_Callback(hObject, eventdata, handles)
% hObject    handle to brshgbr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
set(proyek.figsisipan,'CurrentAxes',proyek.GbrStego);
cla;
set(proyek.figsisipan,'CurrentAxes',proyek.GbrAsli);
cla;

% --------------------------------------------------------------------
function brshteks_Callback(hObject, eventdata, handles)
% hObject    handle to brshteks (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
pesan='';
set(proyek.listbox1,'string',pesan);

% --------------------------------------------------------------------
function keluar_Callback(hObject, eventdata, handles)
% hObject    handle to keluar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pilihan=questdlg(['Anda yakin keluar dari aplikasi',...
    get(handles.figsisipan,'Name'),'?'],...
    ['Konfirmasi Tutup'],'Ya','Tidak','Ya');

if strcmp(pilihan,'Tidak')
    return;
end
delete(handles.figsisipan);
Penjelasan :

Fungsi fopen berguna untuk membuka suatu file yang natinya bisa digunakan untuk membaca, menulis, atau menyisipkan teks. Tanda ‘r’ berarti membaca (read). Variabel ‘teks’ merupakan keluaran fungsi fopen yang berupa data dalam format biner. Agar dapat dimengerti oleh pengguna pada umumnya, data biner diubah ke dalam data karakter. Caranya adalah dengan menggunakan fungsi fread(teks, ’uint8=>char’). Variabel ’pesan’ merupakan keluaran fungsi fread dan berupa matriks yang berisi karakter. Karena data yang akan ditampilkan pada listbox harus berformat string, kita menggunakan fungsi sprint. Fungsi sprintf  digunakan untuk menulis format data ke dalam bentuk string. Perlu diingat bahwa file yang sudah dibuka (fopen) harus ditutup kembali dengan menggunakan fclose.

Fungsi get() digunakan untuk mengambil data dari properti userdata pada suatu uicontrol.
Pesan=[pesan ’QQQQ’];
[] artinya string yang termuat dalam variabel pesan digabung dengan string ’QQQQ’.
String ’QQQQ’ digunakan sebagai petunjuk akhir suatu pesan. Diasumsikan tidak ada pesan yang memuat kata QQQQ.

Fungsi uiputfile() merupakan suatu fungsi yang memanggil kotak dialog untuk menyimpan file dengan format tertentu. Fungsi imwrite(gbr2,namafile) digunakan untuk menuliskan citra ke dalam file grafik.

 2.  Proses Mengekstrak Pesan Dari Gambar
Di bawah ini adalah kodingannya:
Koding:
function varargout = Ekstrak(varargin)
% EKSTRAK MATLAB code for Ekstrak.fig
%      EKSTRAK, by itself, creates a new EKSTRAK or raises the existing
%      singleton*.
%
%      H = EKSTRAK returns the handle to a new EKSTRAK or the handle to
%      the existing singleton*.
%
%      EKSTRAK('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EKSTRAK.M with the given input arguments.
%
%      EKSTRAK('Property','Value',...) creates a new EKSTRAK or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Ekstrak_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Ekstrak_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Ekstrak

% Last Modified by GUIDE v2.5 19-Dec-2011 13:04:03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Ekstrak_OpeningFcn, ...
                   'gui_OutputFcn',  @Ekstrak_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Ekstrak is made visible.
function Ekstrak_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Ekstrak (see VARARGIN)

% Choose default command line output for Ekstrak
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Ekstrak wait for user response (see UIRESUME)
% uiwait(handles.figekstrak);


% --- Outputs from this function are returned to the command line.
function varargout = Ekstrak_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in btnekstrak.
function btnekstrak_Callback(hObject, eventdata, handles)
% hObject    handle to btnekstrak (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
I=get(proyek.GbrStego,'Userdata');

teksbin=ekstraklsb(I);
set(proyek.listbox1,'String',teksbin);
set(proyek.listbox1,'Userdata',teksbin);

% --- Executes on button press in btnsimpanteks.
function btnsimpanteks_Callback(hObject, eventdata, handles)
% hObject    handle to btnsimpanteks (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
[namafile,direktori]=uiputfile('*.txt','Simpan Pesan');

teks=fopen(namafile,'w');
pesan=get(proyek.listbox1,'Userdata');
fprintf(teks,pesan);
fclose(teks);

% --- Executes on button press in btnbukagambar.
function btnbukagambar_Callback(hObject, eventdata, handles)
% hObject    handle to btnbukagambar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata (gcbo);
[namafile,direktori]=uigetfile('*.bmp','Load Gambar');
I=imread(namafile);
set (proyek.figekstrak,'CurrentAxes',proyek.GbrStego);
set (imshow(I));
set (proyek.GbrStego,'Userdata',I);

% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject    handle to file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function sisipan_Callback(hObject, eventdata, handles)
% hObject    handle to sisipan (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
sisipan;

% --------------------------------------------------------------------
function ekstraksi_Callback(hObject, eventdata, handles)
% hObject    handle to ekstraksi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function brshgbr_Callback(hObject, eventdata, handles)
% hObject    handle to brshgbr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
proyek=guidata(gcbo);
set(proyek.figekstrak,'CurrentAxes',proyek.GbrStego);
cla;

% --------------------------------------------------------------------
function brshteks_Callback(hObject, eventdata, handles)
% hObject    handle to brshteks (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function keluar_Callback(hObject, eventdata, handles)
% hObject    handle to keluar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
pilihan=questdlg(['Anda yakin keluar dari aplikasi',...
    get(handles.figekstrak,'Name'),'?'],...
    ['Konfirmasi Tutup'],'Ya','Tidak','Ya');

if strcmp(pilihan,'Tidak')
    return;
end
delete(handles.figekstrak);
Penjelasan:


Fungsi ekstraklsb merupakan fungsi M-File yang dirancang untuk mengekstrak LSB setiap pixel citra agar diperoleh bit-bit pesan

Fungsi bin2str() digunakan untuk mengubah bilangan biner ASCII menjadi string. Idenya adalah mengubah bilangan biner menjadi bilangan decimal (menggunakan fungsi bin2dec). Kemudian, bilangan desimal diubah menjadi string (menggunakan fungsi char).

Penulisan string ke dalam suatu file teks (TXT) dilakukan dengan menyediakan suatu file kosong untuk ditulis, yaitu menggunakan perintah:
Teks=fopen(namafile, ‘w’);
Kemudian, untuk menulis data string ke dalam file kita menggunakan perintah:
            Fprinf(teks, pesan);
Setelah file ditulis, file teks harus ditutup kembali dengan perintah:
            Fclose(teks);


Output Akhir :
Proses Menyisipkan Pesan Ke Gambar



Proses Mengekstrak Pesan Dari Gambar




Tidak ada komentar:

Posting Komentar