Skip to content

Instantly share code, notes, and snippets.

@brool
Created January 23, 2020 00:35
Show Gist options
  • Save brool/cd1da98a4805fac8d6f831b68158c548 to your computer and use it in GitHub Desktop.
Save brool/cd1da98a4805fac8d6f831b68158c548 to your computer and use it in GitHub Desktop.
;; fixed base64-decode-region that works with any number of characters (not just modulo 4)
(defun base64-decode ()
(interactive)
(when mark-active
(let* ((first (region-beginning))
(last (region-end))
(s (buffer-substring first last))
(slen (length s))
(srem (% slen 4))
(adjust (if (zerop srem)
""
(make-string (- 4 srem) ?=)))
(s (concat s adjust)))
(save-excursion
(delete-region first last)
(goto-char first)
(insert (base64-decode-string s))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment