############################# # SCRIPT: discretelog.bdscr # ############################# # Compute discrete logarithm # Simple... x=1;g=2;p=5 # INPUT b=1;for k in (1..p) do b=modmul(b,g,p);breakif(b==x) done println("The discrete log of ",x," to the base ",g," mod ",p," is ", k) # Check that modexp(g,k,p) == x println(" since modexp(g,k,p)=",modexp(g,k,p)) ??modexp(g,k,p) == x # Slightly bigger... x=18;g=5;p=23 # INPUT b=1;for k in (1..p) do b=modmul(b,g,p);breakif(b==x) done println("The discrete log of ",x," to the base ",g," mod ",p," is ", k) # Check that modexp(g,k,p) == x println(" since modexp(g,k,p)=",modexp(g,k,p)) ??modexp(g,k,p) == x # Much bigger... x=3668993056;g=5;p=9048610007 # INPUT print("Computing...\r") b=1;for k in (1..p) do b=modmul(b,g,p);breakif(b==x) done println("The discrete log of ",x," to the base ",g," mod ",p," is ", k) # Check that modexp(g,k,p) == x println(" since modexp(g,k,p)=",modexp(g,k,p)) ??modexp(g,k,p) == x