Last active
October 29, 2020 11:06
-
-
Save caffeinatedgaze/b7760d6a5e198ae4ca779e100041235f to your computer and use it in GitHub Desktop.
Exercises for lab 3 on EC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import libnum | |
def func(a, x, y, p=37): | |
return ((3 * x ** 2 + a) * libnum.invmod((2 * y), p)) % p | |
def pp(x1, a, b, p=37): | |
y = libnum.sqrtmod_prime_power((math.pow(x1, 3) + a * x1 + b) % p, p, 1) | |
y = list(y) | |
if not y: | |
return | |
# for each in y[0:]: | |
s = func(a, x1, y[0]) | |
x2 = (s ** 2 - 2 * x1) % p | |
y2 = (s * (x1 - x2) - y[0]) % p | |
print(x2, y2) | |
def main(): | |
a = 0 | |
b = 7 | |
p = 37 | |
x = 6 | |
pp(x, a, b, p) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import libnum | |
def generate_100(a, b, p=37, r=100): | |
k = 0 | |
for each in range(p): | |
if k > r: | |
return | |
y = libnum.sqrtmod_prime_power((int(math.pow(each, 3)) + a * each + b) % p, p, 1) | |
try: | |
for another in y: | |
k += 1 | |
print('(' + str(each) + ', ' + str(another) + ')', end=' ') | |
except ValueError as e: | |
pass | |
def main(): | |
a = 5 | |
b = 7 | |
p = 101 | |
generate_100(a, b, p=p) | |
if __name__ == '__main__': | |
main() | |
# (1, 66) (1, 35) (2, 5) (2, 96) (3, 7) (3, 94) (5, 37) (5, 64) (7, 48) (7, 53) (8, 16) (8, 85) (10, 42) (10, 59) (11, 79) (11, 22) (12, 52) (12, 49) (13, 59) (13, 42) (15, 86) (15, 15) (17, 37) (17, 64) (18, 24) (18, 77) (21, 92) (21, 9) (23, 88) (23, 13) (24, 35) (24, 66) (25, 1) (25, 100) (28, 92) (28, 9) (32, 98) (32, 3) (33, 31) (33, 70) (35, 58) (35, 43) (36, 79) (36, 22) (38, 78) (38, 23) (41, 7) (41, 94) (42, 26) (42, 75) (50, 57) (50, 44) (52, 92) (52, 9) (54, 79) (54, 22) (57, 94) (57, 7) (59, 34) (59, 67) (61, 12) (61, 89) (66, 36) (66, 65) (67, 78) (67, 23) (69, 56) (69, 45) (70, 19) (70, 82) (72, 97) (72, 4) (75, 73) (75, 28) (76, 35) (76, 66) (77, 1) (77, 100) (78, 42) (78, 59) (79, 37) (79, 64) (81, 54) (81, 47) (82, 27) (82, 74) (86, 71) (86, 30) (87, 83) (87, 18) (88, 88) (88, 13) (89, 80) (89, 21) (91, 88) (91, 13) (94, 72) (94, 29) (95, 8) (95, 93) (97, 78) (97, 23) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import libnum | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def generate_100(a, b, p=37, r=100): | |
k = 0 | |
x, _y = [], [] | |
for each in range(p): | |
if k > r: | |
break | |
y = libnum.sqrtmod_prime_power((int(math.pow(each, 3)) + a * each + b) % p, p, 1) | |
try: | |
for another in y: | |
k += 1 | |
x.append(each) | |
_y.append(another) | |
except ValueError as e: | |
pass | |
return x, _y | |
def main(): | |
a = 5 | |
b = 7 | |
p = 101 | |
x, y = generate_100(a, b, p=p) | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
ax.set_xlabel('x') | |
ax.set_ylabel('y') | |
ax.set_title('ECC Points') | |
ax.scatter(x, y, color='r') | |
plt.show() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment