;; Hat tip to JP Aumasson. !(defrec fastexp (lambda (b e) (if (= e 0) 1 (if (< (/ e 2) 0) ; is e odd? (* b (fastexp (* b b) (/ (- e 1) 2))) (fastexp (* b b) (/ e 2)))))) (fastexp 2 5) ;; (4p - 3) / 5 !(def r 23158417847463239084714197001737581570690445185553317903743794198714690358477) !(def fifth-root (lambda (n) (fastexp n r))) !(def fifth (lambda (n) (fastexp n 5))) (fifth-root 42) (fifth 0x2e6606ca7e8983f71964677e06cd8fd13ee0d46bf3c3e52d3af1b80df06f730b) !(def round (lambda (state) (let ((x (car state)) (y (car (cdr state))) (i (car (cdr (cdr state))))) (cons (fifth-root (+ x y)) (cons (+ x i) (cons (+ i 1) nil)))))) !(def inverse-round (lambda (state) (let ((x (car state)) (y (car (cdr state))) (i (car (cdr (cdr state)))) (new-i (- i 1)) (new-x (- y new-i)) (new-y (- (fifth x) new-x))) (cons new-x (cons new-y (cons new-i nil)))))) !(defrec minroot (lambda (state rounds) (if (= rounds 0) state (minroot (round state) (- rounds 1))))) !(defrec minroot-inverse (lambda (state rounds) (if (= rounds 0) state (minroot-inverse (inverse-round state) (- rounds 1))))) (minroot '(123 456 1) 10) (minroot-inverse '(0x27ec1d892ff1b85d98dd8e61509c0ce63b6954da8a743ee54b1f405cde722eb1 0x0da555f3ff604e853948466204d773c4c34d8cf38cea55351c9c97593613fb3b 11) 10) !(prove) !(verify "Nova_Pallas_10_0edc673ca67889bd824bb09d6be89a1b93fc7bc013fff4f4cd50e7bf10587831") !(def timelock-encrypt (lambda (secret-key plaintext rounds) (let ((ciphertext (+ secret-key plaintext)) (timelocked-key-state (minroot-inverse (cons secret-key '(0 1)) rounds))) (cons timelocked-key-state ciphertext)))) !(def timelock-decrypt (lambda (timelocked-key-state ciphertext rounds) (let ((secret-key (car (minroot timelocked-key-state rounds))) (plaintext (- ciphertext secret-key))) plaintext))) ; (timelock-encrypt (num (commit )) 10000) ; [2370068 iterations] => ((0x2b7a3b8ddd37f5729671b40f14ea588eb74e0474516503cae76114c80c3e68b3 0x39766ed0c1d5a61b0a0b5146585f01ea78bac01860ce0f8653bb098d42efcce3 0x40000000000000000000000000000000224698fc0994a8dd8c46eb20ffffd8f2) . 0x0fbc16c244caeec63f5e0316c9b36ad5eba0b1c10f7ecf5d681a911e9dfa74d0) ; (timelock-decrypt ;; timelocked key state ; '(0x2b7a3b8ddd37f5729671b40f14ea588eb74e0474516503cae76114c80c3e68b3 ; 0x39766ed0c1d5a61b0a0b5146585f01ea78bac01860ce0f8653bb098d42efcce3 ; 0x40000000000000000000000000000000224698fc0994a8dd8c46eb20ffffd8f2) ; ;; ciphertext ; 0x0fbc16c244caeec63f5e0316c9b36ad5eba0b1c10f7ecf5d681a911e9dfa74d0 ; ;; rounds ; 10000) ;; [97420052 iterations] =>