Python-ELMO is a Python library which offers an encapsulation of the binary tool ELMO, in order to manipulate it easily in Python and SageMath script.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

projectclass.py 1.9KB

  1. ### In this file is defined a Python class to manipulate the simualtion project.
  2. ### - This class must be inherited from th class 'SimulationProject' (no need to import it)
  3. ### - You can use here the function "write(input_file, uint, nb_bits=16)"
  4. ### to write an integer of 'nb_bits' bits in the 'input_file' (no need to import it too).
  5. ### To get this simulation class in Python scripts, please use the functions in manage.py as
  6. ### - search_simulations(repository)
  7. ### - get_simulation(repository, classname=None)
  8. ### - get_simulation_via_classname(classname)
  9. class KyberNTTSimulation(SimulationProject):
  10. KYBER_K = 2 #k=2 for Kyber512
  11. KYBER_N = 256 #n=256 for Kyber512
  12. @classmethod
  13. def get_binary_path(cl):
  14. return 'project.bin'
  15. def __init__(self, *args, **kwargs):
  16. super().__init__(*args, **kwargs)
  17. def set_input(self, input):
  18. """ Write into the 'input' file of ELMO tool
  19. the parameters and the challenges for the simulation """
  20. super().set_input(input)
  21. def set_input_for_each_challenge(self, input, challenge):
  22. """ Write into the 'input' file of ELMO tool
  23. the 'challenge' for the simulation """
  24. secret = challenge
  25. # Write the secret vector
  26. for j in range(self.KYBER_K):
  27. for k in range(self.KYBER_N):
  28. write(input, secret[j,k])
  29. def get_test_challenges(self):
  30. import numpy as np
  31. just_ones = np.ones((self.KYBER_K, self.KYBER_N), dtype=int)
  32. return [
  33. 0 * just_ones,
  34. 1 * just_ones,
  35. -2 * just_ones,
  36. ]
  37. def get_random_challenges(self, nb_challenges=5):
  38. import numpy as np
  39. return [ np.random.choice(
  40. [-2, -1, 0, 1, 2],
  41. (self.KYBER_K, self.KYBER_N),
  42. p=[1/16, 4/16, 6/16, 4/16, 1/16],
  43. ) for _ in range(nb_challenges) ]