Skip to content

Instantly share code, notes, and snippets.

View lastland's full-sized avatar

Li Yao lastland

View GitHub Profile
@stribika
stribika / montgomery_ladder.py
Created February 14, 2016 23:13
Basic Montgomery ladder implementation. In the test it works with just numbers, but you can plug in any operation.
#!/usr/bin/python3 -O
from math import floor, log
def montgomery_ladder(x, n, op, select):
k = floor(log(n, 2)) + 1
x1 = x
x2 = op(x, x)
for i in range(k - 2, -1, -1):
bit = 1 if n & (1 << i) else 0
@unionx
unionx / iter.lisp
Created July 21, 2012 01:07
Iteration in Common Lisp
;;;;;; iteration in common lisp
;;;; do
;; `do` is like `if` in c
(do ((x 1 (+ x 1))
(y 1 (* y 2)))
((> x 5) y) ;; when x is bigger than 5, return y
(print y)