BASE64のエンコード関数を使いたくなったので作成。
(defun octet-to-bytes (octet)
(loop FOR i FROM 7 DOWNTO 0
COLLECT (ldb (byte 1 i) octet)))
(defun padding (list divisor padding-value)
(append list
(loop REPEAT (abs (nth-value 1 (ceiling (length list) divisor)))
COLLECT padding-value)))
(defun cdddddr (list) (nthcdr 6 list))
(let ((table "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"))
(defun octets-to-base64 (octets)
(let ((bytes
(loop FOR octet ACROSS octets
NCONC (octet-to-bytes octet))))
(coerce
(padding
(loop FOR (a b c d e f) ON (padding bytes 6 0) BY #'cdddddr
COLLECT
(aref table (+ (ash a 5) (ash b 4) (ash c 3)
(ash d 2) (ash e 1) (ash f 0))))
4 #\=)
'string))))