diff --git a/.gitignore b/.gitignore index 3d12d3f..637f77b 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ # these rules might exclude image files for figures etc. # *.ps # *.eps -# *.pdf +*.pdf ## Generated if empty string is given at "Please type another file name for output:" .pdf @@ -244,3 +244,6 @@ TSWLatexianTemp* # generated if using elsarticle.cls *.spl + +# +.ipynb_checkpoints/ diff --git a/ctnt2018/Untitled.ipynb b/ctnt2018/Untitled.ipynb new file mode 100644 index 0000000..564eeb2 --- /dev/null +++ b/ctnt2018/Untitled.ipynb @@ -0,0 +1,1402 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-20\n", + "-19\n", + "-18\n", + "-17\n", + "-16\n", + "-15\n", + "try the following: a= -15 and k= 8377\n", + "-14\n", + "-13\n", + "-12\n", + "try the following: a= -12 and k= 3407\n", + "-11\n", + "-10\n", + "-9\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 115\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 116\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m149185656432189838133\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 117\u001b[0;31m \u001b[0mecm_trial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m20\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkrange\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 118\u001b[0m \u001b[0;31m#N=2**128+1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 119\u001b[0m \u001b[0;31m#ecm_trial(N,arange=100,krange=10000)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mecm_trial\u001b[0;34m(N, arange, krange)\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkrange\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 102\u001b[0;31m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mexp_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 103\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mArithmeticError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'try the following: a='\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m' and k='\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mexp_p\u001b[0;34m(x, y, a, b, m, N)\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 83\u001b[0;31m \u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 84\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 85\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtwo_p\u001b[0;34m(x, y, a, b, N)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0mLu\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0;31m# print(Lu)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 58\u001b[0;31m \u001b[0mLb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 59\u001b[0m \u001b[0;31m# print(Lb)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[0mL\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mLu\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mLb\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mmod_inv\u001b[0;34m(u, N)\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0meuclid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 50\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36meuclid\u001b[0;34m(u, v)\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[0mq\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx0\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 38\u001b[0m \u001b[0mx2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx0\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mq\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 39\u001b[0;31m \u001b[0ma2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0ma0\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mq\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 40\u001b[0m \u001b[0mb2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mb0\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mq\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mb1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0mx0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb0\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "# %load ECM.py\n", + "from math import factorial, gcd, log\n", + "import numpy as np\n", + "P=np.zeros(10000)\n", + "P[0]=1\n", + "P[1]=1\n", + "for i in range(2,10000):\n", + " if P[i]==0:\n", + " j=2\n", + " while i*j<100:\n", + " P[i*j]=1\n", + " j=j+1\n", + "Primes10000=[i for i,x in enumerate(P) if x==0 ] \n", + "B1000=1\n", + "B10000=1\n", + "for x in Primes10000:\n", + " if x<1000:\n", + " B1000=B1000*(x**(int(log(1000)/log(x))))\n", + " B10000=B10000*(x**(int(log(1000)/log(x))))\n", + "\n", + "def mexp(a,x,N):\n", + " m,s=1,a\n", + " while x>0:\n", + " if x % 2 ==1:\n", + " m=((m*s) % N)\n", + " s=((s*s) % N)\n", + " x=x//2\n", + " return m\n", + "\n", + "def euclid(u,v):\n", + " if v==0:\n", + " raise ArithmeticError('Division by Zero')\n", + " x0,x1=u,v\n", + " a0,a1=1,0\n", + " b0,b1=0,1\n", + " while x1!=0:\n", + " q=x0//x1\n", + " x2=x0-q*x1\n", + " a2=a0-q*a1\n", + " b2=b0-q*b1\n", + " x0,a0,b0=x1,a1,b1\n", + " x1,a1,b1=x2,a2,b2\n", + " if x0<0:\n", + " return -x0,-a0,-b0\n", + " else:\n", + " return x0,a0,b0\n", + "\n", + "def mod_inv(u,N):\n", + " d,a,b=euclid(u,N)\n", + " if d==1:\n", + " return a\n", + " else:\n", + " raise ArithmeticError('Common factor is '+str(d))\n", + "\n", + "def two_p(x,y,a,b,N):\n", + " Lu=(3*x**2+a) % N\n", + " # print(Lu)\n", + " Lb=mod_inv(2*y,N)\n", + " # print(Lb)\n", + " L=Lu*Lb % N\n", + " x_two=(L*L-2*x) % N\n", + " y_two=(L*(x-x_two)-y) %N\n", + " return x_two,y_two\n", + "\n", + "def sum_p(x1,y1,x2,y2,a,b,N):\n", + " Lu=(y2-y1) % N\n", + " Lb=mod_inv(x2-x1,N)\n", + " L=(Lu*Lb) % N\n", + " x_sum=(L*L-x1-x2) %N\n", + " y_sum=(L*(x1-x_sum)-y1) %N\n", + " return x_sum,y_sum\n", + " \n", + "def exp_p(x,y,a,b,m,N):\n", + " sx,sy=x,y\n", + " first=True\n", + " while m>0:\n", + " if m%2==1:\n", + " if first:\n", + " xm,ym=sx,sy\n", + " first=False\n", + " else:\n", + " xm,ym=sum_p(xm,ym,sx,sy,a,b,N)\n", + " sx,sy=two_p(sx,sy,a,b,N)\n", + " m=m//2\n", + " return xm,ym\n", + "\n", + "#def mexp(a,x,N):\n", + " # m,s=1,a\n", + " # while x>0:\n", + " # if x % 2 ==1:\n", + " # m=((m*s) % N)\n", + " # s=((s*s) % N)\n", + " # x=x//2\n", + " # return m\n", + "\n", + "def ecm_trial(N,arange=50,krange=30):\n", + " for a in range(-arange,arange):\n", + " xm,ym=0,1\n", + " print(a) \n", + " for k in range(2,krange):\n", + " try:\n", + " xm,ym=exp_p(xm,ym,a,1,k,N)\n", + " except ArithmeticError:\n", + " print('try the following: a=',a,' and k=',k)\n", + " break\n", + "\n", + "def ecm_trial_2(N,arange=50,B=B1000):\n", + " for a in range(-arange,arange):\n", + " xm,ym=0,1\n", + " try:\n", + " xm,ym=exp_p(xm,ym,a,1,B,N)\n", + " except ArithmeticError:\n", + " print('try the following: a=',a)\n", + " break\n", + " \n", + "N=149185656432189838133\n", + "ecm_trial(N,arange=20,krange=10000)\n", + "#N=2**128+1\n", + "#ecm_trial(N,arange=100,krange=10000)\n", + "#xm,ym=exp_p(0,1,-91,1,factorial(7883),N)\n", + " \n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "ename": "ArithmeticError", + "evalue": "Common factor is 16029560051", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mArithmeticError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mexp_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m15\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfactorial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m8377\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mexp_p\u001b[0;34m(x, y, a, b, m, N)\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0mfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 82\u001b[0;31m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 83\u001b[0m \u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36msum_p\u001b[0;34m(x1, y1, x2, y2, a, b, N)\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 66\u001b[0m \u001b[0mLu\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my2\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0my1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 67\u001b[0;31m \u001b[0mLb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 68\u001b[0m \u001b[0mL\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLu\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mLb\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0mx_sum\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mmod_inv\u001b[0;34m(u, N)\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 52\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 53\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mArithmeticError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Common factor is '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 54\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mArithmeticError\u001b[0m: Common factor is 16029560051" + ] + } + ], + "source": [ + "exp_p(0,1,-15,1,factorial(8377),N)" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "try the following: a= -91\n" + ] + } + ], + "source": [ + "P=np.zeros(10000)\n", + "P[0]=1\n", + "P[1]=1\n", + "for i in range(2,10000):\n", + " if P[i]==0:\n", + " j=2\n", + " while i*j<100:\n", + " P[i*j]=1\n", + " j=j+1\n", + "Primes10000=[i for i,x in enumerate(P) if x==0 ] \n", + "B1000=1\n", + "B10000=1\n", + "for x in Primes10000:\n", + " if x<1000:\n", + " B1000=B1000*(x**(int(log(1000)/log(x))))\n", + " B10000=B10000*(x**(int(log(10000)/log(x))))\n", + "ecm_trial_2(N,arange=100,B=B10000)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "B=1\n", + "for x in Primes10000:\n", + " B=B*(x**(int(log(1000000)/log(x))))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(272092429413788558381560766739333595442,\n", + " 304592951138784758364937297795729494958)" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exp_p(0,1,-91,1,B10000,N)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "ename": "ArithmeticError", + "evalue": "Common factor is 59649589127497217", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mArithmeticError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mexp_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m91\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mB\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mexp_p\u001b[0;34m(x, y, a, b, m, N)\u001b[0m\n\u001b[1;32m 76\u001b[0m \u001b[0mfirst\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 78\u001b[0;31m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 79\u001b[0m \u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 80\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36msum_p\u001b[0;34m(x1, y1, x2, y2, a, b, N)\u001b[0m\n\u001b[1;32m 61\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 62\u001b[0m \u001b[0mLu\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0my2\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0my1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 63\u001b[0;31m \u001b[0mLb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 64\u001b[0m \u001b[0mL\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLu\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mLb\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0mx_sum\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx1\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0mx2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mmod_inv\u001b[0;34m(u, N)\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 49\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mArithmeticError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Common factor is '\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 51\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mArithmeticError\u001b[0m: Common factor is 59649589127497217" + ] + } + ], + "source": [ + "exp_p(0,1,-91,1,B,N)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Primes1000" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "from math import factorial, gcd, log\n", + "import numpy as np\n", + "P=np.zeros(10000)\n", + "P[0]=1\n", + "P[1]=1\n", + "for i in range(2,10000):\n", + " if P[i]==0:\n", + " j=2\n", + " while i*j<10000:\n", + " P[i*j]=1\n", + " j=j+1\n", + "Primes10000=[i for i,x in enumerate(P) if x==0 ] " + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2,\n", + " 3,\n", + " 5,\n", + " 7,\n", + " 11,\n", + " 13,\n", + " 17,\n", + " 19,\n", + " 23,\n", + " 29,\n", + " 31,\n", + " 37,\n", + " 41,\n", + " 43,\n", + " 47,\n", + " 53,\n", + " 59,\n", + " 61,\n", + " 67,\n", + " 71,\n", + " 73,\n", + " 79,\n", + " 83,\n", + " 89,\n", + " 97,\n", + " 101,\n", + " 103,\n", + " 107,\n", + " 109,\n", + " 113,\n", + " 127,\n", + " 131,\n", + " 137,\n", + " 139,\n", + " 149,\n", + " 151,\n", + " 157,\n", + " 163,\n", + " 167,\n", + " 173,\n", + " 179,\n", + " 181,\n", + " 191,\n", + " 193,\n", + " 197,\n", + " 199,\n", + " 211,\n", + " 223,\n", + " 227,\n", + " 229,\n", + " 233,\n", + " 239,\n", + " 241,\n", + " 251,\n", + " 257,\n", + " 263,\n", + " 269,\n", + " 271,\n", + " 277,\n", + " 281,\n", + " 283,\n", + " 293,\n", + " 307,\n", + " 311,\n", + " 313,\n", + " 317,\n", + " 331,\n", + " 337,\n", + " 347,\n", + " 349,\n", + " 353,\n", + " 359,\n", + " 367,\n", + " 373,\n", + " 379,\n", + " 383,\n", + " 389,\n", + " 397,\n", + " 401,\n", + " 409,\n", + " 419,\n", + " 421,\n", + " 431,\n", + " 433,\n", + " 439,\n", + " 443,\n", + " 449,\n", + " 457,\n", + " 461,\n", + " 463,\n", + " 467,\n", + " 479,\n", + " 487,\n", + " 491,\n", + " 499,\n", + " 503,\n", + " 509,\n", + " 521,\n", + " 523,\n", + " 541,\n", + " 547,\n", + " 557,\n", + " 563,\n", + " 569,\n", + " 571,\n", + " 577,\n", + " 587,\n", + " 593,\n", + " 599,\n", + " 601,\n", + " 607,\n", + " 613,\n", + " 617,\n", + " 619,\n", + " 631,\n", + " 641,\n", + " 643,\n", + " 647,\n", + " 653,\n", + " 659,\n", + " 661,\n", + " 673,\n", + " 677,\n", + " 683,\n", + " 691,\n", + " 701,\n", + " 709,\n", + " 719,\n", + " 727,\n", + " 733,\n", + " 739,\n", + " 743,\n", + " 751,\n", + " 757,\n", + " 761,\n", + " 769,\n", + " 773,\n", + " 787,\n", + " 797,\n", + " 809,\n", + " 811,\n", + " 821,\n", + " 823,\n", + " 827,\n", + " 829,\n", + " 839,\n", + " 853,\n", + " 857,\n", + " 859,\n", + " 863,\n", + " 877,\n", + " 881,\n", + " 883,\n", + " 887,\n", + " 907,\n", + " 911,\n", + " 919,\n", + " 929,\n", + " 937,\n", + " 941,\n", + " 947,\n", + " 953,\n", + " 967,\n", + " 971,\n", + " 977,\n", + " 983,\n", + " 991,\n", + " 997,\n", + " 1009,\n", + " 1013,\n", + " 1019,\n", + " 1021,\n", + " 1031,\n", + " 1033,\n", + " 1039,\n", + " 1049,\n", + " 1051,\n", + " 1061,\n", + " 1063,\n", + " 1069,\n", + " 1087,\n", + " 1091,\n", + " 1093,\n", + " 1097,\n", + " 1103,\n", + " 1109,\n", + " 1117,\n", + " 1123,\n", + " 1129,\n", + " 1151,\n", + " 1153,\n", + " 1163,\n", + " 1171,\n", + " 1181,\n", + " 1187,\n", + " 1193,\n", + " 1201,\n", + " 1213,\n", + " 1217,\n", + " 1223,\n", + " 1229,\n", + " 1231,\n", + " 1237,\n", + " 1249,\n", + " 1259,\n", + " 1277,\n", + " 1279,\n", + " 1283,\n", + " 1289,\n", + " 1291,\n", + " 1297,\n", + " 1301,\n", + " 1303,\n", + " 1307,\n", + " 1319,\n", + " 1321,\n", + " 1327,\n", + " 1361,\n", + " 1367,\n", + " 1373,\n", + " 1381,\n", + " 1399,\n", + " 1409,\n", + " 1423,\n", + " 1427,\n", + " 1429,\n", + " 1433,\n", + " 1439,\n", + " 1447,\n", + " 1451,\n", + " 1453,\n", + " 1459,\n", + " 1471,\n", + " 1481,\n", + " 1483,\n", + " 1487,\n", + " 1489,\n", + " 1493,\n", + " 1499,\n", + " 1511,\n", + " 1523,\n", + " 1531,\n", + " 1543,\n", + " 1549,\n", + " 1553,\n", + " 1559,\n", + " 1567,\n", + " 1571,\n", + " 1579,\n", + " 1583,\n", + " 1597,\n", + " 1601,\n", + " 1607,\n", + " 1609,\n", + " 1613,\n", + " 1619,\n", + " 1621,\n", + " 1627,\n", + " 1637,\n", + " 1657,\n", + " 1663,\n", + " 1667,\n", + " 1669,\n", + " 1693,\n", + " 1697,\n", + " 1699,\n", + " 1709,\n", + " 1721,\n", + " 1723,\n", + " 1733,\n", + " 1741,\n", + " 1747,\n", + " 1753,\n", + " 1759,\n", + " 1777,\n", + " 1783,\n", + " 1787,\n", + " 1789,\n", + " 1801,\n", + " 1811,\n", + " 1823,\n", + " 1831,\n", + " 1847,\n", + " 1861,\n", + " 1867,\n", + " 1871,\n", + " 1873,\n", + " 1877,\n", + " 1879,\n", + " 1889,\n", + " 1901,\n", + " 1907,\n", + " 1913,\n", + " 1931,\n", + " 1933,\n", + " 1949,\n", + " 1951,\n", + " 1973,\n", + " 1979,\n", + " 1987,\n", + " 1993,\n", + " 1997,\n", + " 1999,\n", + " 2003,\n", + " 2011,\n", + " 2017,\n", + " 2027,\n", + " 2029,\n", + " 2039,\n", + " 2053,\n", + " 2063,\n", + " 2069,\n", + " 2081,\n", + " 2083,\n", + " 2087,\n", + " 2089,\n", + " 2099,\n", + " 2111,\n", + " 2113,\n", + " 2129,\n", + " 2131,\n", + " 2137,\n", + " 2141,\n", + " 2143,\n", + " 2153,\n", + " 2161,\n", + " 2179,\n", + " 2203,\n", + " 2207,\n", + " 2213,\n", + " 2221,\n", + " 2237,\n", + " 2239,\n", + " 2243,\n", + " 2251,\n", + " 2267,\n", + " 2269,\n", + " 2273,\n", + " 2281,\n", + " 2287,\n", + " 2293,\n", + " 2297,\n", + " 2309,\n", + " 2311,\n", + " 2333,\n", + " 2339,\n", + " 2341,\n", + " 2347,\n", + " 2351,\n", + " 2357,\n", + " 2371,\n", + " 2377,\n", + " 2381,\n", + " 2383,\n", + " 2389,\n", + " 2393,\n", + " 2399,\n", + " 2411,\n", + " 2417,\n", + " 2423,\n", + " 2437,\n", + " 2441,\n", + " 2447,\n", + " 2459,\n", + " 2467,\n", + " 2473,\n", + " 2477,\n", + " 2503,\n", + " 2521,\n", + " 2531,\n", + " 2539,\n", + " 2543,\n", + " 2549,\n", + " 2551,\n", + " 2557,\n", + " 2579,\n", + " 2591,\n", + " 2593,\n", + " 2609,\n", + " 2617,\n", + " 2621,\n", + " 2633,\n", + " 2647,\n", + " 2657,\n", + " 2659,\n", + " 2663,\n", + " 2671,\n", + " 2677,\n", + " 2683,\n", + " 2687,\n", + " 2689,\n", + " 2693,\n", + " 2699,\n", + " 2707,\n", + " 2711,\n", + " 2713,\n", + " 2719,\n", + " 2729,\n", + " 2731,\n", + " 2741,\n", + " 2749,\n", + " 2753,\n", + " 2767,\n", + " 2777,\n", + " 2789,\n", + " 2791,\n", + " 2797,\n", + " 2801,\n", + " 2803,\n", + " 2819,\n", + " 2833,\n", + " 2837,\n", + " 2843,\n", + " 2851,\n", + " 2857,\n", + " 2861,\n", + " 2879,\n", + " 2887,\n", + " 2897,\n", + " 2903,\n", + " 2909,\n", + " 2917,\n", + " 2927,\n", + " 2939,\n", + " 2953,\n", + " 2957,\n", + " 2963,\n", + " 2969,\n", + " 2971,\n", + " 2999,\n", + " 3001,\n", + " 3011,\n", + " 3019,\n", + " 3023,\n", + " 3037,\n", + " 3041,\n", + " 3049,\n", + " 3061,\n", + " 3067,\n", + " 3079,\n", + " 3083,\n", + " 3089,\n", + " 3109,\n", + " 3119,\n", + " 3121,\n", + " 3137,\n", + " 3163,\n", + " 3167,\n", + " 3169,\n", + " 3181,\n", + " 3187,\n", + " 3191,\n", + " 3203,\n", + " 3209,\n", + " 3217,\n", + " 3221,\n", + " 3229,\n", + " 3251,\n", + " 3253,\n", + " 3257,\n", + " 3259,\n", + " 3271,\n", + " 3299,\n", + " 3301,\n", + " 3307,\n", + " 3313,\n", + " 3319,\n", + " 3323,\n", + " 3329,\n", + " 3331,\n", + " 3343,\n", + " 3347,\n", + " 3359,\n", + " 3361,\n", + " 3371,\n", + " 3373,\n", + " 3389,\n", + " 3391,\n", + " 3407,\n", + " 3413,\n", + " 3433,\n", + " 3449,\n", + " 3457,\n", + " 3461,\n", + " 3463,\n", + " 3467,\n", + " 3469,\n", + " 3491,\n", + " 3499,\n", + " 3511,\n", + " 3517,\n", + " 3527,\n", + " 3529,\n", + " 3533,\n", + " 3539,\n", + " 3541,\n", + " 3547,\n", + " 3557,\n", + " 3559,\n", + " 3571,\n", + " 3581,\n", + " 3583,\n", + " 3593,\n", + " 3607,\n", + " 3613,\n", + " 3617,\n", + " 3623,\n", + " 3631,\n", + " 3637,\n", + " 3643,\n", + " 3659,\n", + " 3671,\n", + " 3673,\n", + " 3677,\n", + " 3691,\n", + " 3697,\n", + " 3701,\n", + " 3709,\n", + " 3719,\n", + " 3727,\n", + " 3733,\n", + " 3739,\n", + " 3761,\n", + " 3767,\n", + " 3769,\n", + " 3779,\n", + " 3793,\n", + " 3797,\n", + " 3803,\n", + " 3821,\n", + " 3823,\n", + " 3833,\n", + " 3847,\n", + " 3851,\n", + " 3853,\n", + " 3863,\n", + " 3877,\n", + " 3881,\n", + " 3889,\n", + " 3907,\n", + " 3911,\n", + " 3917,\n", + " 3919,\n", + " 3923,\n", + " 3929,\n", + " 3931,\n", + " 3943,\n", + " 3947,\n", + " 3967,\n", + " 3989,\n", + " 4001,\n", + " 4003,\n", + " 4007,\n", + " 4013,\n", + " 4019,\n", + " 4021,\n", + " 4027,\n", + " 4049,\n", + " 4051,\n", + " 4057,\n", + " 4073,\n", + " 4079,\n", + " 4091,\n", + " 4093,\n", + " 4099,\n", + " 4111,\n", + " 4127,\n", + " 4129,\n", + " 4133,\n", + " 4139,\n", + " 4153,\n", + " 4157,\n", + " 4159,\n", + " 4177,\n", + " 4201,\n", + " 4211,\n", + " 4217,\n", + " 4219,\n", + " 4229,\n", + " 4231,\n", + " 4241,\n", + " 4243,\n", + " 4253,\n", + " 4259,\n", + " 4261,\n", + " 4271,\n", + " 4273,\n", + " 4283,\n", + " 4289,\n", + " 4297,\n", + " 4327,\n", + " 4337,\n", + " 4339,\n", + " 4349,\n", + " 4357,\n", + " 4363,\n", + " 4373,\n", + " 4391,\n", + " 4397,\n", + " 4409,\n", + " 4421,\n", + " 4423,\n", + " 4441,\n", + " 4447,\n", + " 4451,\n", + " 4457,\n", + " 4463,\n", + " 4481,\n", + " 4483,\n", + " 4493,\n", + " 4507,\n", + " 4513,\n", + " 4517,\n", + " 4519,\n", + " 4523,\n", + " 4547,\n", + " 4549,\n", + " 4561,\n", + " 4567,\n", + " 4583,\n", + " 4591,\n", + " 4597,\n", + " 4603,\n", + " 4621,\n", + " 4637,\n", + " 4639,\n", + " 4643,\n", + " 4649,\n", + " 4651,\n", + " 4657,\n", + " 4663,\n", + " 4673,\n", + " 4679,\n", + " 4691,\n", + " 4703,\n", + " 4721,\n", + " 4723,\n", + " 4729,\n", + " 4733,\n", + " 4751,\n", + " 4759,\n", + " 4783,\n", + " 4787,\n", + " 4789,\n", + " 4793,\n", + " 4799,\n", + " 4801,\n", + " 4813,\n", + " 4817,\n", + " 4831,\n", + " 4861,\n", + " 4871,\n", + " 4877,\n", + " 4889,\n", + " 4903,\n", + " 4909,\n", + " 4919,\n", + " 4931,\n", + " 4933,\n", + " 4937,\n", + " 4943,\n", + " 4951,\n", + " 4957,\n", + " 4967,\n", + " 4969,\n", + " 4973,\n", + " 4987,\n", + " 4993,\n", + " 4999,\n", + " 5003,\n", + " 5009,\n", + " 5011,\n", + " 5021,\n", + " 5023,\n", + " 5039,\n", + " 5051,\n", + " 5059,\n", + " 5077,\n", + " 5081,\n", + " 5087,\n", + " 5099,\n", + " 5101,\n", + " 5107,\n", + " 5113,\n", + " 5119,\n", + " 5147,\n", + " 5153,\n", + " 5167,\n", + " 5171,\n", + " 5179,\n", + " 5189,\n", + " 5197,\n", + " 5209,\n", + " 5227,\n", + " 5231,\n", + " 5233,\n", + " 5237,\n", + " 5261,\n", + " 5273,\n", + " 5279,\n", + " 5281,\n", + " 5297,\n", + " 5303,\n", + " 5309,\n", + " 5323,\n", + " 5333,\n", + " 5347,\n", + " 5351,\n", + " 5381,\n", + " 5387,\n", + " 5393,\n", + " 5399,\n", + " 5407,\n", + " 5413,\n", + " 5417,\n", + " 5419,\n", + " 5431,\n", + " 5437,\n", + " 5441,\n", + " 5443,\n", + " 5449,\n", + " 5471,\n", + " 5477,\n", + " 5479,\n", + " 5483,\n", + " 5501,\n", + " 5503,\n", + " 5507,\n", + " 5519,\n", + " 5521,\n", + " 5527,\n", + " 5531,\n", + " 5557,\n", + " 5563,\n", + " 5569,\n", + " 5573,\n", + " 5581,\n", + " 5591,\n", + " 5623,\n", + " 5639,\n", + " 5641,\n", + " 5647,\n", + " 5651,\n", + " 5653,\n", + " 5657,\n", + " 5659,\n", + " 5669,\n", + " 5683,\n", + " 5689,\n", + " 5693,\n", + " 5701,\n", + " 5711,\n", + " 5717,\n", + " 5737,\n", + " 5741,\n", + " 5743,\n", + " 5749,\n", + " 5779,\n", + " 5783,\n", + " 5791,\n", + " 5801,\n", + " 5807,\n", + " 5813,\n", + " 5821,\n", + " 5827,\n", + " 5839,\n", + " 5843,\n", + " 5849,\n", + " 5851,\n", + " 5857,\n", + " 5861,\n", + " 5867,\n", + " 5869,\n", + " 5879,\n", + " 5881,\n", + " 5897,\n", + " 5903,\n", + " 5923,\n", + " 5927,\n", + " 5939,\n", + " 5953,\n", + " 5981,\n", + " 5987,\n", + " 6007,\n", + " 6011,\n", + " 6029,\n", + " 6037,\n", + " 6043,\n", + " 6047,\n", + " 6053,\n", + " 6067,\n", + " 6073,\n", + " 6079,\n", + " 6089,\n", + " 6091,\n", + " 6101,\n", + " 6113,\n", + " 6121,\n", + " 6131,\n", + " 6133,\n", + " 6143,\n", + " 6151,\n", + " 6163,\n", + " 6173,\n", + " 6197,\n", + " 6199,\n", + " 6203,\n", + " 6211,\n", + " 6217,\n", + " 6221,\n", + " 6229,\n", + " 6247,\n", + " 6257,\n", + " 6263,\n", + " 6269,\n", + " 6271,\n", + " 6277,\n", + " 6287,\n", + " 6299,\n", + " 6301,\n", + " 6311,\n", + " 6317,\n", + " 6323,\n", + " 6329,\n", + " 6337,\n", + " 6343,\n", + " 6353,\n", + " 6359,\n", + " 6361,\n", + " 6367,\n", + " 6373,\n", + " 6379,\n", + " 6389,\n", + " 6397,\n", + " 6421,\n", + " 6427,\n", + " 6449,\n", + " 6451,\n", + " 6469,\n", + " 6473,\n", + " 6481,\n", + " 6491,\n", + " 6521,\n", + " 6529,\n", + " 6547,\n", + " 6551,\n", + " 6553,\n", + " 6563,\n", + " 6569,\n", + " 6571,\n", + " 6577,\n", + " 6581,\n", + " 6599,\n", + " 6607,\n", + " 6619,\n", + " 6637,\n", + " 6653,\n", + " 6659,\n", + " 6661,\n", + " 6673,\n", + " 6679,\n", + " 6689,\n", + " 6691,\n", + " 6701,\n", + " 6703,\n", + " 6709,\n", + " 6719,\n", + " 6733,\n", + " 6737,\n", + " 6761,\n", + " 6763,\n", + " 6779,\n", + " 6781,\n", + " 6791,\n", + " 6793,\n", + " 6803,\n", + " 6823,\n", + " 6827,\n", + " 6829,\n", + " 6833,\n", + " 6841,\n", + " 6857,\n", + " 6863,\n", + " 6869,\n", + " 6871,\n", + " 6883,\n", + " 6899,\n", + " 6907,\n", + " 6911,\n", + " 6917,\n", + " 6947,\n", + " 6949,\n", + " 6959,\n", + " 6961,\n", + " 6967,\n", + " 6971,\n", + " 6977,\n", + " 6983,\n", + " 6991,\n", + " 6997,\n", + " 7001,\n", + " 7013,\n", + " 7019,\n", + " 7027,\n", + " 7039,\n", + " 7043,\n", + " 7057,\n", + " 7069,\n", + " 7079,\n", + " 7103,\n", + " 7109,\n", + " 7121,\n", + " 7127,\n", + " 7129,\n", + " 7151,\n", + " 7159,\n", + " 7177,\n", + " 7187,\n", + " 7193,\n", + " 7207,\n", + " 7211,\n", + " 7213,\n", + " 7219,\n", + " 7229,\n", + " 7237,\n", + " 7243,\n", + " 7247,\n", + " 7253,\n", + " 7283,\n", + " 7297,\n", + " 7307,\n", + " 7309,\n", + " 7321,\n", + " 7331,\n", + " 7333,\n", + " 7349,\n", + " 7351,\n", + " 7369,\n", + " 7393,\n", + " 7411,\n", + " 7417,\n", + " 7433,\n", + " 7451,\n", + " 7457,\n", + " 7459,\n", + " 7477,\n", + " 7481,\n", + " 7487,\n", + " 7489,\n", + " 7499,\n", + " 7507,\n", + " 7517,\n", + " 7523,\n", + " 7529,\n", + " 7537,\n", + " 7541,\n", + " 7547,\n", + " 7549,\n", + " 7559,\n", + " 7561,\n", + " 7573,\n", + " 7577,\n", + " 7583,\n", + " 7589,\n", + " 7591,\n", + " 7603,\n", + " 7607,\n", + " 7621,\n", + " 7639,\n", + " 7643,\n", + " 7649,\n", + " 7669,\n", + " 7673,\n", + " 7681,\n", + " 7687,\n", + " 7691,\n", + " 7699,\n", + " 7703,\n", + " 7717,\n", + " 7723,\n", + " 7727,\n", + " 7741,\n", + " 7753,\n", + " 7757,\n", + " 7759,\n", + " 7789,\n", + " 7793,\n", + " 7817,\n", + " 7823,\n", + " 7829,\n", + " 7841,\n", + " 7853,\n", + " 7867,\n", + " 7873,\n", + " 7877,\n", + " 7879,\n", + " 7883,\n", + " 7901,\n", + " 7907,\n", + " 7919,\n", + " ...]" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Primes10000" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "U=59649589127497217" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [], + "source": [ + "V=N//U" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5704689200685129054721" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "V\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/ctnt2018/Untitled1.ipynb b/ctnt2018/Untitled1.ipynb new file mode 100644 index 0000000..26bc131 --- /dev/null +++ b/ctnt2018/Untitled1.ipynb @@ -0,0 +1,374 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "U=59649589127497217" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "N=2**(128)+1" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "V=N//U" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "P=np.zeros(10000)\n", + "P[0]=1\n", + "P[1]=1\n", + "for i in range(2,10000):\n", + " if P[i]==0:\n", + " j=2\n", + " while i*j<10000:\n", + " P[i*j]=1\n", + " j=j+1\n", + "Primes10000=[i for i,x in enumerate(P) if x==0 ] " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "K=U-1" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], + "source": [ + "for x in Primes10000:\n", + " if K % x ==0:\n", + " print(x)\n", + " K=K//x" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "def mexp(a,x,N):\n", + " m,s=1,a\n", + " while x>0:\n", + " if x % 2 ==1:\n", + " m=((m*s) % N)\n", + " s=((s*s) % N)\n", + " x=x//2\n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "59649589127497216" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mexp(3,K,U)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "# %load ECM.py\n", + "# %load ec3.py\n", + "from math import factorial, gcd, log\n", + "import numpy as np\n", + "P=np.zeros(1000)\n", + "P[0]=1\n", + "P[1]=1\n", + "for i in range(2,100):\n", + " if P[i]==0:\n", + " j=2\n", + " while i*j<100:\n", + " P[i*j]=1\n", + " j=j+1\n", + "Primes1000=[i for i,x in enumerate(P) if x==0 ] \n", + "\n", + "\n", + "def mexp(a,x,N):\n", + " m,s=1,a\n", + " while x>0:\n", + " if x % 2 ==1:\n", + " m=((m*s) % N)\n", + " s=((s*s) % N)\n", + " x=x//2\n", + " return m\n", + "\n", + "def euclid(u,v):\n", + " if v==0:\n", + " raise ArithmeticError('Division by Zero')\n", + " x0,x1=u,v\n", + " a0,a1=1,0\n", + " b0,b1=0,1\n", + " while x1!=0:\n", + " q=x0//x1\n", + " x2=x0-q*x1\n", + " a2=a0-q*a1\n", + " b2=b0-q*b1\n", + " x0,a0,b0=x1,a1,b1\n", + " x1,a1,b1=x2,a2,b2\n", + " if x0<0:\n", + " return -x0,-a0,-b0\n", + " else:\n", + " return x0,a0,b0\n", + "\n", + "def mod_inv(u,N):\n", + " d,a,b=euclid(u,N)\n", + " if d==1:\n", + " return a\n", + " else:\n", + " raise ArithmeticError('Common factor is '+str(d))\n", + "\n", + "def two_p(x,y,a,b,N):\n", + " Lu=(3*x**2+a) % N\n", + " # print(Lu)\n", + " Lb=mod_inv(2*y,N)\n", + " # print(Lb)\n", + " L=Lu*Lb % N\n", + " x_two=(L*L-2*x) % N\n", + " y_two=(L*(x-x_two)-y) %N\n", + " return x_two,y_two\n", + "\n", + "def sum_p(x1,y1,x2,y2,a,b,N):\n", + " Lu=(y2-y1) % N\n", + " Lb=mod_inv(x2-x1,N)\n", + " L=(Lu*Lb) % N\n", + " x_sum=(L*L-x1-x2) %N\n", + " y_sum=(L*(x1-x_sum)-y1) %N\n", + " return x_sum,y_sum\n", + " \n", + "def exp_p(x,y,a,b,m,N):\n", + " sx,sy=x,y\n", + " first=True\n", + " while m>0:\n", + " if m%2==1:\n", + " if first:\n", + " xm,ym=sx,sy\n", + " first=False\n", + " else:\n", + " xm,ym=sum_p(xm,ym,sx,sy,a,b,N)\n", + " sx,sy=two_p(sx,sy,a,b,N)\n", + " m=m//2\n", + " return xm,ym\n", + "\n", + "#def mexp(a,x,N):\n", + " # m,s=1,a\n", + " # while x>0:\n", + " # if x % 2 ==1:\n", + " # m=((m*s) % N)\n", + " # s=((s*s) % N)\n", + " # x=x//2\n", + " # return m\n", + "\n", + "def ecm_trial(N,arange=50,krange=30):\n", + " for a in range(-arange,arange):\n", + " xm,ym=0,1\n", + " print(a) \n", + " for k in range(2,krange):\n", + " try:\n", + " xm,ym=exp_p(xm,ym,a,1,k,N)\n", + " except ArithmeticError:\n", + " print('try the following: a=',a,' and k=',k)\n", + " break\n", + "\n", + " \n", + " \n", + "#N=149185656432189838133\n", + "#ecm_trial(N,arange=20,krange=10000)\n", + "N=2**128+1\n", + "#ecm_trial(N,arange=100,krange=10000)\n", + "#xm,ym=exp_p(0,1,-91,1,factorial(7883),N)\n", + " \n", + " \n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-100\n", + "-99\n", + "-98\n", + "-97\n", + "-96\n", + "-95\n", + "-94\n", + "-93\n", + "-92\n", + "-91\n", + "try the following: a= -91 and k= 7883\n", + "-90\n", + "-89\n", + "-88\n", + "-87\n", + "-86\n", + "-85\n", + "-84\n", + "-83\n", + "-82\n", + "-81\n", + "-80\n", + "-79\n", + "-78\n", + "-77\n", + "-76\n", + "-75\n", + "-74\n", + "-73\n", + "-72\n", + "-71\n", + "-70\n", + "-69\n", + "-68\n", + "-67\n", + "-66\n", + "-65\n", + "-64\n", + "-63\n", + "-62\n", + "-61\n", + "-60\n", + "-59\n", + "-58\n", + "-57\n", + "-56\n", + "-55\n", + "-54\n", + "-53\n", + "-52\n", + "-51\n", + "-50\n", + "-49\n", + "-48\n", + "-47\n", + "-46\n", + "-45\n", + "-44\n", + "-43\n", + "-42\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mecm_trial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mU\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0marange\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkrange\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mecm_trial\u001b[0;34m(N, arange, krange)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mk\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkrange\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 97\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 98\u001b[0;31m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mexp_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 99\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mArithmeticError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'try the following: a='\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m' and k='\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mexp_p\u001b[0;34m(x, y, a, b, m, N)\u001b[0m\n\u001b[1;32m 77\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 78\u001b[0m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msum_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 79\u001b[0;31m \u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtwo_p\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0msy\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 80\u001b[0m \u001b[0mm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mm\u001b[0m\u001b[0;34m//\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 81\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mxm\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mym\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtwo_p\u001b[0;34m(x, y, a, b, N)\u001b[0m\n\u001b[1;32m 52\u001b[0m \u001b[0mLu\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 53\u001b[0m \u001b[0;31m# print(Lu)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 54\u001b[0;31m \u001b[0mLb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 55\u001b[0m \u001b[0;31m# print(Lb)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0mL\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mLu\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mLb\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mN\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mmod_inv\u001b[0;34m(u, N)\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmod_inv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 45\u001b[0;31m \u001b[0md\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0meuclid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mu\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 46\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0md\u001b[0m\u001b[0;34m==\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "ecm_trial(U,arange=100,krange=10000)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mexp(11,V-1,V)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/ctnt2018/ctnt2018.tex b/ctnt2018/ctnt2018.tex index fce1b44..bf14711 100644 --- a/ctnt2018/ctnt2018.tex +++ b/ctnt2018/ctnt2018.tex @@ -1,9 +1,11 @@ \documentclass{beamer} -\usepackage{minted} +%\usepackage{minted} \newtheorem{proposition}{Proposition} \newtheorem{algorithm}{Algorithm} -\begin{document} +\hypersetup{colorlinks,linkcolor=,urlcolor=blue} +%\usepackage[colorlinks=true]{hyperref} +\begin{document} \begin{frame} \begin{center} Lenstra's Elliptic Curve Factoring Method \\ @@ -17,35 +19,35 @@ \begin{problem} Given a positive composite integer $N$, find a proper prime divisor of $N$. \end{problem} \end{frame} -\begin{frame}{Factoring is important} - - {\small - Problema, numeros primos a compositis dignoscendi, - hosque in factores suos primos resolvendi, ad gravissima ac utilissima totius arithmeticae pertinere, - ...Praetereaque scientiae dignitas requirere videtur, ut omnia subsidia ad solutionem - problematis tam elegantis ac celebris sedulo excolantur. - - \medskip\noindent - The problem of distinguishing prime numbers from composite numbers and of - resolving the latter into their prime factors is known to be one of the most - important and useful in arithmetic. ..Further, the dignity of the - science itself seems to require that every possible means be explored for - the solution of a problem so elegant and so celebrated. - - \medskip\noindent - {\it Gauss, Disquisitiones Arithmeticae (1801): Article 329} - } - -\end{frame} -\begin{frame}{Cryptography} - \begin{block}{} - Gauss thought factoring was important and he was unaware of the role it - plays in the security of widely used public-key cryptographic systems. - \end{block} - \begin{block}{} - Although a major reason for current work on the problem, we won't get into the cryptographic applications in this talk. - \end{block} -\end{frame} +%\begin{frame}{Factoring is important} +% +% {\small +% Problema, numeros primos a compositis dignoscendi, +% hosque in factores suos primos resolvendi, ad gravissima ac utilissima totius arithmeticae pertinere, +% ...Praetereaque scientiae dignitas requirere videtur, ut omnia subsidia ad solutionem +% problematis tam elegantis ac celebris sedulo excolantur. +% +% \medskip\noindent +% The problem of distinguishing prime numbers from composite numbers and of +% resolving the latter into their prime factors is known to be one of the most +% important and useful in arithmetic. ..Further, the dignity of the +% science itself seems to require that every possible means be explored for +% the solution of a problem so elegant and so celebrated. +% +%\medskip\noindent +% {\it Gauss, Disquisitiones Arithmeticae (1801): Article 329} +% } +% +%\end{frame} +%\begin{frame}{Cryptography} +% \begin{block}{} +% Gauss thought factoring was important and he was unaware of the role it +% plays in the security of widely used public-key cryptographic systems. +% \end{block} +% \begin{block}{} +% Although a major reason for current work on the problem, we won't get into the cryptographic applications in this talk. +% \end{block} +%\end{frame} \begin{frame}{Trial division is impractical} @@ -65,8 +67,8 @@ \begin{frame}{Overview of factoring methods} Modern methods of factoring fall into two categories: \begin{itemize} - \item Methods based on algebraic groups (such as the $p-1$ method, the elliptic curve method, and generalizations) - \item Sieve methods (such as the quadratic and number field sieves) + \item Methods based on algebraic groups, such as the $p-1$ method, the elliptic curve method, and generalizations. + \item Sieve methods, such as the quadratic and number field sieves. \end{itemize} \end{frame} \begin{frame}{Overview of factoring} @@ -87,14 +89,11 @@ There is a polynomial time algorithm for a ``quantum computer.'' \end{frame} \begin{frame}{First make sure your number is composite} - The complexity of factoring means factoring algorithms should only be applied to composite numbers. - \begin{theorem}[Fermat] Suppose that $N$ and $a$ are integers with $(a,N)=1$. If $$a^{N-1}\not\equiv 1\pmod{N}.$$ then $N$ is composite. \end{theorem} -\end{frame} -\begin{frame}{The Fermat Test} + Fermat's theorem allows for a quick test of compositeness. \begin{block}{The Fermat Test} @@ -135,7 +134,7 @@ \end{algorithm} \end{frame} \begin{frame}{The $p-1$ algorithm} - Suppose $N$ is composite. Then the multiplicative group of units $(\mathbf{Z}/N\mathbf{Z})^*$ is not cyclic, so it is a product of cyclic + Suppose $N$ is (odd and) composite. Then the multiplicative group of units $(\mathbf{Z}/N\mathbf{Z})^*$ is not cyclic, so it is a product of cyclic groups by the fundamental theorem of abelian groups. \bigskip\noindent @@ -192,8 +191,12 @@ \begin{frame}{The Elliptic Curve Method} For the $p-1$ method to work, we have to be lucky enough to have a prime factor that is $B$-powersmooth for a relatively small $B$. + + \bigskip\noindent If the number $N$ we are trying to factor doesn't have this property, then the $p-1$ method won't work. + + \bigskip\noindent The elliptic curve method opens the door to more situations in which we can apply the idea of the $p-1$ method. \end{frame} \begin{frame}{ECM, cont'd} @@ -204,7 +207,7 @@ Suppose that we can find a point $P$ on this curve mod $N$ so that a multiple $K$ of $P$ is zero in the first factor but not the second. \bigskip\noindent - If we were to write $E$ in Weierstrass form, and the point $P$ in homogeneous coordinates $[x(P):y(P):z(P)]$, then this condition + If we were to write $E$ in Weierstrass form, and the point $P$ in (reduced) homogeneous coordinates $[x(P):y(P):z(P)]$, then this condition would mean that $z(KP)$ is divisible by $U$ but not by $V$. \bigskip\noindent @@ -213,25 +216,162 @@ \begin{frame}{ECM,3} If we were fortunate enough that (say) the order of the first of the two factor groups - $n=|E(\mathbf{Z}/U\mathbf{Z})|$ were $B$-powersmooth for a (relatively) small $B$. + $n=|E(\mathbf{Z}/U\mathbf{Z})|$ were $B$-powersmooth for a (relatively) small $B$, Then we could use the trick of the $p-1$ method and choose our $K$ to hopefully be divisible by $n$. + \bigskip\noindent The Riemann hypothesis for elliptic curves over finite fields tells us that if $U$ is prime then $n$ is roughly $p$. + + \bigskip\noindent + It seems reasonable to assume that these group orders are essentially random numbers of size roughly $p$. So the chance that $n$ is $B$-powersmooth is the same order as $p-1$ having that property. + \bigskip\noindent But there are many elliptic curves! \end{frame} +\begin{frame}{ECM: An example} +Consider the $7^{th}$ Fermat number +$$ +F_{7}=2^{128}+1=340282366920938463463374607431768211457. +$$ +A Fermat test to base $3$ confirms that $N$ is composite: +$$ +3^{N-1}\equiv 47511664169441434718291075092691853899\not\equiv 1\pmod{N} +$$ +\end{frame} +\begin{frame}{ECM: An example, cont'd} +Try many elliptic curves $E$ and a large but not hopelessly large $B$ so that, if $U$ is a factor of $N$, then +$|E(\mathbf{Z}/U\mathbf{Z})|$ is $B$-powersmooth. +\bigskip\noindent +Consider the family of elliptic curves $E_{a}:y^2=x^3+ax+1$ which has the obvious point $P=(0,1)$ on it. +\bigskip\noindent +Consider $a$ as integers (for example in the range $[-100,100]$) and try $B=10000$. Let +$$ +B_{4}=\prod_{p<10000} p^{[\log (10000)/log(p)]} +$$ +For each $a$, compute +$[B_4](P)$ in $E_{a}(\mathbf{Z}/N\mathbf{Z})$. Use the same idea as in modular exponentiation to compute $[B_4](P)$ (repeated doubling of the point). + +\bigskip +In computing this, you have to do modular inversion mod $N$. If that fails: you've found a factor of $N$. +\end{frame} +\begin{frame}{ECM: an example, cont'd} +A very naive search finds that +$$ +E_{-91}: y^2=x^3-91x+1 +$$ +gives us our factorization and finds the factor +$$N=UV=(59649589127497217)(5704689200685129054721)$$ +\bigskip\noindent +Some quick pseudoprime tests suggests that this is prime (it is) and $U-1$ has a prime divisor with 15 digits and $V-1$ +has a prime factor with $12$ digits, so this factorization is unlikely to have been found by the $p-1$ method. +\end{frame} +\begin{frame}{Lenstra's ECM for theoretical purposes} +Let $N$ be an integer that is not a prime power and is relatively prime to +$6$. +\begin{enumerate} + +\item Choose integers $v$ and $w$ and set +$$ +k=\prod_{2}^{w} r^{e(r)} +$$ +where $e(r)$ is maximal so that +$r^{e(r)}\le v+2\sqrt{v}+1. +$ +\item Draw three elements $a,x_0,y_0$ at random modulo $N$. Let $b=y_0^2-x_0^3-ax$. Then $P=(x_0,y_0)$ is a point on the curve +$E$ with equation $y^2=x^3+ax+b$. +\item Try to compute $kP$. If you find a divisor, cheer! Otherwise, try again until you've tried $h$ times, then give up. +\end{enumerate} +Here $v$ serves as bound on the smallest prime factor of $N$ and $w$ a bound on the largest prime divisor of the group of points mod that prime. +\end{frame} +\begin{frame}{Analysis of ECM} +The method described above will find a divisor provided that the following conditions hold: +\begin{enumerate} +\item $N$ has a prime divisor $p\le v$. +\item The elliptic curve chosen is non-singular mod $p$. +\item The order of the group of points on that curve is $w$-smooth. +\item For some \textit{other} divisor $q$ of $N$, $E$ is non-singular mod $q$ and the order of $P$ mod $q$ is NOT divisible by the +largest prime divisor of the order of $P$ mod $p$. +\end{enumerate} + +How likely is this to happen? There is a trade off between time spent on one curve $v,w$ and number of times you try $h$. +\end{frame} +\begin{frame}{Analysis of ECM, cont'd} +Lenstra uses properties of elliptic curves to show the following. Let +$$ +u=|\{ s: |s-p-1|<\sqrt{p} \hbox{\rm\ and $s$ is $w$-smooth}\}| +$$ +So $u$ is the number of $w$-smooth numbers that could possibly be the order of an elliptic curve mod $p$. +Then the chance that a single attempt at Lenstra's ECM method works (i.e. that a particular $(a,x,y)$ succeeds) is closely related to +the chance of a smooth group order, or $u/(2\sqrt{p}+1)$. +\bigskip\noindent +Conjecture: The chance that a randomly chosen integer in the range $(x-\sqrt{x}+1,x+\sqrt{x}+1)$ is $w$-smooth is the same +as the chance that a randomly chosen integer of that size is $w$-smooth. +\end{frame} +\begin{frame}{Analysis of ECM, cont'd} +\begin{theorem} Suppose $N$ has two prime divisors, that $p$ is the smallest prime divisor of $N$, and that $N$ is prime to $6$. +Let $f(w)$ be the probability that a randomly chosen integer in the range $$(p+1-\sqrt{p},p+1+\sqrt{p})$$ +is $w$-smooth. Assuming $v\ge p$, +then there is an explicitly computable constant $c$ so that the chance of success of the ECM with parameters $v,w,h$ +is +$$1-c^{-hf(w)/\log(v)}.$$ +\end{theorem} +\end{frame} +\begin{frame}{Analysis of ECM, cont'd} +\bigskip\noindent +Meanwhile, the running time for the algorithm is +$$O(hw\log(v)M(N))$$ + because you have to compute $kP$, +and +$$ +\log k\le w\log(v). +$$ +\end{frame} +\begin{frame}{Analysis of ECM, cont'd} +Let $$ +L(x)=e^{\sqrt{\log(x)\log\log(x)}}. +$$ +\bigskip\noindent +Lenstra invokes a famous result of Canfield, Erd\"{o}s, and Pomerance that states that the probability that a random positive integer +$s\le x$ is $L(x)^{\alpha}$-smooth is (asymptotically) +$$ +L(x)^{\frac{1}{2\alpha}+o(1)} +$$ +\end{frame} +\begin{frame}{Analysis of ECM, cont'd} +One way to think of the problem is: for a fixed chance of success, minimize running time. In other words, +for a fixed value of $hf(w)$, minimize $hw$. This boils down to minimizing $w/f(w)$. - - - - - +\bigskip\noindent +The CEP result says that +$$ +w/f(w)= O(L(p)^{\frac{1}{2\alpha}+\alpha+o(1)} +$$ +so the minimum value happens when $\alpha=\frac{1}{\sqrt{2}}$, and, in that case. +$$ +w/f(w)=O(L(p)^{\sqrt{2}}). +$$ +\bigskip\noindent +In other words, for a fixed chance of success, the running time behaves like +$$ +L(p)^{\sqrt{2}}=e^{\sqrt{((2+o(1))\log p\log\log p}} +$$ +where $p$ is the smallest prime factor of $N$. +\end{frame} +\begin{frame}{Further Discussion} +To make ECM work in practice there are many refinements, including: +\begin{enumerate} +\item Using highly optimized elliptic curve operations and modular arithmetic; +\item Careful choice of parameters (smoothness bound, for example). +\end{enumerate} + +\href{http://swc.math.arizona.edu/aws/2006/notes.html}{Bernstein's notes} from the 2006 Winter School address some of these optimizations. +\end{frame} \end{document} \ No newline at end of file