Jumat, 19 November 2010
Aplikasi Hill's Substitution dengan Matlab 7.1
Keamanan merupakan suatu kebutuhan manusia, bukan hanya untuk kepentingan kelompok atau perusahaan melainkan juga untuk pengunaan secara individu. Terutama dalam bidang pengamanan informasi di mana kemajuan terjadi dengan begitu cepat. Kriptografi sebagai langkah terakhir dalam pengamanan sangat berperan dalam melindungi kerahasiaan isi dokumen ataupun informasi lainnya. Dengan demikian unsur kerahasiaan suatu informasi dapat dilindungi dari ancaman pihak yang tidak berhak.
Sistem Hills merupakan sistem kriptografi substitusi yang ditemukan oleh Prof. L. S. Hills. Sistem ini menggunakan metode algrebaic linier transformation, yaitu menggunakan sistem persamaan linier untuk mentransformasikan teks terang menjadi teks sandi (enkripsi) maupun sebaliknya (dekripsi). Sistem ini dibagi menjadi 4, yaitu: monographic, digraphic, trigraphic, dan polygraphic. Sistem monographic menggunakan satu persamaan dengan dua variabel dan dua konstanta dalam proses enkripsi dan dekripsi, digraphic dua persamaan dengan empat variabel dan empat konstanta, trigraphic tiga persamaan dengan enam variabel dan enam konstanta, dan sistem polygraphic menggunakan empat persamaan dengan delapan variabel dan delapan konstanta.
Sistem Substitusi Hills Digrafik ini merupakan suatu sistem yang terdiri atas dua persamaan linier, empat variabel (y1,y2,x1, dan x2), dan empat konstanta (a,b,k1,dan k2). Secara umum persamaan liniernya dapat ditulis menjadi :
y1= ax1+k1
y2= bx2+k2
Keterangan : y1= huruf sandi satu
y2= huruf sandi dua
x1= huruf terang satu
x2= huruf terang dua
a = konstanta pengali x1 yang harus bernilai reguler (tidak boleh 0, 13, atau genap)
b= konstanta pengali x2 yang harus bernilai reguler (tidak boleh 0, 13, atau genap)
k1= konstanta bernilai sembarang pada persamaan linier satu
k2= konstanta bernilai sembarang pada persamaan liner dua
Dalam pengerjaannya, sistem ini menggunakan tabel perkalian modulus 26, karena jumlah alfabet hanya sampai 26 huruf. Sebelum dimasukkan ke dalam rumus, kita membangkitkan (generate) alfabet campuran (mixed alphabet) dengan suatu kata kunci terparafrase (huruf kunci yang sama dihilangkan) menggunakan suatu sistem Key Sequence (KS), Simple Columnar Transposition (SCTr), atau Keyed Columnar Transposition (KCTr). Mixed alphabet tersebut kita beri nilai sesuai dengan hasil urutan masing-masing pada suatu sistem tadi.
Teks terang (plain text) atau teks sandi (cipher text) diubah menjadi angka sesuai dengan urutan mix alphabet yang telah digenerate dengan menggunakan sistem KS, SCTr atau KCTr. Setelah itu teks terang atau teks sandi yang telah diubah menjadi angka dimasukkan ke dalam persamaan linier y1 = ax1 +k1 ; y2 = bx2 + k2 , per angka. Sistem ini pada saat menyandi ataupun membuka dilakukan per dua huruf. Setelah mendapatkan angka sandi atau angka terangnya, lalu kita lihat urutan kata kunci yang telah digenerate dengan menggunakan sistem KS, SCTr, ataupun KCTr untuk mendapatkan teks terang atau teks sandinya.
1. Kode Program Menu Utama(main)
function varargout = main(varargin)
% MAIN M-file for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help main
% Last Modified by GUIDE v2.5 30-Jan-2008 20:10:32
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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 next.
function next_Callback(hObject, eventdata, handles)
% hObject handle to next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(main)
registrasi
% --- Executes on button press in exit.
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(main)
button = questdlg('Really wanna exit ??',...
'Muak dengan ini ??','Yes','No','No');
switch button
case 'Yes',
msgbox('Makasih...',...
'Bilang apa?');
case 'No',
main
end
% --- Executes on button press in next.
function next_Callback(hObject, eventdata, handles)
% hObject handle to next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
2. Kode Program Halaman Pertama (hal1)
function varargout = hal1(varargin)
% HAL1 M-file for hal1.fig
% HAL1, by itself, creates a new HAL1 or raises the existing
% singleton*.
%
% H = HAL1 returns the handle to a new HAL1 or the handle to
% the existing singleton*.
%
% HAL1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HAL1.M with the given input arguments.
%
% HAL1('Property','Value',...) creates a new HAL1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hal1_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hal1_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help hal1
% Last Modified by GUIDE v2.5 28-Jan-2007 14:22:53
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hal1_OpeningFcn, ...
'gui_OutputFcn', @hal1_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 hal1 is made visible.
function hal1_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 hal1 (see VARARGIN)
% Choose default command line output for hal1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hal1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hal1_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 pilih.
function pilih_Callback(hObject, eventdata, handles)
% hObject handle to pilih (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(hal1)
hal3
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in encrypt.
function encrypt_Callback(hObject, eventdata, handles)
% hObject handle to encrypt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(hal1)
hal2
3. Kode Program Halaman Kedua (hal2)
function varargout = hal2(varargin)
% HAL2 M-file for hal2.fig
% HAL2, by itself, creates a new HAL2 or raises the existing
% singleton*.
%
% H = HAL2 returns the handle to a new HAL2 or the handle to
% the existing singleton*.
%
% HAL2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HAL2.M with the given input arguments.
%
% HAL2('Property','Value',...) creates a new HAL2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hal2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hal2_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help hal2
% Last Modified by GUIDE v2.5 31-Jan-2008 07:13:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hal2_OpeningFcn, ...
'gui_OutputFcn', @hal2_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 hal2 is made visible.
function hal2_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 hal2 (see VARARGIN)
% Choose default command line output for hal2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hal2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hal2_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;
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of a as text
% str2double(get(hObject,'String')) returns contents of a as a double
a = str2double(get(hObject, 'String'));
if isnan(a)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 b_Callback(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of b as text
% str2double(get(hObject,'String')) returns contents of b as a double
b = str2double(get(hObject, 'String'));
if isnan(b)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 c_Callback(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of c as text
% str2double(get(hObject,'String')) returns contents of c as a double
c = str2double(get(hObject, 'String'));
if isnan(c)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function c_CreateFcn(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 d_Callback(hObject, eventdata, handles)
% hObject handle to d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of d as text
% str2double(get(hObject,'String')) returns contents of d as a double
d = str2double(get(hObject, 'String'));
if isnan(d)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function d_CreateFcn(hObject, eventdata, handles)
% hObject handle to d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 k1_Callback(hObject, eventdata, handles)
% hObject handle to k1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of k1 as text
% str2double(get(hObject,'String')) returns contents of k1 as a double
k1 = str2double(get(hObject, 'String'));
if isnan(k1)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function k1_CreateFcn(hObject, eventdata, handles)
% hObject handle to k1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 k2_Callback(hObject, eventdata, handles)
% hObject handle to k2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of k2 as text
% str2double(get(hObject,'String')) returns contents of k2 as a double
k2 = str2double(get(hObject, 'String'));
if isnan(k2)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function k2_CreateFcn(hObject, eventdata, handles)
% hObject handle to k2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on selection change in pil1.
function pil1_Callback(hObject, eventdata, handles)
% hObject handle to pil1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns pil1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from pil1
% --- Executes during object creation, after setting all properties.
function pil1_CreateFcn(hObject, eventdata, handles)
% hObject handle to pil1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 kk_Callback(hObject, eventdata, handles)
% hObject handle to kk (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of kk as text
% str2double(get(hObject,'String')) returns contents of kk as a double
kk = get(hObject,'String');
% --- Executes during object creation, after setting all properties.
function kk_CreateFcn(hObject, eventdata, handles)
% hObject handle to kk (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 rk1_Callback(hObject, eventdata, handles)
% hObject handle to rk1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rk1 as text
% str2double(get(hObject,'String')) returns contents of rk1 as a double
% --- Executes during object creation, after setting all properties.
function rk1_CreateFcn(hObject, eventdata, handles)
% hObject handle to rk1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 plain_Callback(hObject, eventdata, handles)
% hObject handle to plain (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of plain as text
% str2double(get(hObject,'String')) returns contents of plain as a double
plain = get(hObject,'String');
% --- Executes during object creation, after setting all properties.
function plain_CreateFcn(hObject, eventdata, handles)
% hObject handle to plain (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 cipher_Callback(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of cipher as text
% str2double(get(hObject,'String')) returns contents of cipher as a double
% --- Executes during object creation, after setting all properties.
function cipher_CreateFcn(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in proses.
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)
a = str2double(get(handles.a,'String'));
b = str2double(get(handles.b,'String'));
c = str2double(get(handles.c,'String'));
d = str2double(get(handles.d,'String'));
k1= str2double(get(handles.k1,'String'));
k2= str2double(get(handles.k2,'String'));
plain = get(handles.plain,'String');
kk = get(handles.kk,'String');
tes1 = get(handles.ks,'Value');
tes2 = get(handles.sctr,'Value');
tes3 = get(handles.kctr,'Value');
if tes1 == 1
rk = x(kk);
%set(handles.reskey,'string',rk1);
elseif tes2 == 1
rk = sctrx(kk);
%set(handles.reskey,'string',rk1);
elseif tes3 == 1
rk = kctrx(kk);
%set(handles.reskey,'string',rk1);
end
fprintf('%d\n',k1);
if tes1 == 0 & tes2 == 0 & tes3 == 0
errordlg('Anda belum memilih sistem','Error');
end
set(handles.rk1,'string',rk);
fprintf('%c\n',rk(1));
sandi = encrypt(plain,rk,a,b,c,d,k1,k2);
%cipher = int2str(cipher);
%l = size(sandi);
%sandi = grup(sandi,l);
%sandi = buax(sandi);
set(handles.rk1,'string',rk);
set(handles.cipher,'String', sandi);
% --- Executes on button press in plihan.
function plihan_Callback(hObject, eventdata, handles)
% hObject handle to plihan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(hal2)
button = questdlg('Wanna try it again ??',...
'make ur choice','Yes','No','No');
switch button
case 'Yes',
hal1
case 'No',
msgbox('Makasih...',...
'bilang apa...??');
end
4. Sumber Data Halaman Ketiga (hal3)
function varargout = hal3(varargin)
% HAL3 M-file for hal3.fig
% HAL3, by itself, creates a new HAL3 or raises the existing
% singleton*.
%
% H = HAL3 returns the handle to a new HAL3 or the handle to
% the existing singleton*.
%
% HAL3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HAL3.M with the given input arguments.
%
% HAL3('Property','Value',...) creates a new HAL3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before hal3_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to hal3_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
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help hal3
% Last Modified by GUIDE v2.5 29-Jan-2007 03:05:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @hal3_OpeningFcn, ...
'gui_OutputFcn', @hal3_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 hal3 is made visible.
function hal3_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 hal3 (see VARARGIN)
% Choose default command line output for hal3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes hal3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = hal3_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;
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of a as text
% str2double(get(hObject,'String')) returns contents of a as a double
a = str2double(get(hObject, 'String'));
if isnan(a)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 b_Callback(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of b as text
% str2double(get(hObject,'String')) returns contents of b as a double
b = str2double(get(hObject, 'String'));
if isnan(b)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 c_Callback(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of c as text
% str2double(get(hObject,'String')) returns contents of c as a double
c = str2double(get(hObject, 'String'));
if isnan(c)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function c_CreateFcn(hObject, eventdata, handles)
% hObject handle to c (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 d_Callback(hObject, eventdata, handles)
% hObject handle to d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of d as text
% str2double(get(hObject,'String')) returns contents of d as a double
d = str2double(get(hObject, 'String'));
if isnan(d)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function d_CreateFcn(hObject, eventdata, handles)
% hObject handle to d (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 k1_Callback(hObject, eventdata, handles)
% hObject handle to k1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of k1 as text
% str2double(get(hObject,'String')) returns contents of k1 as a double
k1 = str2double(get(hObject, 'String'));
if isnan(k1)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function k1_CreateFcn(hObject, eventdata, handles)
% hObject handle to k1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 k2_Callback(hObject, eventdata, handles)
% hObject handle to k2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of k2 as text
% str2double(get(hObject,'String')) returns contents of k2 as a double
k2 = str2double(get(hObject, 'String'));
if isnan(k2)
set(hObject, 'String', 0);
errordlg('Input harus bilangan','Error');
end
% --- Executes during object creation, after setting all properties.
function k2_CreateFcn(hObject, eventdata, handles)
% hObject handle to k2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 kk_Callback(hObject, eventdata, handles)
% hObject handle to kk (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of kk as text
% str2double(get(hObject,'String')) returns contents of kk as a double
kk = get(hObject,'String');
% --- Executes during object creation, after setting all properties.
function kk_CreateFcn(hObject, eventdata, handles)
% hObject handle to kk (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 rk1_Callback(hObject, eventdata, handles)
% hObject handle to rk1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of rk1 as text
% str2double(get(hObject,'String')) returns contents of rk1 as a double
% --- Executes during object creation, after setting all properties.
function rk1_CreateFcn(hObject, eventdata, handles)
% hObject handle to rk1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 cipher_Callback(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of cipher as text
% str2double(get(hObject,'String')) returns contents of cipher as a double
% --- Executes during object creation, after setting all properties.
function cipher_CreateFcn(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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 plain_Callback(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of cipher as text
% str2double(get(hObject,'String')) returns contents of cipher as a double
plain = get(hObject,'String');
% --- Executes during object creation, after setting all properties.
function plain_CreateFcn(hObject, eventdata, handles)
% hObject handle to cipher (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in decrypt.
function decrypt_Callback(hObject, eventdata, handles)
% hObject handle to decrypt (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = str2double(get(handles.a,'String'));
b = str2double(get(handles.b,'String'));
c = str2double(get(handles.c,'String'));
d = str2double(get(handles.d,'String'));
k1= str2double(get(handles.k1,'String'));
k2= str2double(get(handles.k2,'String'));
plain = get(handles.plain,'String');
kk = get(handles.kk,'String');
tes1 = get(handles.ks,'Value');
tes2 = get(handles.sctr,'Value');
tes3 = get(handles.kctr,'Value');
if tes1 == 1
rk = x(kk);
%set(handles.reskey,'string',rk1);
elseif tes2 == 1
rk = sctrx(kk);
%set(handles.reskey,'string',rk1);
elseif tes3 == 1
rk = kctrx(kk);
%set(handles.reskey,'string',rk1);
end
fprintf('%d\n',k1);
if tes1 == 0 & tes2 == 0 & tes3 == 0
errordlg('Anda belum memilih sistem','Error');
end
set(handles.rk1,'string',rk);
fprintf('%c\n',rk(1));
sandi = decrypt(plain,rk,a,b,c,d,k1,k2);
%cipher = int2str(cipher);
%l = size(sandi);
%sandi = grup(sandi,l);
sandi = buax(sandi);
set(handles.rk1,'string',rk);
set(handles.cipher,'String', sandi);
% --- Executes on button press in pilihan.
function pilihan_Callback(hObject, eventdata, handles)
% hObject handle to pilihan (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(hal3)
button = questdlg('Mau Lagi ?',...
'Pilih','Yes','No','No');
switch button
case 'Yes',
hal1
case 'No',
msgbox('Thank You',...
'Sayonara');
end
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar