Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Prog Challenge, Easy!

Name: sage 2012-12-29 5:13

Implement https://dis.4chan.org/read/prog/1356634826/25 more elegantly.


(defun 3ml-cgi-decode ()
  (let ((stream (if (string-equal "get" request-method)
            (make-string-input-stream query-string)
          *standard-input*))
    (symbols ()))
    (with-open-stream (output (make-string-output-stream))
      (loop for char = (read-char stream nil nil)
      do (case char
           (#\= (push (intern (string-upcase (get-output-stream-string output)))
              symbols))
           ((nil #\&) (when symbols
                (setf (symbol-value (first symbols)) (get-output-stream-string output))))
           (#\+ (write-char #\space output))
           (#\% (let* ((nib1 (read-char stream nil nil))
               (nib2 (read-char stream nil nil))
               (code (+ (* 16 (digit-char-p nib1 16))
                    (digit-char-p nib2 16))))
              (write-char (code-char code) output)))
           (t (write-char char output)))
      while char))
    (setf *cgi-variables* symbols)))

Name: Anonymous 2012-12-30 7:59

>>20
Yeah, in cases like that you'll typically get some error like the following:


?- 42 is X + Y.
ERROR: is/2: Arguments are not sufficiently instantiated


It could start enumerating all the pairs X,Y that add up to 42, but stuff like that probably isn't what you want. Although you could certainly define your own predicates that would do that, and if you implemented SHA256 using them then prolog would be able to reverse the operations and calculate preimages, although with all the branching possibilities, dead ends, and back tracking, it wouldn't terminate within a reasonable amount of time.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List