Created
March 16, 2018 15:49
-
-
Save doubledup/f49cb97170b53457838a1f2bc3b92cea to your computer and use it in GitHub Desktop.
A scratchpad for (string <-> hex number) conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(format nil "~{~c~}" | |
(mapcar (lambda (dec) | |
(code-char dec)) | |
(mapcar (lambda (hex) | |
(parse-integer hex :radix 16)) | |
'("48" "61" "70" "70" "79" "20" "42" "69" "72" "74" "68" "64" "61" "79" "20" "44" "61" "76" "69" "64" "20" "44" "75" "6E" "6E")))) | |
(defun encode-string (input-string) | |
(format nil "~S" | |
(mapcar (lambda (code) | |
(write-to-string code :base 16)) | |
(mapcar (lambda (ch) | |
(char-code ch)) | |
(coerce input-string 'list))))) | |
; (coerce (with-input-from-string | |
; (s "(\"84\" \"104\" \"97\" \"110\" \"107\" \"115\" \"32\" \"83\" \"101\" \"97\" \"110\" \"33\")") | |
; (read s)) | |
; 'list) | |
(defun decode-string (input-string) | |
(format nil "~{~c~}" | |
(mapcar (lambda (dec) | |
(code-char dec)) | |
(mapcar (lambda (hex) | |
(parse-integer hex :radix 16)) | |
(coerce (with-input-from-string (s input-string) | |
(read s)) | |
'list))))) | |
"(\"54\" \"68\" \"61\" \"6E\" \"6B\" \"73\" \"20\" \"53\" \"65\" \"61\" \"6E\" \"21\")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment