Skip to main content
. 2024 Feb 5;24(3):1035. doi: 10.3390/s24031035
Algorithm 3: Encrypt(M,WDO){CT}
// Params: message M, attribute weights WDO
// Returns: ciphertext CT
function EncryptMessageWithAttributes(char[] M, int[] WDO) →CT
01: // Select a random number δ from GT to be used as the symmetric encryption key
02: δ = selectRandom(GT)
03: // Encrypt the message M with δ using symmetric encryption E
04: EδM = symmetricEncrypt(δ, M)
05: // Store the encrypted message EδM on IPFS and get the storage address
06: Address_EδM = IPFS.store(EδM)
07: // Step (i): Compute the sum of weights W and select W+1 prime numbers b0 to bW
08: W=sumWDO
09: B= selectPrimes(W+1)
10: // Select a random number β from GFb0
11: β= selectRandom(GFb0)
12: // Encrypt δ using the formula given
13: C=δuβ
14: // Step (ii): Set the attribute weight threshold t and compute μ
15: Y= product(B,1,t) // Product of the first t primes in B
16: A= selectInteger(0, floor(Yb01)
17: μ=β+Ab0
18: // Construct the ciphertext CT
19: CT=A,B,C
20: // Store the ciphertext CT on the blockchain using a regulatory node
21: blockchain.store(CT)
22: // Provide a description of the ciphertext, link it with the attribute category and data storage address
23: blockchain.associate(CT, “description”, “attribute category”, Address_EδM)
24: return CT
endfunction