A tiny, focused Python library for Quantitative Information Flow (QIF): model secrets, channels, and analyze leakage via the g-vulnerability framework.
Project description
QIFLib is a Python library for modeling, analyzing, and quantifying information leakage in probabilistic systems using the Quantitative Information Flow (QIF) framework.
It provides a clean, composable set of primitives — secrets, channels, hyper-distributions, vulnerability and uncertainty functions — so you can build end-to-end analyses of how much information an adversary could learn.
For more details see the book The Science of Quantitative Information Flow.
Features
- Secrets Modeling — define hidden states with flexible prior distributions.
- Channels — represent probabilistic mappings $p(y\mid x)$ from secrets to observations.
- Hyper-distributions — automatically compute joint $p(x,y)$, outer $p(y)$, and inners $p(x\mid y)$.
- Vulnerability Analysis — use $g$-vulnerability to quantify an adversary’s expected gain before and after observing outputs.
- Uncertainty Analysis — use $\ell$-uncertainty to measure the expected loss under optimal strategies.
- Leakage Metrics — compute additive and multiplicative leakage.
- Flexible Functions — provide gain/loss as matrices or Python callables.
Why QIF?
Traditional security analysis asks whether a secret can be inferred. QIF quantifies how much an adversary is expected to learn, under probabilistic models of system behavior and strategies.
Useful for:
- privacy-preserving data publishing,
- side-channel analysis,
- communication protocol evaluation,
- decision-making under uncertainty.
Installation
You can install via PyPI:
pip install qiflib
or manuallly by copying this repository to your local machine and running:
pip install path/to/qiflib
To verify if the package was installed correctly, you can run tests:
cd path/to/qiflib
python -m unittest discover tests
Example
from qiflib.core.secrets import Secrets
from qiflib.core.channel import Channel
from qiflib.core.hyper import Hyper
from qiflib.core.gvulnerability import GVulnerability
# Secrets & prior
secrets = Secrets(["x0", "x1"], [0.6, 0.4])
# Channel matrix: rows sum to 1
outputs = ["y0", "y1"]
C = [
[0.8, 0.2], # p(y|x0)
[0.1, 0.9], # p(y|x1)
]
channel = Channel(secrets, outputs, C)
# Hyper-distribution
hyper = Hyper(channel)
# Gain function (1 if correct guess, else 0)
actions = ["guess_x0", "guess_x1"]
def gfun(w, x): return 1.0 if w == x else 0.0
g = GVulnerability(secrets, actions, gfun)
print("Prior vulnerability:", g.prior_vulnerability())
print("Posterior vulnerability:", g.posterior_vulnerability(hyper))
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qiflib-1.0.tar.gz.
File metadata
- Download URL: qiflib-1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533609a864e5a532f7af2959feeb5cfde979d2f654cc4b00b4dc4aff9095a546
|
|
| MD5 |
1bea861670ab04222d490d503a11fff1
|
|
| BLAKE2b-256 |
14cdc5116816fd830ec410c8cd41dffc2fe30e290e2d98ce713379079c27b403
|
File details
Details for the file qiflib-1.0-py3-none-any.whl.
File metadata
- Download URL: qiflib-1.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27e6f2a14b975de112c56111b6555e3d575ffe5b2a8e66d6e115ebb6f45b1552
|
|
| MD5 |
0139fd9ed2340dcdc0724055f838b1e4
|
|
| BLAKE2b-256 |
05e169d36f5fb9b464632315eb9018cf90df2fd8567b5e0d8dc6332650f6a6dc
|