CuriousStudent

eccpy

Mar 8th, 2023
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. from random import randint
  2. from unittest import TestCase
  3. from field import FieldElement
  4. from point import Point
  5.  
  6. class ECCTest(TestCase):
  7.  
  8. def test_on_curve(self):
  9. prime = 223
  10. valid_points = ((192, 105), (17, 56), (1, 193))
  11. invalid_points = ((200, 119), (42, 99))
  12. # TODO 1 - Implement a check if the point is on the curve y^2=x^3-7 over F_223:
  13.  
  14.  
  15. def test_add(self):
  16. # tests the following additions on curve y^2=x^3-7 over F_223:
  17. # (192,105) + (17,56)
  18. # (47,71) + (117,141)
  19. # (143,98) + (76,66)
  20. prime = 223
  21.  
  22. additions = (
  23. # (x1, y1, x2, y2, x3, y3)
  24. (192, 105, 17, 56, 170, 142),
  25. (47, 71, 117, 141, 60, 139),
  26. (143, 98, 76, 66, 47, 71),
  27. )
  28.  
  29. # TODO 2 - Implement add on curve y^2=x^3-7 over F_223 with this numbers.
  30. for x1r, y1r, x2r, y2r, x3r, y3r in additions:
  31.  
  32. def test_rmul(self):
  33. # tests the following scalar multiplications
  34. # 2*(192,105)
  35. # 2*(143,98)
  36. # 2*(47,71)
  37. # 4*(47,71)
  38. # 8*(47,71)
  39. # 21*(47,71)
  40. prime = 223
  41.  
  42. multiplications = (
  43. # (coefficient, x1, y1, x2, y2)
  44. (2, 192, 105, 49, 71),
  45. (2, 143, 98, 64, 168),
  46. (2, 47, 71, 36, 111),
  47. (4, 47, 71, 194, 51),
  48. (8, 47, 71, 116, 55),
  49. (21, 47, 71, None, None),
  50. )
  51.  
  52. # iterate over the multiplications
  53. for s, x1_raw, y1_raw, x2_raw, y2_raw in multiplications:
  54. # TODO 3 - Implement rmul on curve y^2=x^3-7 over F_223 with this numbers.
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment