{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f890e69f", "metadata": {}, "outputs": [], "source": [ "q = pow(2,255) - 19" ] }, { "cell_type": "code", "execution_count": 2, "id": "d90a7f0b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "37095705934669439343138083508754565189542113879843219016388785533085940283555" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "d = ((q - 1) * (121665 * pow(121666, -1, q)) % q)\n", "d" ] }, { "cell_type": "code", "execution_count": 3, "id": "1b2aebc5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "46316835694926478169428394003475163141307993866256225615783033603165251855960" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y = 4 * pow(5, -1, q) % q\n", "y" ] }, { "cell_type": "code", "execution_count": 4, "id": "aae2f8bf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15112221349535400772501151409588531511454012693041857206046113283949847762202" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 0x216936D3CD6E53FEC0A4E231FDD6DC5C692CC7609525A7B2C9562D608F25D51A\n", "x" ] }, { "cell_type": "code", "execution_count": 5, "id": "ea9a4d90", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "26187595835145689230469591415084376402084551887632582719101735842039498021991" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x_squared = x^2 % q\n", "x_squared" ] }, { "cell_type": "code", "execution_count": 6, "id": "3499c817", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "37053468555941182535542715202780130513046395093004980492626426882532201484768" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y_squared = y^2 % q\n", "y_squared" ] }, { "cell_type": "code", "execution_count": 7, "id": "d9617d2d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10865872720795493305073123787695754110961843205372397773524691040492703462777" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "((q - 1) * x_squared + y_squared) % q" ] }, { "cell_type": "code", "execution_count": 8, "id": "ece46a74", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10865872720795493305073123787695754110961843205372397773524691040492703462777" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "((d * x_squared * y_squared) % q + 1) % q" ] }, { "cell_type": "code", "execution_count": 9, "id": "b430f926", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "21711016731996786641919559689128982722488122124807605757398297001483711807481" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pow(8, -1, q)" ] }, { "cell_type": "code", "execution_count": 10, "id": "d8575e54", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "486662" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = 2 * (-1 + d) / (-1 - d)\n", "A" ] }, { "cell_type": "code", "execution_count": 11, "id": "2ee580a3", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "57896044618658097711785492504343953926634992332820282019728792003956564333285" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B = 4 / (-1 - d)\n", "B" ] }, { "cell_type": "code", "execution_count": null, "id": "ec089e21", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 9.2", "language": "sage", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }