fix: minor improvements

master
Toerd@archlinux 5 years ago
parent bb24172964
commit b2981ba23d

@ -40,7 +40,6 @@
(when (get-buffer buf-a) (kill-buffer buf-a)) (when (get-buffer buf-a) (kill-buffer buf-a))
(generate-new-buffer buf-a) (generate-new-buffer buf-a)
(with-current-buffer buf-a (with-current-buffer buf-a
(progn
(insert (phga/dh-pretty-name "Alice")) (insert (phga/dh-pretty-name "Alice"))
(insert (concat "P for GF(P) = " (number-to-string p) "\n")) (insert (concat "P for GF(P) = " (number-to-string p) "\n"))
(insert (concat "G = " (number-to-string g) "\n")) (insert (concat "G = " (number-to-string g) "\n"))
@ -48,12 +47,11 @@
(insert (concat "Alpha = " (number-to-string aa) "\n")) (insert (concat "Alpha = " (number-to-string aa) "\n"))
(insert (concat "Beta = " (number-to-string bb) " (sent by Bob to Alice)\n")) (insert (concat "Beta = " (number-to-string bb) " (sent by Bob to Alice)\n"))
(insert (concat "Secret Key = " (number-to-string ka) " (Beta^A mod P == (G^B)^A mod P\n")) (insert (concat "Secret Key = " (number-to-string ka) " (Beta^A mod P == (G^B)^A mod P\n"))
)) )
;; Bob ;; Bob
(when (get-buffer buf-b) (kill-buffer buf-b)) (when (get-buffer buf-b) (kill-buffer buf-b))
(generate-new-buffer buf-b) (generate-new-buffer buf-b)
(with-current-buffer buf-b (with-current-buffer buf-b
(progn
(insert (phga/dh-pretty-name "Bob")) (insert (phga/dh-pretty-name "Bob"))
(insert (concat "P for GF(P) = " (number-to-string p) "\n")) (insert (concat "P for GF(P) = " (number-to-string p) "\n"))
(insert (concat "G = " (number-to-string g) "\n")) (insert (concat "G = " (number-to-string g) "\n"))
@ -61,12 +59,11 @@
(insert (concat "Beta = " (number-to-string bb) "\n")) (insert (concat "Beta = " (number-to-string bb) "\n"))
(insert (concat "Alpha = " (number-to-string aa) " (sent by Alice to Bob)\n")) (insert (concat "Alpha = " (number-to-string aa) " (sent by Alice to Bob)\n"))
(insert (concat "Secret Key = " (number-to-string kb) " (Alpha^B mod P == (G^A)^B mod P\n")) (insert (concat "Secret Key = " (number-to-string kb) " (Alpha^B mod P == (G^A)^B mod P\n"))
)) )
;; (kill-buffer "*Public*") ;; (kill-buffer "*Public*")
(when (get-buffer buf-p) (kill-buffer buf-p)) (when (get-buffer buf-p) (kill-buffer buf-p))
(generate-new-buffer buf-p) (generate-new-buffer buf-p)
(with-current-buffer buf-p (with-current-buffer buf-p
(progn
(insert "XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx\n") (insert "XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx\n")
(insert " This is a public transport buffer!\n") (insert " This is a public transport buffer!\n")
(insert " Mean Hackerbois can wait here\n and sniff the communication!!!\n") (insert " Mean Hackerbois can wait here\n and sniff the communication!!!\n")
@ -75,13 +72,13 @@
(insert (concat "G = " (number-to-string g) "\n")) (insert (concat "G = " (number-to-string g) "\n"))
(insert (concat "Alpha = " (number-to-string aa) "\n")) (insert (concat "Alpha = " (number-to-string aa) "\n"))
(insert (concat "Beta = " (number-to-string bb) "\n")) (insert (concat "Beta = " (number-to-string bb) "\n"))
)) )
;; Create Window setup lel that's soooo bad I am SORRY ;; Create Window setup lel that's soooo bad I am SORRY
(delete-other-windows) (delete-other-windows)
(command-execute 'split-window-horizontally) (split-window-horizontally)
(command-execute 'split-window-horizontally) (split-window-horizontally)
(command-execute 'balance-windows) (balance-windows)
(set-window-buffer (nth 0 (window-list)) buf-a) (set-window-buffer (nth 0 (window-list)) buf-a)
(set-window-buffer (nth 1 (window-list)) buf-p) (set-window-buffer (nth 1 (window-list)) buf-p)
@ -93,11 +90,10 @@
"Get a random prime number up to n (inclusive)" "Get a random prime number up to n (inclusive)"
(interactive) (interactive)
(let ( (let (
(q (random n)) (q (+ 2 (random (- n 2))))
) )
;; p <= 1 -> not a prime number ;; p <= 1 -> not a prime number
(if (and (> q 1) (if (phga/dh-is-prime q)
(phga/dh-is-prime q))
q q
(phga/dh-get-random-prime-number n)) (phga/dh-get-random-prime-number n))
) )
@ -135,10 +131,12 @@
(defun phga/dh-pretty-name (name) (defun phga/dh-pretty-name (name)
"Returns the name in a pretty format" "Returns the name in a pretty format"
(format "****************************\n Hi my Name is %s!\n****************************\n\n" name)) (format "****************************\n Hi my Name is %s!\n****************************\n\n" name))
;; (phga/dh-example)
;; (and nil t)
;; Tests:
;; (phga/dh-get-generator-p (phga/dh-get-random-prime-number 20)) ;; (phga/dh-get-generator-p (phga/dh-get-random-prime-number 20))
;; (and nil t)
;; ;; Test
;; (setq phga/p (phga/dh-get-generator-p (phga/dh-get-random-prime-number 20))) ;; (setq phga/p (phga/dh-get-generator-p (phga/dh-get-random-prime-number 20)))
;; (setq phga/g (phga/dh-get-generator-elem phga/p)) ;; (setq phga/g (phga/dh-get-generator-elem phga/p))
;; (setq phga/a (+ 1 (random (- phga/p 2)))) ;; (setq phga/a (+ 1 (random (- phga/p 2))))

Loading…
Cancel
Save