Created
January 23, 2020 00:35
-
-
Save brool/cd1da98a4805fac8d6f831b68158c548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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