Skip to content

Commit

Permalink
fix(frontend): fixing an issue in the string generation
Browse files Browse the repository at this point in the history
closes #819
  • Loading branch information
bcm-at-zama committed Jul 25, 2024
1 parent d8e36c3 commit b911945
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def dna():

def __init__(self, letters: str):
self.letters = letters
self.mapping_to_int = {}

for i, c in enumerate(self.letters):
self.mapping_to_int[c] = i
Expand Down Expand Up @@ -75,7 +76,10 @@ def random_pick_in_values(self) -> int:

def _random_string(self, length: int) -> str:
"""Pick a random string in the alphabet."""
return "".join([random.choice(list(self.mapping_to_int)) for _ in range(length)])
ans = "".join([random.choice(list(self.mapping_to_int)) for _ in range(length)])
check = [c in self.letters for c in ans]
assert all(check), "Issue in generation"
return ans

def prepare_random_patterns(self, len_min: int, len_max: int, nb_strings: int) -> list:
"""Prepare random patterns of different lengths."""
Expand Down Expand Up @@ -223,18 +227,15 @@ def _compute_in_fhe(self, list_patterns: list, show_distance: bool = False):
# Module FHE
@fhe.module()
class LevenshsteinModule:
@staticmethod
@fhe.function({"x": "encrypted", "y": "encrypted"})
def equal(x, y):
"""Assert equality between two chars of the alphabet."""
return x == y

@staticmethod
@fhe.function({"x": "clear"})
def constant(x):
return fhe.zero() + x

@staticmethod
@fhe.function(
{
"is_equal": "encrypted",
Expand Down

0 comments on commit b911945

Please sign in to comment.