;;; -*- 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)