To implement the SPQ protocol, we integrated all the functionalities developed from the pre- vious algorithms. The SPQ protocol’s output will be evaluated such that, let T be the threshold value, f(ED)= 0 if ED ≤ T 1 if ED > T.
Depending on the threshold value and the size of the sequence we implement the key generation algorithm. For example, if the threshold value is 30, then ED ≤ 30 implies that patients are similar. Let the length of the sequence be 100, then we generate a binary sequence of the form
9.3. Performance Evaluation of SPQ 73
:
[0] ∗ 30+ [1] ∗ 70.
We use section 4.1 and algorithm 2 to generate p, which will be the secret key of Okamoto- Uchiyama cryptosystem. At first the encryption function will be applied directly by the querier by importing the cryptosystem. Here all the public and private keys are generated before even running the application. The crucial step in SPQ protocol is implementation of protocol for secure computation of Euclidean distance. For implementing this, we relied on pandas data frames in python. The querier’s input will be read iteratively across the entire string and three encryptions for each string are generated in each iteration. This is sent to the hospital, which then performs addition homomorphically. Then we multiply it with alpha and add β homomorphically. The entire result is raised to a random r2c | rc
R
←− Z2k, which is homomorphic multiplication that can be evaluated upon decryption.
The protocol implementation has three algorithms:
• section 9.3.2 is the algorithm for User encryption for implementing the protocol for se- cure computation of Euclidean distance
• In the algorithm presented in section 9.3.2, Hospital chooses the relevant cipher text based on the indices and performs homomorphic addition, converting the cipher text c to αc + β and then re-randomizing it by multiplying with r2
c.
• The algorithm displayed in section 9.3.2 consists of User Decryption and applying eval- uation function to find if Euclidean distance is ≤ threshold value.
User SPQ
In this step the user will contain a plain text query ∈ {0, 1, 2}n. The user will input the query
into algorithm in section 9.3.2. The algorithm will scan across each value in the user’s query and will encrypt the related bit from table 8.1 , that way for each bit 3 different encryptions are produced based on the table 8.1. All of these are stored in an array named res. Now the user sends this res array, along with files containing the public key modulus n, g values the hospital in separate files as comma separated values.
Input: Pre-computed Euclidean Distance Values in Plain text, input query sequence,pk, OkamotoUchiyama.enc
Output: For each bit in query sequence, encrypted Euclidean distance combinations- Encr
Lookup ←[[0, 1, 4], [1, 0, 1], [4, 1, 0]] function spqencrypt(query, pk)
c ← OkamotoUchiyama.enc(pk, query) return c end function function spquser(query) for n ∈ query do d f ← int(n) end for res ←[[ ]] for i ∈ d f do for x ∈ Lookup[i] do data ← spqencrypt(x, pk) res.append(data) end for end for return res end function Algorithm 3: User SPQ Hospital SPQ
Presented in section 9.3.2, this algorithm the hospital receives three files related to res, n, g and the RS ID of particular gene locations. Using these files the hospital will now calculate the Euclidean distance as per the Secure ED protocol. In the first step, the hospital will form an empty array to store the Encrypted Euclidean Distance values denoted as EED in section 9.3.2. Now we read across each file in the database held by the hospital. In every single patient file,
9.3. Performance Evaluation of SPQ 75
we compile the necessary sequence based on the RS IDs and these sequences will be used for comparison. For each patient, we pick one sequence. In the beginning of search through every patient’s sequence we form an empty array titled arr. Now we iterate through every single sequence and using the sequence value and the iteration step, we form the column and row re- spectively of the encrypted results. For example if we are in second row and the sequence value with hospital is 2, we pick the value at location res[2][2] in res array. That way for each se- quence, we form a complete array filled with differences of squares. Now we homomorphically sum this array for obtaining the Euclidean distance by taking the prod value of entire array. We take the encrypted sum for each individual record and blind it by homomorphically multiplying α and adding β. To do this, we raise the EncryptedSum to plain text α (mod n) using the pow function in python. This is the fastest implementation of exponentiation (mod n). Where as, to homomorphically add β, we need to encrypt β first and then perform multiplication of cipher texts. We then re-randomizing using some r2, where r ∈ Zn. This way, EEDs of all the patients
Input: RSIDs, res - the Encrypted Euclidean distance combinations that were outputted from section 9.3.2, n, g, α, β, OkamotoUchiyama.enc, hospital database
Output: Encrypted Euclidean Distance
Encr ← res
function spqhosp(hospdata) EED ←[ ]
for seq ∈ hospdata do df ←[int(i) for i ∈ seq] arr ←[[ ]] for j ∈ len(df ) do data ← encr[ j][d f [ j]] arr.append(data) end for pk ← n, g EncryptedSum ← math.prod(arr)
ct= (EncryptedSum)(α)· (enc(β)) (mod n) r←− {1, 2, 3, ...., n}R c0 ← ctr2 (mod n) EED.append(c0) end for return EED end function Algorithm 4: Hospital SPQ
User Decryption and Evaluation
As presented in section 9.3.2 this is the final step in the protocol where the user receives a file full of re-randomized Encrypted Euclidean Distance values that were calculated between the user query and all the patients in the hospital database. User applies Dec and retrieves the plain