Paillier.cairo
Includes encryption and decryption methods for Paillier's Homomorphic encryption in Cairo
Install / Use
/learn @he-cairo/Paillier.cairoREADME
Paillier's homomorphic cryptosystem in Cairo
Performs Paillier encryption and decryption in Cairo.
Most of the stuff is shamelessly copied from Will Clark's article on blog.openmined.org
Key generation
Key generation is not included in the Cairo code. Key generation works as follows:
- Pick two large prime numbers
pandq, randomly and independently. Confirm thatgcd(pq,(p−1)(q−1))is1. If not, start again.gcd(x,y)outputs the greatest common divisor of x and y.
- Compute
n = pq. - Define function
L(x) = (x − 1) / n. - Compute
lambda, λ aslcm(p−1, q−1).lcm(x,y)outputs the least common multiple of x and y.
- Pick a random integer
gin the set of integers between1andn**2. - Calculate the modular multiplicative inverse mu,
μ = ( L(gλmodn2))−1 mod n. If μ does not exist, start again from step 1. - The public key is
(n, g). Use this for encryption. - The private key is
lambda, λ. Use this for decryption.
Encryption
Encryption works for any m in the range 0 ≤ m < n:
- Pick a random
rin range of0 < r < n - Compute ciphertext
c = g**m * r**n mod n**2
Decryption
For cyphertext c in range of 0 < c < n**2,
For L(x) = (x − 1) / n,
plaintext = L( c**lambda mod n**2 ) * μ mod n
OR plaintext = (c**lambda mod n**2 - 1) / n * μ mod n
Related Skills
node-connect
353.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
