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.

260 lines
4.8 KiB

  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "id": "f890e69f",
  7. "metadata": {},
  8. "outputs": [],
  9. "source": [
  10. "q = pow(2,255) - 19"
  11. ]
  12. },
  13. {
  14. "cell_type": "code",
  15. "execution_count": 2,
  16. "id": "d90a7f0b",
  17. "metadata": {},
  18. "outputs": [
  19. {
  20. "data": {
  21. "text/plain": [
  22. "37095705934669439343138083508754565189542113879843219016388785533085940283555"
  23. ]
  24. },
  25. "execution_count": 2,
  26. "metadata": {},
  27. "output_type": "execute_result"
  28. }
  29. ],
  30. "source": [
  31. "d = ((q - 1) * (121665 * pow(121666, -1, q)) % q)\n",
  32. "d"
  33. ]
  34. },
  35. {
  36. "cell_type": "code",
  37. "execution_count": 3,
  38. "id": "1b2aebc5",
  39. "metadata": {},
  40. "outputs": [
  41. {
  42. "data": {
  43. "text/plain": [
  44. "46316835694926478169428394003475163141307993866256225615783033603165251855960"
  45. ]
  46. },
  47. "execution_count": 3,
  48. "metadata": {},
  49. "output_type": "execute_result"
  50. }
  51. ],
  52. "source": [
  53. "y = 4 * pow(5, -1, q) % q\n",
  54. "y"
  55. ]
  56. },
  57. {
  58. "cell_type": "code",
  59. "execution_count": 4,
  60. "id": "aae2f8bf",
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "data": {
  65. "text/plain": [
  66. "15112221349535400772501151409588531511454012693041857206046113283949847762202"
  67. ]
  68. },
  69. "execution_count": 4,
  70. "metadata": {},
  71. "output_type": "execute_result"
  72. }
  73. ],
  74. "source": [
  75. "x = 0x216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A\n",
  76. "x"
  77. ]
  78. },
  79. {
  80. "cell_type": "code",
  81. "execution_count": 5,
  82. "id": "ea9a4d90",
  83. "metadata": {},
  84. "outputs": [
  85. {
  86. "data": {
  87. "text/plain": [
  88. "26187595835145689230469591415084376402084551887632582719101735842039498021991"
  89. ]
  90. },
  91. "execution_count": 5,
  92. "metadata": {},
  93. "output_type": "execute_result"
  94. }
  95. ],
  96. "source": [
  97. "x_squared = x^2 % q\n",
  98. "x_squared"
  99. ]
  100. },
  101. {
  102. "cell_type": "code",
  103. "execution_count": 6,
  104. "id": "3499c817",
  105. "metadata": {},
  106. "outputs": [
  107. {
  108. "data": {
  109. "text/plain": [
  110. "37053468555941182535542715202780130513046395093004980492626426882532201484768"
  111. ]
  112. },
  113. "execution_count": 6,
  114. "metadata": {},
  115. "output_type": "execute_result"
  116. }
  117. ],
  118. "source": [
  119. "y_squared = y^2 % q\n",
  120. "y_squared"
  121. ]
  122. },
  123. {
  124. "cell_type": "code",
  125. "execution_count": 7,
  126. "id": "d9617d2d",
  127. "metadata": {},
  128. "outputs": [
  129. {
  130. "data": {
  131. "text/plain": [
  132. "10865872720795493305073123787695754110961843205372397773524691040492703462777"
  133. ]
  134. },
  135. "execution_count": 7,
  136. "metadata": {},
  137. "output_type": "execute_result"
  138. }
  139. ],
  140. "source": [
  141. "((q - 1) * x_squared + y_squared) % q"
  142. ]
  143. },
  144. {
  145. "cell_type": "code",
  146. "execution_count": 8,
  147. "id": "ece46a74",
  148. "metadata": {},
  149. "outputs": [
  150. {
  151. "data": {
  152. "text/plain": [
  153. "10865872720795493305073123787695754110961843205372397773524691040492703462777"
  154. ]
  155. },
  156. "execution_count": 8,
  157. "metadata": {},
  158. "output_type": "execute_result"
  159. }
  160. ],
  161. "source": [
  162. "((d * x_squared * y_squared) % q + 1) % q"
  163. ]
  164. },
  165. {
  166. "cell_type": "code",
  167. "execution_count": 9,
  168. "id": "b430f926",
  169. "metadata": {},
  170. "outputs": [
  171. {
  172. "data": {
  173. "text/plain": [
  174. "21711016731996786641919559689128982722488122124807605757398297001483711807481"
  175. ]
  176. },
  177. "execution_count": 9,
  178. "metadata": {},
  179. "output_type": "execute_result"
  180. }
  181. ],
  182. "source": [
  183. "pow(8, -1, q)"
  184. ]
  185. },
  186. {
  187. "cell_type": "code",
  188. "execution_count": 10,
  189. "id": "d8575e54",
  190. "metadata": {},
  191. "outputs": [
  192. {
  193. "data": {
  194. "text/plain": [
  195. "486662"
  196. ]
  197. },
  198. "execution_count": 10,
  199. "metadata": {},
  200. "output_type": "execute_result"
  201. }
  202. ],
  203. "source": [
  204. "A = 2 * (-1 + d) / (-1 - d)\n",
  205. "A"
  206. ]
  207. },
  208. {
  209. "cell_type": "code",
  210. "execution_count": 11,
  211. "id": "2ee580a3",
  212. "metadata": {},
  213. "outputs": [
  214. {
  215. "data": {
  216. "text/plain": [
  217. "57896044618658097711785492504343953926634992332820282019728792003956564333285"
  218. ]
  219. },
  220. "execution_count": 11,
  221. "metadata": {},
  222. "output_type": "execute_result"
  223. }
  224. ],
  225. "source": [
  226. "B = 4 / (-1 - d)\n",
  227. "B"
  228. ]
  229. },
  230. {
  231. "cell_type": "code",
  232. "execution_count": null,
  233. "id": "ec089e21",
  234. "metadata": {},
  235. "outputs": [],
  236. "source": []
  237. }
  238. ],
  239. "metadata": {
  240. "kernelspec": {
  241. "display_name": "SageMath 9.2",
  242. "language": "sage",
  243. "name": "sagemath"
  244. },
  245. "language_info": {
  246. "codemirror_mode": {
  247. "name": "ipython",
  248. "version": 3
  249. },
  250. "file_extension": ".py",
  251. "mimetype": "text/x-python",
  252. "name": "python",
  253. "nbconvert_exporter": "python",
  254. "pygments_lexer": "ipython3",
  255. "version": "3.9.7"
  256. }
  257. },
  258. "nbformat": 4,
  259. "nbformat_minor": 5
  260. }