JHUISI / charm

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

Type casting EC points from str to <class pairing.Element> #233

Closed Billy1900 closed 5 years ago

Billy1900 commented 5 years ago

I was implementing a sample code and face the following problem. P = P1 ** k gave error like left hand operand is not suitable, the issue is I have red the point P1 from a file. When I checked type(P1) it is showing str where as the points like P2=group.rand(G1) shows when used with type.

Can any one help how i can convert the point from str to required type

Billy1900 commented 5 years ago
from charm.toolbox.pairinggroup import PairingGroup, GT
from ac17 import AC17CPABE

def main():
# instantiate a bilinear pairing map
pairing_group = PairingGroup('MNT224')

# AC17 CP-ABE under DLIN (2-linear)
cpabe = AC17CPABE(pairing_group, 2)

# run the set up
(pk, msk) = cpabe.setup()

# generate a key
attr_list = ['ONE', 'TWO', 'THREE']
key = cpabe.keygen(pk, msk, attr_list)

# choose a random message
msg = pairing_group.random(GT)

# generate a ciphertext
policy_str = '((ONE and THREE) and (TWO OR FOUR))'
ctxt = cpabe.encrypt(pk, msg, policy_str)

# decryption
rec_msg = cpabe.decrypt(pk, ctxt, key)
if debug:
    if rec_msg == msg:
        print ("Successful decryption.")
    else:
        print ("Decryption failed.")

if __name__ == "__main__":
    debug = False
    main()

I want to encrypt "hello world" too, how can I convert the msg whose type is str or bytes to pairing.Element?

Billy1900 commented 5 years ago

it solved.

PekeDevil commented 2 years ago

How did you solve this in the end?