Skip to content

Commit

Permalink
Add doctest/example that compares result to in-the-clear distance cal…
Browse files Browse the repository at this point in the history
…culation.
  • Loading branch information
lapets committed Dec 7, 2023
1 parent 6f404ba commit 144604b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ Finally, the party interested in authenticating itself can broadcast its origina
>>> reveal(shares) # Floating point results may differ slightly.
0.43375208257785347
The above result can be compared to that of a calculation that uses the original descriptors. The results are exactly equivalent due to the conversion from floating point values to a fixed-point representation during masking:

.. code-block:: python
>>> import math
>>> math.sqrt(sum([(x - y)**2 for (x, y) in zip(reg_descriptor, auth_descriptor)]))
0.43378989435406744
Development
-----------
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
Expand Down
12 changes: 11 additions & 1 deletion src/tinybio/tinybio.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,17 @@ class node(tinynmc.node):
between the registration and authentication descriptors.
>>> shares = [node.authenticate(reg_token, auth_token) for node in nodes]
>>> abs(reveal(shares) - 0.43) <= 0.05 # Use comparison for floating point value.
>>> result = reveal(shares)
The tests below confirm that the computed result is indeed the Euclidean
distance.
>>> abs(result - 0.43) <= 0.05 # Use comparison for floating point value.
True
>>> abs(result - math.sqrt(sum(
... (x - y) ** 2
... for (x, y) in zip(reg_descriptor, auth_descriptor)
... ))) <= 0.05
True
"""
def authenticate(
Expand Down

0 comments on commit 144604b

Please sign in to comment.