File size: 3,806 Bytes
55931d5
3092881
d2c12fb
eabd74d
55931d5
 
 
65df51c
 
790b5f0
21527ce
65df51c
 
4f03df5
 
72e86f6
8421130
790b5f0
4f03df5
55931d5
72e86f6
e00bc68
72e86f6
3092881
72e86f6
 
 
55931d5
72e86f6
55931d5
72e86f6
 
24b6be0
55931d5
72e86f6
ca4d4cf
 
 
 
55931d5
72e86f6
 
 
ca4d4cf
 
72e86f6
ca4d4cf
72e86f6
 
d8483f8
aa98dc4
9d3f042
 
60ee97d
9d3f042
24b6be0
aa98dc4
55931d5
72e86f6
 
 
21527ce
aa98dc4
f0c62c3
24b6be0
81e50b0
0b150f9
aa98dc4
a304763
 
 
 
 
d2c12fb
a304763
d2c12fb
6a8c329
 
d2c12fb
6a8c329
 
 
 
 
 
 
a304763
de8bb2c
a304763
2ed8131
65267b4
2ed8131
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import gradio as gr
from phe import paillier


# Generate Paillier keypair
public_key, private_key = paillier.generate_paillier_keypair(n_length=1024)


def secure_encoding(input_data):
    # print intro 
   
    # Print raw input_data
    
    print("Raw Input Data:", input_data)

    # Convert input data to a list
    data = input_data.split(',')
    
    print("Processed Input Data:", data)

    # Encode data
    encoded_data = [1 if val == "smoker" else 0 for val in data]
    print("Encoded Data:", encoded_data)

    # Encrypt and send to cloud
    print("Encrypting data and send to cloud...")
    print("===================================")

    encrypted_data = [public_key.encrypt(x) for x in encoded_data]

    print("Third party only sees encrypted data and cannot figure out the nature of the data or encoding")
    print("=========================================")
    print("Encrypted Ciphertext based on paillier looks like this -> :", encrypted_data[0].ciphertext())

    # Perform homomorphic addition to count smokers
    encrypted_count = encrypted_data[0]
    
    for i in range(1, len(encrypted_data)):
        encrypted_count += encrypted_data[i]

    # Output encrypted count
    print("Result is also encrypted")
    print("========================")
    print("Encrypted Count:", encrypted_count)
      
    # Send result to the data owner
    decrypted_count = private_key.decrypt(encrypted_count)
    print("Send result to the data owner")
    print("Decrypted Count:", decrypted_count)

    return (
        f"Raw data (only data owner has access to the plain text): {data}",
        f"Encrypted Ciphertext: {encrypted_data[0].ciphertext()}",
        f"Run encrypted private query processing and generate encrypted result: {encrypted_count}",
        f"Decrypted Result: {decrypted_count}",
        "Data processing is complete. The encrypted count have been generated."
    )

# Gradio Interface
iface = gr.Interface(
    fn=secure_encoding,
    inputs=gr.Textbox("smoker,non-smoker,smoker,smoker", placeholder="Enter data (e.g., smoker,non-smoker)"),
    outputs=[
        gr.Textbox("text", label="Raw data"),
        gr.Textbox("text", label="Encrypted data -- using private key"),
        gr.Textbox("text", label="Encrypted Result -- not readable by the third party without the private key"),
        gr.Textbox("text", label="Decrypted Result -- total numbers of smokers in this DB")
    ],
    title="Privacy Preserving Encrypted Query Demonstration",
    
     description="""
This demonstration showcases a method for analyzing sensitive data while protecting individual privacy. It uses Paillier encryption (partial homomorphic) and , a powerful technique that allows calculations on encrypted data without revealing the actual values.

## Welcome to DNAsafe demo!

### Why is this important?

- Privacy Protection: Analyzing personal data often raises privacy concerns. This method keeps individual data private even while performing calculations, like counting the number of "smokers" in a dataset.
- Secure Collaboration: Sensitive data can be analyzed jointly by multiple parties without anyone directly accessing the raw data and the result. Only authorized stakeholders and data owner have access to the private key that allows them to see the raw text.
- Cloud Computing: This approach enables secure analysis on cloud platforms, leveraging their computing power without jeopardizing data privacy.

Watch the demo to see:

* How Paillier encryption works to conceal data values.
* How encrypted data can be processed and analyzed (e.g., counting smokers).
* How the final results are obtained while maintaining privacy.

Press the submit button with the suggested values here. 
""",
)

# Display the image and then launch the Gradio app
iface.launch()