This the main file for hill cipher

6 visualizaciones (últimos 30 días)
nishant tomar
nishant tomar el 19 de Jul. de 2021
Comentada: DARSHAN S S el 20 de Mzo. de 2023
function [destr] = Hill_Cipher()
message = input('Input Message without spaces: ', 's');
len = length(message);
while f==1
disp('Enter The Key');
for i=1:3
for j=1:3
key(i,j)=input('element-');
end
end
detkey = det(key);
if mod(detkey,2)==0
disp('enter key with odd determinant');
f=1;
else
f=0;
end
end
amessage = double(message);
modlen = mod(len,3);
if mod(len,3) ~= 0
for i=1:3 - mod(len,3)
amessage(1,len+i) = 32;
end
end
bmessage = reshape(amessage, 3, ceil(len/3));
for i=1:ceil((len/3))
for j=1:3
bmessage(j,i)= bmessage(j,i)-33;
end
end
en_message = Encrypt(key,bmessage);
twoen_message = en_message;
for i=1:ceil(len/3)
for j=1:3
en_message(j,i)= en_message(j,i)+33;
end
end
enstr = reshape(char(en_message),1,j*i);
disp(enstr);
de_message = Decrypt(key,twoen_message);
for i=1:ceil(len/3)
for j=1:3
de_message(j,i)= de_message(j,i)+33;
end
end
destr = reshape(char(de_message),1,j*i);
if modlen ~= 0
destr = destr(1:len);
end
end
  2 comentarios
KSSV
KSSV el 19 de Jul. de 2021
Few variables and functions are not defined inside the code. You may learn about it referring this: https://www.geeksforgeeks.org/hill-cipher/
DARSHAN S S
DARSHAN S S el 20 de Mzo. de 2023
f is a non defined fuction

Iniciar sesión para comentar.

Respuestas (1)

DGM
DGM el 19 de Jul. de 2021
uhh okay?
f = 1;
But if you really want my advice, asking the user to input a bunch of things one element at a time using input() is nothing but incredibly tedious and confusing. It's an unnecessary invitation for frustration and error. Functions take arguments. Your function needs two arguments - a char vector and a 3x3 matrix. Take then from the function call instead of pestering the user to retype everything repeatedly.
... and if you don't want spaces in the message, just strip them instead of relying on the input to be perfect.
message = message(message~=' ');

Categorías

Más información sobre Encryption / Cryptography en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by