NAME: YEnc
CREATOR: Jürgen Helbing
PB AUTHOR: Torsten Rienow
DESCRIPTION: YEnc is a public domain encoding scheme similar to UUEncode and BASE64, but has much less overhead and encoded data is much smaller.
NOTES: See www.yenc.org for official details.
SOURCE: http://www.powerbasic.com/support/forums/Forum7/HTML/001878.html
Viewing source from yenc.bas   1856 bytes   Last modified Wed, 20 September 2006

#Compile Exe

Sub yEncodeBuffer(ByVal inBuf As Dword, ByVal cbInBuf As Dword, ByVal outBuf As Dword, ByRef cbOutUsed As Dword)
    #Register None
    Dim bTemp   As Byte
    Dim bIn     As Byte Ptr
    Dim bOut    As Byte Ptr
    bIn     = inBuf
    bOut    = outBuf
    For bIn = inBuf To (inBuf + cbInbuf - 1)
        bTemp = @bIn
        bTemp = bTemp + 42
        Select Case bTemp
            Case 0, 9, 10, 13, 46, 61
                @bOut = 61
                Incr bOut
                Incr cbOutUsed
                @bOut = bTemp + 64
                Incr bOut
                Incr cbOutUsed
            Case Else
                @bOut = bTemp
                Incr bOut
                Incr cbOutUsed
        End Select
    Next
End Sub

Sub yDecodeBuffer(ByVal inBuf As Dword, ByVal cbInBuf As Dword, ByVal outBuf As Dword, ByRef cbOutUsed As Dword)
    #Register None
    Dim bTemp   As Byte
    Dim bIn     As Byte Ptr
    Dim bOut    As Byte Ptr
    bIn     = inBuf
    bOut    = outBuf
    For bIn = inBuf To (inBuf + cbInbuf - 1)
        bTemp = @bIn
        If bTemp = 61 Then
            Incr bIn
            bTemp = @bIn - 64
        End If
        bTemp = bTemp - 42
        @bOut = bTemp
        Incr bOut
    Next 
End Sub

Function PBMain 
    Dim s1 As String
    Dim s2 As String
    Dim cb As Dword 
    s1 = "Hallo" + Chr$(253)
    MsgBox "Text : " +  s1 + $CrLf + "Length : " + Str$(Len(s1)) , , "Before yCoding"
    s2 = Space$(Len(s1) * 2)
    yEncodeBuffer StrPtr(s1), Len(s1), StrPtr(s2), cb
    MsgBox "Text : " + s2 + $CrLf + "Length : " + Str$(cb) , , "yCoded"
    s1 = s2
    s2 = Space$(Len(s1))
    yDecodeBuffer StrPtr(s1), Len(s1), StrPtr(s2), cb
    MsgBox "Text : " + Mid$(s2,1,cb) + $CrLf + "Length : " + Str$(cb) , , "Restored from yCode" 
End Function

Back to The Archives