2024-11-21

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

yEnc

Algorithm creator(s)

Jürgen Helbing


PB author(s)

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.


Note

n/a


Source

https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/24967-yenc-basic-implementation?t=24318


See also


Source Code

Download source code file yenc.bas (Right-click -> "Save as ...")

#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

Mirror provided by Knuth Konrad