This commit is contained in:
Michael Zhang 2020-11-08 23:44:19 -06:00
commit d8ec7ca3fd
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

26
cryptopals.lisp Normal file
View file

@ -0,0 +1,26 @@
(ql:quickload :cl-base64)
(ql:quickload :iterate)
(use-package :iterate)
(defun hex-to-dec (hex-chr)
(cond
((char<= #\0 hex-chr #\9)
(- (char-code hex-chr) (char-code #\0)))
((char<= #\a hex-chr #\f)
(+ (- (char-code hex-chr) (char-code #\a)) 10))
((char<= #\A hex-chr #\F)
(+ (- (char-code hex-chr) (char-code #\A)) 10))))
(defun hex-to-bytes (hex-str)
(iter
(for i below (length hex-str) by 2)
(let ((c1 (hex-to-dec (aref hex-str i)))
(c2 (hex-to-dec (aref hex-str (1+ i)))))
(collect (+ (* 16 c1) c2) result-type (vector (unsigned-byte 8))))))
;; set 1 challenge 1
(defun hex-to-base64 (hex-str)
(cl-base64:usb8-array-to-base64-string (hex-to-bytes hex-str)))