I have a function that generates cipher text for ElGamal encryption and I want to make return two values, but it returns only one. This is the code:
elgamalencrypt[m_, p_, g_, h_] := Module[{k, r, t},
SeedRandom[];
k = RandomInteger[{2,p-2}];
r = PowerMod[g,k,p] ;
t = Mod[Power[h,k]*m,p] ;
Return [{r,t},Module];
]
I tried modifying the Return statement to:
Return [{r,t}]
and
Return [r,t]
, but I was keep getting an error about not enclosing the function, also tried this Break::nofunc Continue::nofunc Return::nofunc
from documentation with no luck. If someone wants to try it out this is a test scenario:
plaintext = toblocks["whataboutsecondbreakfast",3]
this divides the plain text into blocks
{230801,200102,152120,190503,151404,21805,11106,11920}
output
{p, g, h} = getelgamalpublickey[33]
generate the values for the public key
{22822153,8469268,20935791}
output
ciphertext =Map[elgamalencrypt[#,p,g,h]&,plaintext]
and finally the encryption of each block
{18627519,22660971,10034668,14492011,14579397,12595172,4596731,20282426}
output
In the last output I want to have both r and t as result, how can I achieve that?
toblocks
; though, here, it does not seem to be entirely necessary. $\endgroup$plaintext
andp,g,h
as you describe (but gives different results). Can you try this with a fresh kernel? Nevertheless, as mikado shows the finalReturn
is not needed in Mathematica, and it is best practice to avoid it. $\endgroup$