Modulus of a negative exponent in matlab?
Show older comments
I am basically trying to perform euclidean distance calculation in the encrypted domain (Paillier encryption). Using the homomorphic properties of Paillier, the squared euclidean distance formula can be written as:

I'm having trouble with (III) as matlab wont accept a negative exponent in mod or powermod.
Based on the above equation, Im trying to implement it as follows:
powermod(encA,(-2*vpi(B)), n*n);
mod((encA)^(-2*vpi(B)), n*n);
and am provided with the errors:
D must be a non-negative integer smaller than flintmax.
vpi2bin only works on non-negative vpi integers
How will I make this possible in Matlab?
Thank you
Accepted Answer
More Answers (1)
Sid Parida
on 4 Jun 2018
Edited: Sid Parida
on 4 Jun 2018
Hi Faraz
I believe this function should perform the task you want. I have formatted it according to the powermod function above, except that it accepts negative values for the second argument. The MATLAB Function file is attached.
The usual call case would be:
result = modPow(base, exponent, modulus)
Example cases:
>> result = modPow(2, -1, 7)
result =
4
I am using the Extended Euclidean Algorithm to find the Modular Multiplicative Inverse first and then raising it to the absolute value of the exponent using powermod.
Does this satisfy your use case?
3 Comments
Faraz
on 4 Jun 2018
Sid Parida
on 4 Jun 2018
Hi Faraz
I have updated the script to use the vpi toolbox function modsolve to calculate the inverse. This should fix the error. Please let me know if this works.
Thanks Sid
Faraz
on 5 Jun 2018
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!