Re: Happy new year to CLISP
Pascal Bourguignon <[email protected]>
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
> On 31 Dec 2016, at 13:02, Jean Louis <[email protected]> wrote: > > I wish to all Happy New Year, to CLISP users. > > While learning, I am wondering, how to use this function: > > (encrypt (ext:convert-string-to-bytes "Hello there" "utf-8") t) > > *** - ENCRYPT: #(72 101 108 108 111 32 116 104 101 114 101) is not of type (VECTOR (UNSIGNED-BYTE 8) 8) > > as: > > [59]> (type-of (convert-string-to-bytes "Hello there" "utf-8")) > (SIMPLE-ARRAY (UNSIGNED-BYTE 8) (11)) > > while implementation notes say, it should return the byte vector. How > can I convert simple array to byte vector? > > > (EXT:CONVERT-STRING-TO-BYTES string encoding &KEY :START :END) > converts the subsequence of string from start to end to a (VECTOR > (UNSIGNED-BYTE 8)), according to the given encoding, and returns the > resulting byte vector. You have a simple-array of 1x11 octets, and the function expects a vector of 8 octets. Since there’s this difference of size, we may assume that the encrypt function cannot process the whole 11 octets at once. You will have to apply it block-by-block. Perhaps something like: (defun encrypt-message (clear) (let* ((block-size 8) (buffer (make-array block-size :element-type '(unsigned-byte 8))) (text (make-array (ceiling (length clear) block-size) :element-type '(unsigned-byte 8)))) (loop :for start :from 0 :by block-size :for end := (+ start block-size) :while (< start (length clear)) :do (replace buffer clear :start2 start) (when (< (length clear) end) ; fillup last block (fill buffer 0 :start (- end (length clear)) :end block-size)) (encrypt buffer t) (replace text buffer :start1 start) :finally (return text (length clear))))) (encrypt-message (convert-string-to-bytes "Hello there" "utf-8”)) -- __Pascal J. Bourguignon__ ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ clisp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/clisp-list