1
0
Fork 0
This commit is contained in:
Mike 2024-02-01 18:16:53 +02:00
parent 70b037bf1c
commit 03a5baee0c
2 changed files with 26 additions and 32 deletions

View File

@ -19,7 +19,7 @@
(and
(link (swap 'E (/ E 2)))
(gt0 E) ) ) ) ) )
(de expmod (B E M)
(de expmod- (B E M)
(println 'B B 'E E 'M M)
(let R 1
(for I (steps E)
@ -29,15 +29,15 @@
(setq R (modulo (* R B) M)) ) )
(println 'R R)
R ) )
(de expmod- (B E M)
(de expmod (B E M)
(if (=0 E)
1
(let R
(%
(** (expmod- B (/ E 2) M) 2)
(** (expmod B (/ E 2) M) 2)
M )
(when (bit? 1 E)
(setq R (% (* R B) M)) )
(setq R (modulo (* R B) M)) )
R ) ) )
(de inv (X)
(expmod X (- *Q 2) *Q) )
@ -195,25 +195,3 @@
M ) ) )
(= (scalarmult *Bxy S) (edwards R (scalarmult A H))) ) )
#{
OLD
(need 32 0)
(59 106 39 188 206 182 164 45 98 163 168 208 42 111 13 115 101 50 21 119 29 226 67 166 58 192 72 161 139 89 218 41)
}#
#{
(publickey (157 97 177 157 239 253 90 96 186 132 74 244 146 236 44 196 68 73 197 105 123 50 105 25 112 59 172 3 28 174 127 96)
OLD
(215 90 152 1 130 177 10 183 213 75 254 211 201 100 7 58 14 225 114 243 218 166 35 37 175 2 26 104 247 7 81 26)
NEW
(215 90 152 1 130 177 10 183 213 75 254 211 201 100 7 58 14 225 114 243 218 166 35 37 175 2 26 104 247 7 81 154)
}#
(println (publickey (157 97 177 157 239 253 90 96 186 132 74 244 146 236 44 196 68 73 197 105 123 50 105 25 112 59 172 3 28 174 127 96)))
(bye)

View File

@ -13,9 +13,20 @@ M 57896044618658097711785492504343953926634992332820282019728792003956564819949
R 37095705934669439343138083508754565189542113879843219016388785533085940283556
}#
(seed (time))
(de rnd ()
(let Big (| (rand 0 7) (>> -28 (rand 0 15)) (>> -57 (rand 0 7)))
(when (rand T)
(setq Big (| Big `(hex "1FFFFFF0FFFFFF8"))) )
(do (rand 0 2)
(let Dig (| (rand 0 7) (>> -30 (rand 0 15)) (>> -61 (rand 0 7)))
(when (rand T)
(setq Dig (| Dig `(hex "1FFFFFFC3FFFFFF8"))) )
(setq Big (| Dig (>> -64 Big))) ) )
Big ) )
(de modulo (X Y)
(% (+ Y (% X Y)) Y) )
(de expmod (B E M)
(if (=0 E)
1
@ -24,7 +35,8 @@ R 37095705934669439343138083508754565189542113879843219016388785533085940283556
(** (expmod B (/ E 2) M) 2)
M )
(when (bit? 1 E)
(setq R (% (* R B) M)) )
(setq R (modulo (* R B) M))
)
R ) ) )
(de inv (X)
(expmod X (- *Q 2) *Q) )
@ -65,10 +77,14 @@ R 37095705934669439343138083508754565189542113879843219016388785533085940283556
(and
(setq R (modulo (* R R) M))
(bit? 1 I)
(setq R (modulo (* R B) M)) ) )
(setq R (modulo (* R B) M))
) )
R ) )
(do 10000
(let (B (rnd) E (rnd) M (rnd))
(when (rand T) (setq B (- B)))
(test
(expmod-OLD B E M)
(expmod B E M) ) ) )
(msg 'ok)
(bye)