#!/usr/bin/newlisp # # Base64 decoder - tested with newLisp 8.3.2 # # Due to the nature of newLISP, this is the smallest # BASE64 decoder I've ever written. # # March 2, 2004 - PvE. #------------------------------------------------------- # Setup base64 encode string (set 'BASE64 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/") # Get input from argument (set 'dat (nth 2 (main-args))) (if (= (nth 1 (main-args)) dat) (begin (println "Usage: ./b64dec.lsp ") (exit) )) # Initialize result variable to string (set 'res "") # Mainloop (while (> (length dat) 0) (begin # Find the indexnumber in the BASE64 definition (set 'byte1 (find (nth 0 dat) BASE64)) (if (= byte1 nil)(set 'byte1 0)) (set 'byte2 (find (nth 1 dat) BASE64)) (if (= byte2 nil)(set 'byte2 0)) (set 'byte3 (find (nth 2 dat) BASE64)) (if (= byte3 nil)(set 'byte3 0)) (set 'byte4 (find (nth 3 dat) BASE64)) (if (= byte4 nil)(set 'byte4 0)) # Recalculate to ASCII value (set 'res (append res (char (+ (* (& byte1 63) 4) (/ (& byte2 48) 16))))) (set 'res (append res (char (+ (* (& byte2 15) 16) (/ (& byte3 60) 4))))) (set 'res (append res (char (+ (* (& byte3 3) 64) byte4)))) # Decrease string with 4 (set 'dat (slice dat 4)) )) # Print resulting string (println "Decoded from BASE64: " res) # Exit (exit)