Coder Social home page Coder Social logo

fhe's Introduction

FHE

Implementation of Encryption and Decryption in Homomorphic Encryption Algorithm.

Used Pyfhel library in python

which includes

  1. BFV Scheme which is more suited for arithmetic on integers and decrypt the exact result.
  2. CKKS Scheme which is more suited for arithmetic on real numbers and give approximate close result. and it also provides bootstrapping for CKKS.

Pyfhel Uses Microsoft SEAL as a Backend.


Object of Pyfhel is Created using

HE = Pyfhel()

Keys are Generated using

HE.keyGen()


For Example let x = 3 and y = 5 in BFV Scheme :-

Cipher text:

cx, cy = obj.encrypt(x=[3], y=[5])

Addition, Multiplication and Subtraction:

csum = cx + cy
cmul = cx * cy
csub = cx - cy

Ciphertext-ciphertext multiplications increase the size of the polynoms representing the resulting ciphertext. To prevent this growth, the relinearization technique is used (typically right after each c-c mult) to reduce the size of a ciphertext back to the minimal size. For this, a special type of public key called Relinearization Key is used.

Initializing Relinearization Key

HE.relinKeyGen()

And to relinearize a multiplication ~ sign is used


Before using ~cmul :- <Pyfhel Ciphertext at 0x1d8043f0840, scheme=bfv, size=3/3, noiseBudget=114>

~cmul

After using ~cmul :- <Pyfhel Ciphertext at 0x1d8043f0840, scheme=bfv, size=2/3, noiseBudget=114>


Decryption :-

BFV Scheme gives exact result

obj.decrypt("csum (cx + cy)", csum)
Decryption of csum (cx + cy) > [8 0 0 ... 0 0 0]

obj.decrypt("csub (cx - cy)", csub)
Decryption of csub (cx - cy) > [-2  0  0 ...  0  0  0]

obj.decrypt("cmul (cx * cy)", cmul)
Decryption of cmul (cx * cy) > [15  0  0 ...  0  0  0]

Example with CKKS Scheme :-

Equation

Encrypt(3xy + x) = Encrypt(3xy) + Encrypt(x) = [3 * Encrypt(x) * Encrypt(y)] + Encrypt(x)

Encryption

cx, cy = obj.encrypt(x=[1.1, 2.2], y=[3.3, 4.4])

3xy = [3 * Encrypt(x) * Encrypt(y)]

_3xy = ~(3 * cx * cy)

Encrypt(3xy + x) = Encrypt(3xy) + Encrypt(x)

eq = _3xy + cx

Decryption :-

obj.decrypt("Equation Result", eq)
Decryption of Equation Result > [ 1.19936477e+01  3.12497888e+01  1.12081209e-06 ...  1.08117709e-05 -1.27877279e-06 -3.55203472e-06]

Decryption of above equation with BFV Scheme (x = 3, y = 5) :-

obj.decrypt("Equation Result", eq)
Decryption of Equation Result > [48  0  0 ...  0  0  0]

fhe's People

Contributors

hemalkavaiya 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.