From c4f4f3d305850b3be7ca3c35d2f70727f0bcd91f Mon Sep 17 00:00:00 2001 From: David Florness Date: Sat, 9 Nov 2019 20:44:03 -0700 Subject: [PATCH] Begin crappy interface and choose r --- crypto.rkt | 2 +- info.rkt | 2 +- main.rkt | 89 ++++++++++++++++++++++++------------------------------ 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/crypto.rkt b/crypto.rkt index 7f6f00a..be0b4c8 100644 --- a/crypto.rkt +++ b/crypto.rkt @@ -1,7 +1,7 @@ #lang racket (require math/number-theory) -(provide e p q d) +(provide keylen e p q d n) (define keylen 1024) (define e 65537) diff --git a/info.rkt b/info.rkt index c78f29e..ec26753 100644 --- a/info.rkt +++ b/info.rkt @@ -1,6 +1,6 @@ #lang info (define collection "vohea") -(define deps '("base")) +(define deps '("base" "simple-http" "crypto")) (define build-deps '("scribble-lib" "racket-doc" "rackunit-lib")) (define scribblings '(("scribblings/vohea.scrbl" ()))) (define pkg-desc "Description Here") diff --git a/main.rkt b/main.rkt index 7e16dd4..e8a7a08 100644 --- a/main.rkt +++ b/main.rkt @@ -1,50 +1,39 @@ -#lang racket/base - -(module+ test - (require rackunit)) - -;; Notice -;; To install (from within the package directory): -;; $ raco pkg install -;; To install (once uploaded to pkgs.racket-lang.org): -;; $ raco pkg install <> -;; To uninstall: -;; $ raco pkg remove <> -;; To view documentation: -;; $ raco docs <> -;; -;; For your convenience, we have included LICENSE-MIT and LICENSE-APACHE files. -;; If you would prefer to use a different license, replace those files with the -;; desired license. -;; -;; Some users like to add a `private/` directory, place auxiliary files there, -;; and require them in `main.rkt`. -;; -;; See the current version of the racket style guide here: -;; http://docs.racket-lang.org/style/index.html - -;; Code here - - - -(module+ test - ;; Any code in this `test` submodule runs when this file is run using DrRacket - ;; or with `raco test`. The code here does not run when this file is - ;; required by another module. - - (check-equal? (+ 2 2) 4)) - -(module+ main - ;; (Optional) main submodule. Put code here if you need it to be executed when - ;; this file is run using DrRacket or the `racket` executable. The code here - ;; does not run when this file is required by another module. Documentation: - ;; http://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29 - - (require racket/cmdline) - (define who (box "world")) - (command-line - #:program "my-program" - #:once-each - [("-n" "--name") name "Who to say hello to" (set-box! who name)] - #:args () - (printf "hello ~a~n" (unbox who)))) +#lang racket +(require simple-http) +(require binaryio) +(require "crypto.rkt") +(require racket/random) + +(define vohea-server + (update-port (update-host json-requester "localhost") 5598)) + +(define candidates (json-response-body (get vohea-server "/candidates"))) + +(define/contract (displayln-und s) + (-> string? void?) + (displayln s) + (displayln (make-string (string-length s) #\=))) + +(displayln-und "Log in") + +(display "Username: ") +(define username (read-line)) +(display "Password: ") +(define password (read-line)) + +(displayln-und "You may choose among the following candidates") +(for/list ([i (in-naturals)] + [c candidates]) + (displayln (format "~a) ~a" i c))) + +(display "Your ranking: ") +(define ranking (string-split (read-line))) + +(define M (bytes->integer (string->bytes/utf-8 (string-join ranking ":")) #f)) + +(define r + (let gen ([r (bytes->integer + (crypto-random-bytes (/ keylen 8)) #f)]) + (if (eq? (gcd r n) 1) + r + (gen)))) -- 2.38.4