From cac0b07415a610cde2571a6db4e63acab3f68049 Mon Sep 17 00:00:00 2001 From: David Florness Date: Sun, 9 Feb 2020 21:15:58 -0700 Subject: [PATCH] The client can deduce the constant from the sums! --- client.rkt | 58 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/client.rkt b/client.rkt index 1e26a4d..1341053 100644 --- a/client.rkt +++ b/client.rkt @@ -1,16 +1,18 @@ #lang racket/base -(require racket/port) +(require math/matrix) (require racket/contract) +(require racket/list) (require racket/math) +(require racket/port) -(require readline/readline) +(require (only-in openssl/sha1 hex-string->bytes)) +(require binaryio) (require crypto) +(require json) (require net/http-client) (require net/uri-codec) -(require json) -(require binaryio) +(require readline/readline) (require simple-http) -(require (only-in openssl/sha1 hex-string->bytes)) (define num-bytes (/ 1024 8)) @@ -118,21 +120,33 @@ (natural->hex-string point)))))))))))))) (newline) - (display "summing sums...") - (define sum - (foldl + 0 - (map - hex-string->natural - (hash-values - (json-response-body - (let loop ([wait 0]) - (sleep wait) - (with-handlers ([exn:fail:network:http:error? - (λ (exn) - (break-enabled #t) - (display ".") - (flush-output) - (loop 3))]) - (get bulletin "/sums")))))))) + (display "finding constant...") + (define constant + (let ([k (length peer-inputs)] + [sums (for/hash ([(k v) + (in-hash + (json-response-body + (let loop ([wait 0]) + (sleep wait) + (with-handlers ([exn:fail:network:http:error? + (λ (exn) + (break-enabled #t) + (display ".") + (flush-output) + (loop 3))]) + (get bulletin "/sums")))))]) + (values (hex-string->natural (symbol->string k)) + (hex-string->natural v)))]) + (matrix-ref + (matrix-solve + ; M + (for*/matrix k k ([x peer-inputs] + [p (range k)]) + (expt x p)) + ; B + (for*/matrix k 1 ([x peer-inputs]) + (hash-ref sums x))) + 0 0))) (newline) - (displayln (format "sum: ~a" sum))) + + (displayln (format "Result: ~a" constant))) -- 2.38.4