Sample code for 30+ languages & platforms
PureBasic

UU Encoding and Decoding

See more Encryption Examples

Demonstrates how to UU encode and decode.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkCrypt2.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    crypt.i = CkCrypt2::ckCreate()
    If crypt.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    s1.s
    s2.s
    s3.s

    s1 = "This string is to be UU encoded"

    CkCrypt2::setCkUuMode(crypt, "666")
    CkCrypt2::setCkUuFilename(crypt, "something.txt")

    ; UU encode:
    s2 = CkCrypt2::ckEncodeString(crypt,s1,"ansi","uu")

    ; Note: Call crypt.Encode instead of crypt.EncodeString
    ; to UU encode binary bytes (i.e. non-text binary data).

    Debug s2

    ; UU decode:
    crypt2.i = CkCrypt2::ckCreate()
    If crypt2.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    s3 = CkCrypt2::ckDecodeString(crypt2,s2,"ansi","uu")

    ; Note: Likewise, call crypt.Decode to decode non-text binary data.

    Debug s3

    ; Show the file permissions mode and filename found
    ; in the UU encoded data:
    Debug "UuMode = " + CkCrypt2::ckUuMode(crypt2)
    Debug "UuFilename = " + CkCrypt2::ckUuFilename(crypt2)


    CkCrypt2::ckDispose(crypt)
    CkCrypt2::ckDispose(crypt2)


    ProcedureReturn
EndProcedure