Packages

An Elixir cryptocurrency library which contains algorithms used in Bitcoin, Ethereum, and other blockchains. Includes a rich cryptography, number theory, and general mathematics class library.

Current section

Files

Jump to
caustic lib test.ex
Raw

lib/test.ex

defmodule Test do
alias Caustic.Format
import Caustic.Utils
import Enum
@moduledoc false
def start do
m = 14
elems = 0..(m - 1) |> filter(&(gcd(m, &1) == 1))
totient = count elems
table = elems |> map(fn a ->
2..totient |> map(&pow_mod(a, &1, m))
end)
col_labels = 2..totient |> map(& "a^#{&1}")
IO.puts("m = #{m}")
IO.puts("φ(m) = #{totient}")
Format.print_table(table, elems, col_labels)
IO.puts("")
table2 = elems |> map(fn a ->
elems |> map(& mod(a * &1, m))
end)
Format.print_table(table2, elems, elems)
end
def mp1 do
p = mersenne_prime 29
p - p
end
def mp2 do
e = 132049
p = pow(2, e) - 1
p - p
end
def find_solutions(n, x_max) do
# find solutions for x >= 0
# it will be mirrored
0..x_max
|> Enum.map(&{&1, sqrti(&1 * &1 - n)})
|> Enum.filter(fn {_, y} -> y !== nil end)
|> Enum.flat_map(fn {x, y} -> [{x, y}, {-x, y}, {x, -y}, {-x, -y}] end)
|> uniq()
end
end