JHUISI / charm

Charm: A Framework for Rapidly Prototyping Cryptosystems
http://charm-crypto.io
GNU Lesser General Public License v3.0
541 stars 166 forks source link

How to do logarithm operation in PairingGroup #281

Open Artemisl opened 2 years ago

Artemisl commented 2 years ago

In my project, I want to do a logarithm operation. But it will report an error message "TypeError : must be real number, not pairing.Element".

r = group.random(ZR) math.log( r, g )

I don't know how to transform the pairing.Element to real number or integer. Does anyone have the same problem?

alejandro-imt commented 2 years ago

I assume you are using pairinggroup:

Just explicitly convert the ZR element to an int.

from charm.toolbox.pairinggroup import PairingGroup, ZR 
import math

r = group.random(ZR)
base = 10 # or whatever you need
int_r = int(r)
log_r = math.log(int_r, base)