?? elgencrypt.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 + -