⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elgencrypt.m

📁 elgamal elgrithm by matlab
💻 M
字号:
function ciphertext = ELGencrypt(p,Alpha,Betaa,m)global y1 y2 % This function encrypts the message typed by the sender using the % public key Betaa the primitive root Alpha and the large prime p.% Get the message lengthmessage_length = numel(m);% Convert all characters in the message to number and store in mnum_arrayn = 1;j = 2;mnum = '';% For the first character, we don't need any zero infront of the number (if the number is less than 10)h =text2int1(m(1));mnum_array(1) = h;% For the rest of the message, if the number is less than 10 we need to put 0 in front of that numbern= 2;while (j <= message_length)  h = text2int1(m(j));  if ( h <= 9 )    mnum_array(n) = 0;    mnum_array(n+1) = h;    n = n + 2;  else    mnum_array(n) = h;    n = n + 1;  end;  j = j + 1;end;% Put every values in the array together and assign to variable mnum (numberic message)mnum_array_length = numel(mnum_array);for n=1:mnum_array_length,mnum = strcat(mnum,num2str(mnum_array(n)));end;maple('mnum:=',mnum);mnum_length = numel(mnum);% Compare mnum with p. If mnum is greater than p then set flag to 1
p_length = numel(p);flag = 0;if (mnum_length == p_length)   for index=1: p_length,     if(mnum(index) > p(index))        flag = 1;        break;     end;   end;   end;           if(mnum_length > p_length)      flag =1;end;  % If mnum is greater than p, display the error messageif(flag ==1)   disp('The message is too long, please make it shorter.')% If mnum is less than p, do the encryption processelse   % Generate random integer k   maple('k:=','rand()');   k = maple('k');      % Calculate y1   maple('y1:=','Alpha&^k mod p');   y1 = maple('y1')   % Calculate y2   maple('y2:=','((Betaa&^k)*mnum) mod p');   y2 = maple('y2')end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -