From d8ec7ca3fde9bfdb67783d23f4f6dd5f82ea723f Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 8 Nov 2020 23:44:19 -0600 Subject: [PATCH] s1 c1 --- cryptopals.lisp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cryptopals.lisp diff --git a/cryptopals.lisp b/cryptopals.lisp new file mode 100644 index 0000000..af0a66e --- /dev/null +++ b/cryptopals.lisp @@ -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))) + +