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

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

Re: Noob dumb question (extending emacs)


From: Emanuel Berg
Subject: Re: Noob dumb question (extending emacs)
Date: Wed, 03 Nov 2021 23:16:06 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Michael Heerdegen wrote:

>> What does that formula communicate?
>
> For given entropy N, a given number, it returns for what
> word length there are approximately N different (pass)words.

Okay, so for entropy 10 and S = {a, b} the passwords have to
have length 10 for there to be 10 different passwords:

(epwgen-password-length 10 '(a b)) ; 10.0

What about length 4?

aaaa
aaab
aaba
...
bbbb

or 2^4 = 16 passwords?

(expt 2  4) ; 16

(expt 2 10) ; 1024 ?

Only the first 10 are random?

But none of them are ... they are a function of the alphabet
length and the password length, as we see above.

;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;;   https://dataswamp.org/~incal/emacs-init/epwgen.el
;;;
;;; 48 bits, alphabet length n, password length l
;;; 2^48     = n^l            <=>
;;; 48*ln(2) = l*ln(n)        <=>
;;; l        = 48*ln(2)/ln(n)

(defun epwgen-password-length (bits abc)
  (let ((abc-len (if (numberp abc)
                     abc
                   (when (listp abc)
                     (length abc) ))))
    (when abc-len
      (/ (* bits (log 2)) (log abc-len)) )))

;; (epwgen-password-length 48 60)       ;  8.1
;; (epwgen-password-length 48 '(a b c)) ; 30.3
;; (epwgen-password-length 10 '(a b))   ; 10.0

(defun urandom (bits)
  (interactive "nbits: ")
  (let*((bytes     (/ bits 8))
        (bytes-opt (format "--bytes=%s" bytes)) )
    (with-temp-buffer
      (set-buffer-multibyte nil)
      (call-process "head" "/dev/urandom" t nil bytes-opt)
      (string-to-list
       (buffer-substring-no-properties (point-min) (point-max)) ))))
;; (urandom 100)

(provide 'epwgen)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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