Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

yEnc basic implementation

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • yEnc basic implementation

    Please visit www.yenc.org to unterstand what yEnc is.
    In short, yEnc is an encoding sheme similar to UUE or BASE64
    with much (much much much) less overhead and encoded data.
    I use it to encode text/binary data for storage in XML files.

    Code:
    #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
    ------------------

  • #2
    Torsten, I started writing my own yEnc tool and it didn't seem to be decoding correctly. When I do a file compare of the original picture and the decoded version, the binary gets screwed up somewhere in the file. So I trashed mine and used yours, thinking I was doing something wrong. But using your program, I have the same problem. I have tried multiple files. It always seems to start having problems at byte 124 and then the comparison gets out of sync. have you noticed anything, or is it just me?

    Steve


    ------------------

    Comment

    Working...
    X