• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
      • Std/lists
      • Omaps
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
          • Base64-impl
          • Base64-decode-list
            • Base64-decode
            • Base64-encode-list
            • Base64-revappend-decode
            • Base64-revappend-encode
            • Base64-encode
          • Charset-p
          • Strtok!
          • Cases
          • Concatenation
          • Character-kinds
          • Html-encoding
          • Substrings
          • Strtok
          • Equivalences
          • Url-encoding
          • Lines
          • Explode-implode-equalities
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Base64

    Base64-decode-list

    Base64 decode a character list.

    Signature
    (base64-decode-list x) → (mv okp ans)
    Arguments
    x — Character list to decode.
        Guard (character-listp x).
    Returns
    okp — Was decoding successful? It can fail if we encounter non Base-64 alphabetic characters in the input, or if the input is not of the proper length (a multiple of 4), or if there is incorrect padding.
        Type (booleanp okp).
    ans — On success, the decoded version of x. On failure, it is some nonsensical character list that should not be relied on.
        Type (character-listp ans).

    Definitions and Theorems

    Function: base64-decode-list

    (defun base64-decode-list (x)
      (declare (xargs :guard (character-listp x)))
      (let ((acl2::__function__ 'base64-decode-list))
        (declare (ignorable acl2::__function__))
        (mbe :logic
             (b* (((when (atom x)) (mv t nil))
                  ((when (atom (cdddr x))) (mv nil nil))
                  (c1 (first x))
                  (c2 (second x))
                  (c3 (third x))
                  (c4 (fourth x))
                  (rest (cddddr x))
                  ((when (atom rest))
                   (b64-decode-last-group c1 c2 c3 c4))
                  ((mv okp x1 x2 x3)
                   (b64-dec3 c1 c2 c3 c4))
                  ((unless okp) (mv nil nil))
                  ((mv rest-ok rest-ans)
                   (base64-decode-list (cddddr x))))
               (mv (and okp rest-ok)
                   (list* x1 x2 x3 rest-ans)))
             :exec
             (b* (((mv okp acc)
                   (b64-decode-list-impl x nil)))
               (mv okp (reverse acc))))))

    Theorem: booleanp-of-base64-decode-list.okp

    (defthm booleanp-of-base64-decode-list.okp
      (b* (((mv ?okp ?ans) (base64-decode-list x)))
        (booleanp okp))
      :rule-classes :type-prescription)

    Theorem: character-listp-of-base64-decode-list.ans

    (defthm character-listp-of-base64-decode-list.ans
      (b* (((mv ?okp ?ans) (base64-decode-list x)))
        (character-listp ans))
      :rule-classes :rewrite)

    Theorem: b64-decode-list-impl-removal

    (defthm b64-decode-list-impl-removal
      (equal (b64-decode-list-impl x acc)
             (mv (mv-nth 0 (base64-decode-list x))
                 (revappend (mv-nth 1 (base64-decode-list x))
                            acc))))

    Theorem: base64-decode-list-of-base64-encode-list

    (defthm base64-decode-list-of-base64-encode-list
      (implies (character-listp x)
               (b* ((encoded (base64-encode-list x))
                    ((mv okp decoded)
                     (base64-decode-list encoded)))
                 (and okp (equal decoded x)))))