Coder Social home page Coder Social logo

yash-amin / pysecurecircuit Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 42 KB

pySecureCircuit is a Python library that allows secure multiparty computation using Yao's garbled circuit technique. The library provides a way for multiple parties to securely compute a function on their private inputs without revealing them to each other, using a combination of encryption, randomization, and computation over circuits.

Home Page: https://pypi.org/project/pysecurecircuit/

License: MIT License

Python 100.00%
garbled-circuit python secure-computation

pysecurecircuit's Introduction

pySecureCircuit

pySecureCircuit is a Python library that allows secure multiparty computation using Yao's garbled circuit technique. The library provides a way for multiple parties to securely compute a function on their private inputs without revealing them to each other, using a combination of encryption, randomization, and computation over circuits.

Getting Started

Installation

Run the following command to install the library:

pip install pysecurecircuit

Usage

Here's a simple example of how to use pySecureCircuit for the Millionaire's Problem for two parties.

Write your function logic in a python script.

from pysecurecircuit.circuit import Circuit
from pysecurecircuit.server import Server


def main():
    # Create circuit with 2 party
    circuit = Circuit(name="Millionaires' Problem", num_parties=2)

    # Define input variable
    alice_wealth = circuit.newSecureInteger()
    bob_wealth = circuit.newSecureInteger()

    # Circuit logic
    # 
    # Note:
    # When arithmetic and logical operators are applied to secure datatypes,
    # additional wires and gates are added to the circuit. Magic methods
    # automatically update the circuit based on the operation performed between
    # two secure datatypes, and they return output wires. In the following line
    # of code, the circuit is updated to compare whether `alice_wealth` is greater
    # than `bob_wealth`. The magic method returns an output wire, which is stored
    # in the variable `alice_richer_than_bob`.
    alice_richer_than_bob = alice_wealth > bob_wealth

    # Assign input variables to alice and bob
    circuit.assign_to_party(party_idx=0, name="Wealth (Alice)", variable=alice_wealth)
    circuit.assign_to_party(party_idx=1, name="Wealth (Bob)", variable=bob_wealth)

    # Set circuit's output
    circuit.set_output(name="Alice richer than Bob", variable=alice_richer_than_bob)

    # Start server
    Server(circuit).start()

main()

Server

To start server for the circuit creator run

python3 script.py --host 0.0.0.0 --port PORT

Client

For circuit evaluator, run the following command

python3 -m pysecurecircuit --client-id CLIENT_ID --host HOST --port PORT

Where CLIENT_ID is the identifier of the client that starts from 1, HOST is the IP address or hostname of the server, and PORT is the port number to connect to.

Contributing

Contributions are welcome! If you'd like to contribute to pySecureCircuit, please fork the repository and create a pull request.

Acknowledgments

This library is based on Yao's garbled circuit technique, and builds on existing work in secure multiparty computation. Thank you to the researchers and developers who have contributed to this field.

pysecurecircuit's People

Contributors

yash-amin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.