BASE64 DECODE

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Num3.


Well PB encodes to base64...

And what about decoding a b64 file/string ???

--
Kind Regards

Rui Carvalho

Current PB Projects:
[Construdata 2003 - 30%]
[Step by Step - 50%]
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

To clear things up: this is not my code!

Found this some time ago in the german forum, don't recall who did this.
(Shame on me, forgot to write it down...)

The only change I did, was to change the input data from a pointer to a string - now it's equal to the encoding command in pb.

Code: Select all

Procedure Base64Decoder(b64in$, b64len.l ,*b64out, b64max.l)
  *b64in.l = @b64in$ ;  0
        If b64num = 65
          b64pad +1
        EndIf
        b64bin$ +Right("000000" + Bin(b64num-1),6)   ;24 Bit code
      Else
        b64err = 1
        b64xln = b64tln +1
      EndIf
    Next b64xb

    For b64xu = 0 To 2-b64pad
      b64bit$ = Mid(b64bin$,1+b64xu*8,8) + "|"
      b64num = FindString(b64asc$,b64bit$,0) /9     ;ASC Code 8 Bit Binary
      PokeS(*b64out+b64buf,Chr(b64Num))
      b64buf +1
      If b64buf >b64max
        b64err = 1
        b64xln = b64tln +1
      EndIf
    Next b64xu

  Next b64xln

  If b64err = 1
    RtlFillMemory_(*b64out,b64max,0)
    b64buf = -1
  EndIf
  ProcedureReturn b64buf
EndProcedure 
Have a nice day...

Franco
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

8)=

Code: Select all

8)
--jb


b64asc$ = b64asc$ + Right("0000000" + Bin(b64x),8) + "|"

Code: Select all

  For b64x = 0 To 255
    b64asc$ = b64asc$ + Right("0000000" + Bin(b64x),8) + "|"               ;ASC Binary Code
  Next b64x

b64bit$ = Mid(b64bin$,1+b64xu*8,8) + "|"

Code: Select all

    For b64xu = 0 To 2-b64pad
      b64bit$ = Mid(b64bin$,1+b64xu*8,8) + "|"
      b64num = FindString(b64asc$,b64bit$,0) /9     ;ASC Code 8 Bit Binary
      PokeS(*b64out+b64buf,Chr(b64Num))
      b64buf +1
      If b64buf >b64max
        b64err = 1
        b64xln = b64tln +1
      EndIf
    Next b64xu
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

:lol:
Suppose this will not be the last funny transition code we will see...

Franco
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Is it better like this?

The smileys can be disabled in the posts btw.

Timo
quidquid Latine dictum sit altum videtur
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post by TronDoc »

:idea:
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Post Reply