0
%%%CODE:
clc;
disp('Implementation of ELGAMAL Digital Signature');
clear all;
close all;
%%Hardcoded values (vpi stands for VariablePrecisionIntegers, and are used to store large values)
g = vpi(5) %alpha in example
k = vpi(9) %Random number 1<k<p-1 and gcd(k, p − 1) = 1.
p = vpi(23) %Prime Number
x = vpi(3) %Secret Key 1 < x < p − 1
m = vpi(7) %Message
y = vpi(2)
r = vpi(2)
s = vpi(2)
%%Key Generation
y = powermod(g,x,p) %y = g^x mod p
%%Signature Generation
r = powermod(g,k,p) %r = g^k mod p
multinver = mulinv(9,23) %Generates multiplicative inverse k^-1 mod p
s = mod(((multinver)*(m-x*r)),p-1) %s = (k^-1)*(m-x*r) mod p-1
%%Verification
zvg = vpi(2);
zvg = powermod (g,m,p) %zvg = g^m mod p
zvyr = vpi(2);
zvyr = mod(((y^r)*(r^s)),p) %zvyr = y^r * r^s mod p
輸出:爲什麼在MATLAB中實現的Elgamal數字簽名算法無法正常工作?
Implementation of ELGAMAL Digital Signature
g = 5
k = 9
p = 23
x = 3
m = 7
y = 2
r = 2
s = 2
y = 10
r = 11
multinver = 18
s = 16
zvg = 17
zvyr = 5
zvg
應該等於zvyr
,但它的到來了錯誤。