|
|
|
@ -40,7 +40,6 @@
|
|
|
|
|
(when (get-buffer buf-a) (kill-buffer buf-a))
|
|
|
|
|
(generate-new-buffer buf-a)
|
|
|
|
|
(with-current-buffer buf-a
|
|
|
|
|
(progn
|
|
|
|
|
(insert (phga/dh-pretty-name "Alice"))
|
|
|
|
|
(insert (concat "P for GF(P) = " (number-to-string p) "\n"))
|
|
|
|
|
(insert (concat "G = " (number-to-string g) "\n"))
|
|
|
|
@ -48,12 +47,11 @@
|
|
|
|
|
(insert (concat "Alpha = " (number-to-string aa) "\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"))
|
|
|
|
|
))
|
|
|
|
|
)
|
|
|
|
|
;; Bob
|
|
|
|
|
(when (get-buffer buf-b) (kill-buffer buf-b))
|
|
|
|
|
(generate-new-buffer buf-b)
|
|
|
|
|
(with-current-buffer buf-b
|
|
|
|
|
(progn
|
|
|
|
|
(insert (phga/dh-pretty-name "Bob"))
|
|
|
|
|
(insert (concat "P for GF(P) = " (number-to-string p) "\n"))
|
|
|
|
|
(insert (concat "G = " (number-to-string g) "\n"))
|
|
|
|
@ -61,12 +59,11 @@
|
|
|
|
|
(insert (concat "Beta = " (number-to-string bb) "\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"))
|
|
|
|
|
))
|
|
|
|
|
)
|
|
|
|
|
;; (kill-buffer "*Public*")
|
|
|
|
|
(when (get-buffer buf-p) (kill-buffer buf-p))
|
|
|
|
|
(generate-new-buffer buf-p)
|
|
|
|
|
(with-current-buffer buf-p
|
|
|
|
|
(progn
|
|
|
|
|
(insert "XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx\n")
|
|
|
|
|
(insert " This is a public transport buffer!\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 "Alpha = " (number-to-string aa) "\n"))
|
|
|
|
|
(insert (concat "Beta = " (number-to-string bb) "\n"))
|
|
|
|
|
))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
;; Create Window setup lel that's soooo bad I am SORRY
|
|
|
|
|
(delete-other-windows)
|
|
|
|
|
(command-execute 'split-window-horizontally)
|
|
|
|
|
(command-execute 'split-window-horizontally)
|
|
|
|
|
(command-execute 'balance-windows)
|
|
|
|
|
(split-window-horizontally)
|
|
|
|
|
(split-window-horizontally)
|
|
|
|
|
(balance-windows)
|
|
|
|
|
|
|
|
|
|
(set-window-buffer (nth 0 (window-list)) buf-a)
|
|
|
|
|
(set-window-buffer (nth 1 (window-list)) buf-p)
|
|
|
|
@ -93,11 +90,10 @@
|
|
|
|
|
"Get a random prime number up to n (inclusive)"
|
|
|
|
|
(interactive)
|
|
|
|
|
(let (
|
|
|
|
|
(q (random n))
|
|
|
|
|
(q (+ 2 (random (- n 2))))
|
|
|
|
|
)
|
|
|
|
|
;; p <= 1 -> not a prime number
|
|
|
|
|
(if (and (> q 1)
|
|
|
|
|
(phga/dh-is-prime q))
|
|
|
|
|
(if (phga/dh-is-prime q)
|
|
|
|
|
q
|
|
|
|
|
(phga/dh-get-random-prime-number n))
|
|
|
|
|
)
|
|
|
|
@ -133,12 +129,14 @@
|
|
|
|
|
(+ 1 (random (- p 2))))
|
|
|
|
|
|
|
|
|
|
(defun phga/dh-pretty-name (name)
|
|
|
|
|
"Returns the name in a pretty format"
|
|
|
|
|
(format "****************************\n Hi my Name is %s!\n****************************\n\n" name))
|
|
|
|
|
"Returns the name in a pretty format"
|
|
|
|
|
(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))
|
|
|
|
|
;; (and nil t)
|
|
|
|
|
|
|
|
|
|
;; ;; Test
|
|
|
|
|
;; (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/a (+ 1 (random (- phga/p 2))))
|
|
|
|
|