function varargout = Redes(varargin)
% REDES MATLAB code for [Link]
% REDES, by itself, creates a new REDES or raises the existing
% singleton*.
%
% H = REDES returns the handle to a new REDES or the handle to
% the existing singleton*.
%
% REDES('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in REDES.M with the given input
arguments.
%
% REDES('Property','Value',...) creates a new REDES or raises the
% existing singleton*. Starting from the left, property value
pairs are
% applied to the GUI before Redes_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to Redes_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 Redes
% Last Modified by GUIDE v2.5 11-Mar-2018 [Link]
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Redes_OpeningFcn, ...
'gui_OutputFcn', @Redes_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 Redes is made visible.
function Redes_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 Redes (see VARARGIN)
% Choose default command line output for Redes
[Link] = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Redes wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Redes_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} = [Link];
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
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.
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 edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as
a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as
a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as
a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in uno.
function uno_Callback(hObject, eventdata, handles)
% hObject handle to uno (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of uno
% --- Executes on button press in dos.
function dos_Callback(hObject, eventdata, handles)
% hObject handle to dos (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of dos
% --- Executes on button press in cuatro.
function cuatro_Callback(hObject, eventdata, handles)
% hObject handle to cuatro (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of cuatro
% --- Executes on button press in tres.
function tres_Callback(hObject, eventdata, handles)
% hObject handle to tres (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of tres
% --- Executes on button press in uno1.
function uno1_Callback(hObject, eventdata, handles)
% hObject handle to uno1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of uno1
% --- Executes on button press in dos1.
function dos1_Callback(hObject, eventdata, handles)
% hObject handle to dos1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of dos1
% --- Executes on button press in cuatro1.
function cuatro1_Callback(hObject, eventdata, handles)
% hObject handle to cuatro1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of cuatro1
% --- Executes on button press in tres1.
function tres1_Callback(hObject, eventdata, handles)
% hObject handle to tres1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of tres1
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Ingreso de texto plano
global Sustitucion
TextPlano=get(handles.edit1,'String');
% Ingreso de sustitucion
Permutacion=get(handles.edit3,'String');
Permutacion=str2num(Permutacion)
disp(TextPlano);
L=length(TextPlano);
%disp(L);
division=L/4;
entero=fix(division);
decimal=100*(division-fix(division));
filas=entero;
Text=TextPlano;
%Rellenar espacios
if decimal==25
disp("25");
b = blanks(3);
Text=[TextPlano,b];
filas=entero+1;
L=L+3;
else if decimal==50
disp("50");
b = blanks(2);
Text=[TextPlano,b];
filas=entero+1;
L=L+2;
else if decimal==75
disp("75");
b = blanks(1);
Text=[TextPlano,b];
filas=entero+1;
L=L+1;
end
end
end
%Alfabeto
A = (32:126);
Alfabeto = char(A);
Alfabeto = reshape(Alfabeto,95,1)'
%Alfabeto m+2
After=Alfabeto((Sustitucion + 1):95);
Before=Alfabeto(1:(Sustitucion));
disp("Alfabeto 2");
Alfabeto2=[After,Before]
%Reordenar en bloque de 4
TextBloque=reshape(Text,[4,filas])'
MTP=size(TextBloque);
filaP=MTP(1,1);
%detectar matriz impar para rellenar
if rem(filaP,2)==0
disp('El número es Par')
TextBloque2=TextBloque;
else
disp('El número es Impar')
z = blanks(4);
filaP=filaP+1;
TextBloque2=[TextBloque;z]
end
for ii=1:filaP
for jj=1:4
for kk=1:95
if TextBloque2(ii,jj)==Alfabeto(1,kk)
TextSustitucion(ii,jj)=Alfabeto2(1,kk);
end
end
end
end
TextSustitucion
for iii=1:filaP
for jjj=1:4
TextPermutacion(iii,jjj)=TextSustitucion(iii,Permutacion(1,jjj));
end
end
TextPermutacion
Encriptacion=TextPermutacion;
for iiii=1:filaP
if rem(iiii,2)==0
Encriptacion([(iiii-1) iiii],:)=Encriptacion([iiii (iiii-1)],:);
end
end
Encriptacion=vec2mat(Encriptacion,filaP*4)
set(handles.text9,'String',char(Encriptacion));
% --- 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)
global Sustitucion
TextEncriptado=get(handles.edit2,'String');
% Ingreso de sustitucion
PermutacionClaveInv=get(handles.edit4,'String');
PermutacionClaveInv=str2num(PermutacionClaveInv)
disp(TextEncriptado);
L2=length(TextEncriptado);
% Reorganizar en bloques de 4
BloqueEncriptado=vec2mat(TextEncriptado,4)
MTP2=size(BloqueEncriptado);
filaP2=MTP2(1,1);
% Cambiar filas de 2 en 2
for x=1:filaP2
if rem(x,2)==0
BloqueEncriptado2([(x-1) x],:)=BloqueEncriptado([x (x-1)],:)
end
end
%Permutacion Inversa
for xx=1:filaP2
for yy=1:4
PermutacionINV(xx,yy)=BloqueEncriptado2(xx,PermutacionClaveInv(1,yy));
end
end
PermutacionINV
% Sustitucion Inversa
%Alfabeto
A = (32:126);
Alfabeto = char(A);
Alfabeto = reshape(Alfabeto,95,1)'
%Alfabeto m+2
After=Alfabeto((Sustitucion + 1):95);
Before=Alfabeto(1:(Sustitucion));
disp("Alfabeto 2");
Alfabeto2=[After,Before]
for ii=1:filaP2
for jj=1:4
for kk=1:95
if PermutacionINV(ii,jj)==Alfabeto2(1,kk)
SustitucionINV(ii,jj)=Alfabeto(1,kk);
end
end
end
end
Desencriptacion=vec2mat(SustitucionINV,filaP2*4)
set(handles.text10,'String',char(Desencriptacion));
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.
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
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
% --- Executes when selected object is changed in uibuttongroup2.
function uibuttongroup2_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uibuttongroup2
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Sustitucion
if hObject== [Link]
Sustitucion=1
elseif hObject== [Link]
Sustitucion=2
elseif hObject== [Link]
Sustitucion=3
elseif hObject== [Link]
Sustitucion=4
end
% --- Executes when selected object is changed in uibuttongroup3.
function uibuttongroup3_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uibuttongroup3
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global Sustitucion
if hObject== handles.uno1
Sustitucion=1
elseif hObject== handles.dos1
Sustitucion=2
elseif hObject== handles.tres1
Sustitucion=3
elseif hObject== handles.cuatro1
Sustitucion=4
end