Show HN: Otter, a one time pad tool in lisp, my Saturday side project
github.com
github.com
Try to write the code shorter. You should be able to write it in about 50%.
Example, from 6 to 3 lines:
; generate a random list of *max-int* integers
(defun randlist (size)
(let ((lst ()))
(dotimes (i size)
(setf lst (cons (random *max-int*) lst)))
lst))
vs. (defun random-vector (size)
"generate a random vector of *max-int* integers"
(map-into (make-array size) (lambda () (random *max-int*))))
and ; generate random data
(defun gen (size-string)
(when (null size-string)
(setf size-string "4096"))
(setf size (parse-integer size-string :junk-allowed t))
(unless (numberp size)
(error "size must be a number"))
(defvar buffer (randlist size))
(princ (%octets-to-string (coerce buffer 'vector) *encoding*)))
vs. (defun generate-random-data (&optional (size 4096))
(when (stringp size)
(setf size (parse-integer size :junk-allowed t))
(check-type size integer))
(%octets-to-string (random-vector size) *encoding*)) (with-open-file (input input-path)
(with-open-file (pad pad-path)
(setq input-buffer (%string-to-octets (read-line input) *encoding*))
(setq pad-buffer (%string-to-octets (read-line pad) *encoding*))
Also, I'm not sure what (specifically) read-line looks for to stop reading, but if it can occur randomly you could receive errors if this first random new-line occurs before the length of the file's first line. Or at all when using the same pad for many files as you describe. This may be handled by your %octets-to-string handler though.