PowerBASIC Forums
  Source Code
  yEnc basic implementation

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   yEnc basic implementation
Torsten Rienow
Member
posted May 02, 2003 12:45 PM     Click Here to See the Profile for Torsten Rienow     Edit/Delete Message   Reply w/Quote
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.


#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

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

IP: Logged

Steve Smith
Member
posted August 01, 2004 10:28 PM     Click Here to See the Profile for Steve Smith     Edit/Delete Message   Reply w/Quote
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

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

IP: Logged

All times are EasternTime (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | PowerBASIC BASIC Compilers

Copyright © 1999-2005 PowerBASIC, Inc. All Rights Reserved.


Ultimate Bulletin Board 5.45c