Skip to content

Commit

Permalink
flat_shamir_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
programmingAthlete committed Dec 1, 2023
1 parent bf6c27d commit fe5fff1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/crypto_VDF/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import hashlib


def square_sequences(a: int, steps: int, n: int) -> int:
"""
Modular exponentiation
Expand Down Expand Up @@ -72,3 +75,14 @@ def base_to_10(numb: [int], base: int) -> int:
for i in range(len(numb)):
base_10 += numb[::-1][i] * base ** i
return base_10


def concat_hexs(*args):
hexs = [hex(item)[2:] for item in args]
return int(''.join(hexs), 16)


def flat_shamir_hash(x: int, y: int) -> int:
i = hex(x)[2:] + hex(y)[2:]
h = hashlib.sha256(bytes.fromhex(i)).hexdigest()
return int(h, 16)
9 changes: 7 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from crypto_VDF.utils.utils import exp_modular, square_sequences
from crypto_VDF.utils.utils import exp_modular, square_sequences, concat_hexs


class TestUtils(unittest.TestCase):
Expand All @@ -19,4 +19,9 @@ def test_squaring_sequence(self):
res = square_sequences(2, 4, 3)
self.assertEqual(res, 1)


def test_concat_hexs(self):
x1 = 1
x2 = 2
res = concat_hexs(1, 2)
h1, h2 = hex(x1)[2:], hex(x2)[2:]
self.assertEqual(int(h1+h2, 16), res)

0 comments on commit fe5fff1

Please sign in to comment.