以下代码
(defn caesar-block-cypher
"Computes the caesar block cypher for the given text with the k key. Returns an array of bytes"
[k text]
(let [byte-string (.getBytes text)]
(loop [return-byte-array [] byte-string byte-string]
(if (= '() byte-string)
return-byte-array
(recur
(conj return-byte-array (byte (+ k (first byte-string))))
(rest byte-string))))))
返回经过凯撒密码使用密钥k加密处理后的字节数组。我想将字节数组转换回字符串,或者直接使用密文对字符串执行解密操作,但是 (new String return-byte-array)
不起作用。有什么建议吗?(defn caesar-block-cypher
"Computes the caesar block cypher for the given text with the k key."
[k text & more]
(let [byte-string (.getBytes (apply str text (map str more)))]
(apply str (map #(char (mod (+ (int %) k) 0x100)) byte-string))))