help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Let us see how to encrypt with Emacs?


From: tomas
Subject: Re: Let us see how to encrypt with Emacs?
Date: Fri, 9 Jul 2021 13:52:39 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jul 09, 2021 at 02:32:10PM +0300, Jean Louis wrote:
> * Eli Zaretskii <eliz@gnu.org> [2021-07-09 13:40]:

[...]

> > No, you don't need to chunk, you just need to pad to a multiple of 64
> > bytes.
> 
> I guess something like this unless I am making an error:
> 
> (defun pad-to-multiple-bytes (string max)
>   "Return string padded to multiple of MAX bytes."
>   (let* ((bytes (string-bytes string))
>        (multiple (truncate (/ bytes max)))
>        (multiple (if (zerop multiple) max (* (1+ multiple) max))))
>     (string-pad string multiple)))

small critiques

 - see the `ceiling' function: it does what you want (perhaps
   except at zero. I'm not sure you want to encrypt a zero
   bytes string at all, but this might get philosophical)
 - MAX is an unfortunate variable name for that. Chunksize,
   blocksize or some relative or abbrev might be better
 - Using twice the same var name in a (let* ...) looks
   confusing. To me, at least.

> > What kind of help?  To use these functions, you need to learn about
> > the various ciphers and what they require.  This is something the
> > Emacs Lisp reference manual cannot teach you.
> > 
> > > ‘STRING’
> > >      A string as input will be used directly.  It may be modified by the
> > >      function (unlike most other Emacs Lisp functions) to reduce the
> > > chance of exposing sensitive data after the function does its work.
> > > 
> > > I am trying to use list with STRING as following and that does not work:
> > > 
> > > (gnutls-symmetric-encrypt "CHACHA20-64" (string-pad "MyPassword987" 32) 
> > > (make-string 16 (random 100)) '(STRING "Text to encrypt"))
> > 
> > What do you mean by "does not work"?
> 
> I get invalid object argument: STRING so I do not understand how to use 
> STRING there.

No, no. The STRING in the manual is meta-syntactic. It's saying
that "when the arg is a string". You are providing a two-element
list. Try (warning: untested!):

  (gnutls-symmetric-encrypt "CHACHA20-64" (string-pad "MyPassword987" 32) 
(make-string 16 (random 100)) "Text to encrypt")

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]