Created
January 23, 2020 00:35
-
-
Save brool/d814e813ad21eacbf57b25bf5273b0de to your computer and use it in GitHub Desktop.
This file contains hidden or 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