function varargout = gen_klicu(varargin)
% GEN_KLICU M-file for gen_klicu.fig
%      GEN_KLICU, by itself, creates a new GEN_KLICU or raises the existing
%      singleton*.
%
%      H = GEN_KLICU returns the handle to a new GEN_KLICU or the handle to
%      the existing singleton*.
%
%      GEN_KLICU('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GEN_KLICU.M with the given input arguments.
%
%      GEN_KLICU('Property','Value',...) creates a new GEN_KLICU or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gen_klicu_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gen_klicu_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 gen_klicu

% Last Modified by GUIDE v2.5 12-May-2011 19:57:54

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gen_klicu_OpeningFcn, ...
                   'gui_OutputFcn',  @gen_klicu_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 gen_klicu is made visible.
function gen_klicu_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 gen_klicu (see VARARGIN)


set(handles.group,'SelectionChangeFcn',@group_SelectionChangeFcn);
set(handles.group2,'SelectionChangeFcn',@group2_SelectionChangeFcn);
set(handles.group3,'SelectionChangeFcn',@group3_SelectionChangeFcn);%prid8nooooooo
  
    set(handles.RSA,'Visible','on')
    set(handles.DH,'Visible','off')


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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gen_klicu wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.


  


function varargout = gen_klicu_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 edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
        
        input = str2num(get(hObject,'String'));
        if (isempty(input))
             set(hObject,'String','0')
        end
        guidata(hObject, handles);


function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 pushbutton1_Callback(hObject, eventdata, handles)
      
 
 %Vypocet modulu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  modul = str2num(get(handles.edit1,'String'));
  x = modul/2;
  maple('x:=',x);
  maple('y:=2^x');
  maple('z:=2*y');
  maple('aa:=rand(y..z)');
  maple('p:=nextprime(aa())');
  maple('bb:=rand(y..z)');
  maple('q:=nextprime(bb())');
  maple('n:=p*q');
  
  n = maple('n');
  p = maple('p');
  q = maple('q');
  
  set(handles.textn,'String',n);  
  set(handles.textp,'String',p); 
  set(handles.textq,'String',q); 

%   %Vypocet eulerovy funkce
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

maple('fii:=(p-1)*(q-1)');
POM1 = '0';
while POM1 ~= '1'
    maple('cc:=rand(65537..(5*65537))');
    maple('e:=nextprime(cc())');
    POM1 = maple('gcd(e,fii)');
end
    e = maple('e');
    set(handles.texte,'String',e);
   
% %%%%%%%%%%%%%
% %    d      %
% %%%%%%%%%%%%%
   
   
    maple('d:=e&^(-1) mod fii');
    d = maple('d');
    set(handles.textd,'String',d);
  
        
guidata(hObject, handles);



%%%%%%%
%radio
%%%%%%%
function group_SelectionChangeFcn(hObject, eventdata)
 
%retrieve GUI data, i.e. the handles structure
handles = guidata(hObject); 
 
switch get(eventdata.NewValue,'Tag')   % Get Tag of selected object
    case 'radiobutton1'
      set(handles.RSA,'Visible','on')
      set(handles.DH,'Visible','off')
 
    case 'radiobutton2'
      set(handles.RSA,'Visible','off')
      set(handles.DH,'Visible','on')
 
     otherwise
       % Code for when there is no match.
 
end

function group2_SelectionChangeFcn(hObject, eventdata)
 
%retrieve GUI data, i.e. the handles structure
handles = guidata(hObject); 
 
switch get(eventdata.NewValue,'Tag')   % Get Tag of selected object
    case 'radiobutton3'
        modul = 64;
        set(findobj('Tag','edit1'),'String', modul ); 
         
 
    case 'radiobutton4'
      modul = 128;
      set(findobj('Tag','edit1'),'String', modul ); 
      
     case 'radiobutton5'
      modul = 256;
      set(findobj('Tag','edit1'),'String', modul ); 
      
     case 'radiobutton6'
      modul = 512;
      set(findobj('Tag','edit1'),'String', modul ); 
      
      case 'radiobutton7'
      modul = 1024;
      set(findobj('Tag','edit1'),'String', modul ); 
      
      
    
     
     otherwise
       % Code for when there is no match.
 
end


function group3_SelectionChangeFcn(hObject, eventdata)
 
%retrieve GUI data, i.e. the handles structure
handles = guidata(hObject); 
 
switch get(eventdata.NewValue,'Tag')   % Get Tag of selected object
    case 'radiobutton12'
        modul = 64;
        set(findobj('Tag','edit9'),'String', modul ); 
         
 
    case 'radiobutton13'
      modul = 128;
      set(findobj('Tag','edit9'),'String', modul ); 
      
     case 'radiobutton14'
      modul = 256;
      set(findobj('Tag','edit9'),'String', modul ); 
      
     case 'radiobutton15'
      modul = 512;
      set(findobj('Tag','edit9'),'String', modul ); 
      
      case 'radiobutton16'
      modul = 1024;
      set(findobj('Tag','edit9'),'String', modul ); 
      
      
    
     
     otherwise
       % Code for when there is no match.
 
end




function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double

 input = str2num(get(hObject,'String'));
        if (isempty(input))
             set(hObject,'String','0')
        end
        guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (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 edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
 input = str2num(get(hObject,'String'));
        if (isempty(input))
             set(hObject,'String','0')
        end
        guidata(hObject, handles);

function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)

%volba p a g
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
  x_d = str2num(get(handles.edit9,'String'));                         %velikost prvocisla
  maple('x_d:=',x_d);
  maple('y_d:=2^x_d');
  maple('z_d:=2*y_d');
  maple('aa_d:=rand(y_d..z_d)');
  maple('p_d:=nextprime(aa_d())');
  maple('bb_d:=rand(y_d..z_d)');
  maple('g_d:=nextprime(bb_d())');
 
  p_d = maple('p_d');
  g_d = maple('g_d');


  
 set(handles.textd_p,'String',p_d);  
 set(handles.textd_g,'String',g_d);  

 
%volba a b
%%%%%%%%%%%%%%


    maple('a_d:=rand(1..100)');
    maple('b_d:=rand(1..100)');
    

     a_d = maple('a_d()');
    b_d = maple('b_d()');
    set(handles.a,'String',a_d);
    set(handles.b,'String',b_d);

    
    
 %alfa beta
%%%%%%%%%%%%%%

    maple('a_d:=',a_d);
    maple('b_d:=',b_d);
    

    
    alfa = maple('g_d^a_d mod p_d');
    beta = maple('g_d^b_d mod p_d');
    
  

    set(handles.alfa,'String',alfa);  
    set(handles.beta,'String',beta); 
    
%klice
%%%%%%%
    maple('alfa:=',alfa);
    maple('beta:=',beta);

klic_petr = maple('beta^a_d mod p_d');
klic_lucie= maple('alfa^b_d mod p_d');


 set(handles.klic_petr,'String',klic_petr);  
 set(handles.klic_lucie,'String',klic_lucie); 



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (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 edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (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


