TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Otter, a one time pad tool in lisp, my Saturday side project

6 点作者 ecto大约 10 年前

2 条评论

lispm大约 10 年前
Way too imperative. Tons of undeclared variables. why is &#x27;modo&#x27; a macro? Local &#x27;defvar&#x27;.<p>Try to write the code shorter. You should be able to write it in about 50%.<p>Example, from 6 to 3 lines:<p><pre><code> ; generate a random list of *max-int* integers (defun randlist (size) (let ((lst ())) (dotimes (i size) (setf lst (cons (random *max-int*) lst))) lst)) </code></pre> vs.<p><pre><code> (defun random-vector (size) &quot;generate a random vector of *max-int* integers&quot; (map-into (make-array size) (lambda () (random *max-int*)))) </code></pre> and<p><pre><code> ; generate random data (defun gen (size-string) (when (null size-string) (setf size-string &quot;4096&quot;)) (setf size (parse-integer size-string :junk-allowed t)) (unless (numberp size) (error &quot;size must be a number&quot;)) (defvar buffer (randlist size)) (princ (%octets-to-string (coerce buffer &#x27;vector) *encoding*))) </code></pre> vs.<p><pre><code> (defun generate-random-data (&amp;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*))</code></pre>
jpd大约 10 年前
Doesn&#x27;t this only encrypt the first line of input? I thought the idea was to generate a pad-file of equal length to the whole file.<p><pre><code> (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*)) </code></pre> Also, I&#x27;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&#x27;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.