s1 c1
This commit is contained in:
commit
d8ec7ca3fd
1 changed files with 26 additions and 0 deletions
26
cryptopals.lisp
Normal file
26
cryptopals.lisp
Normal 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)))
|
||||
|
||||
|
Loading…
Reference in a new issue