forked from sagrawal87/ABE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (31 loc) · 950 Bytes
/
Copy pathmain.py
File metadata and controls
42 lines (31 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
:Authors: Shashank Agrawal
:Date: 5/2016
'''
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()