BASE64DEC
(Created page with "= <span class="f_Header">Action</span> = Converts Base-64 data into the original data. <span style="font-family: Arial;"> </span> <span style="font-family: Arial;">&nb...") |
|||
(3 intermediate revisions by one user not shown) | |||
Line 9: | Line 9: | ||
= <span class="f_Header">Syntax</span> = | = <span class="f_Header">Syntax</span> = | ||
− | Result = | + | Result = <span class="f_Syntax">BASE64DEC</span>( source) |
+ | |||
+ | array = <span class="f_Syntax">BASE64DEC</span>( source, elements) | ||
+ | |||
+ | | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
Line 16: | Line 20: | ||
= <span class="f_Header">Remarks</span> = | = <span class="f_Header">Remarks</span> = | ||
− | <div style="padding: 0px; margin: 0px 0px 0px 4px;"> | + | <div style="padding: 0px; margin: 0px 0px 0px 4px;"><div style="padding: 0px; margin: 0px 0px 0px 4px;"> |
− | + | {| style="border: solid 2px #000000; border-spacing:0px; border-collapse: collapse;" width="609" cellspacing="0" cellpadding="1" border="1" | |
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
− | | | + | | style="width:13%; border: solid 1px #000000;" width="13%" valign="top" | |
Result | Result | ||
− | | | + | | style="width:100%; border: solid 1px #000000;" width="100%" valign="top" | |
A string variable that is assigned with the un-coded string. | A string variable that is assigned with the un-coded string. | ||
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
− | | | + | | style="width:13%; border: solid 1px #000000;" width="13%" valign="top" | |
Source | Source | ||
− | | | + | | style="width:100%; border: solid 1px #000000;" width="100%" valign="top" | |
The source string that is coded with base-64. | The source string that is coded with base-64. | ||
+ | |||
+ | |- style="vertical-align: top;" | ||
+ | | style="width:13%; border: solid 1px #000000;" width="13%" valign="top" | | ||
+ | array | ||
+ | |||
+ | | style="width:100%; border: solid 1px #000000;" width="100%" valign="top" | | ||
+ | A byte array that is assigned with the un-coded strings | ||
+ | |||
+ | |- style="vertical-align: top;" | ||
+ | | style="width:13%; border: solid 1px #000000;" width="13%" valign="top" | | ||
+ | elements | ||
+ | |||
+ | | style="width:100%; border: solid 1px #000000;" width="100%" valign="top" | | ||
+ | The number of elements in the resulting array | ||
|} | |} | ||
Line 46: | Line 64: | ||
Base-64 coded strings are always in pairs of 4 bytes. These 4 bytes represent 3 bytes. | Base-64 coded strings are always in pairs of 4 bytes. These 4 bytes represent 3 bytes. | ||
+ | | ||
+ | |||
+ | Because strings can not contain a 0 byte, there is an alternative syntax. Instead of a string you assign a byte array. | ||
+ | |||
+ | The byte variable ELEMENTS is assigned with the number of elements filled with data. | ||
+ | </div> | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
Line 78: | Line 102: | ||
End | End | ||
+ | </source> | ||
+ | |||
+ | <br/><source lang="bascomavr"> | ||
+ | $regfile = "m32U4def.dat" | ||
+ | $crystal = 16000000 | ||
+ | $baud = 19200 | ||
+ | |||
+ | Dim S As String * 80 , Z As String * 80 , B As Byte , J As Byte | ||
+ | Dim Ar(81) As Byte At S Overlay | ||
+ | |||
+ | S = "This is a test" 'while we load the array with string data, we could load it with any data that can contain a 0. | ||
+ | |||
+ | B = Len(s) + 1 'get the length and the 0 byte Z = Base64enc(ar(1) , B) 'use an array Print Z | ||
+ | |||
+ | Ar(1) = Base64dec(z , B) 'now B will hold the number of elements | ||
+ | |||
+ | Print B | ||
+ | |||
+ | 'Another example Ar(1) = 0 : Ar(2) = 1 : Ar(3) = 2 Z = Base64enc(ar(1) , 3) 'use an array Print Z | ||
+ | |||
+ | Ar(1) = Base64dec(z , B) 'now B will hold the number of elements For J = 1 To B | ||
+ | |||
+ | Print Ar(j) | ||
+ | |||
+ | Next End | ||
+ | |||
</source><br/>{{Languages}} | </source><br/>{{Languages}} | ||
− | [[Category: | + | [[Category:BASCOM Language Reference]] |
Latest revision as of 20:02, 17 January 2017
Contents |
Action
Converts Base-64 data into the original data.
Syntax
Result = BASE64DEC( source)
array = BASE64DEC( source, elements)
Remarks
Result |
A string variable that is assigned with the un-coded string. |
Source |
The source string that is coded with base-64. |
array |
A byte array that is assigned with the un-coded strings |
elements |
The number of elements in the resulting array |
Base-64 is not an encryption protocol. It sends data in 7-bit ASCII data format. MIME, web servers, and other Internet servers and clients use Base-64 coding.
The provided Base64Dec() function is a decoding function. It was written to add authentication to the web server sample.
When the web server asks for authentication, the client will send the user and password unencrypted, but base-64 coded to the web server.
Base-64 coded strings are always in pairs of 4 bytes. These 4 bytes represent 3 bytes.
Because strings can not contain a 0 byte, there is an alternative syntax. Instead of a string you assign a byte array.
The byte variable ELEMENTS is assigned with the number of elements filled with data.
See also
CONFIG TCPIP , GETSOCKET , SOCKETCONNECT , SOCKETSTAT , TCPWRITE , TCPWRITESTR , CLOSESOCKET , SOCKETLISTEN , BASE64ENC
Example
$regfile = "m48def.dat" ' specify the used micro $crystal = 8000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space $lib "tcpip.lbx" Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0 Dim S As String * 15 , Z As String * 15 S = "bWFyazptYXJr" Z = Base64dec(s) Print Z 'mark:mark End
$regfile = "m32U4def.dat" $crystal = 16000000 $baud = 19200 Dim S As String * 80 , Z As String * 80 , B As Byte , J As Byte Dim Ar(81) As Byte At S Overlay S = "This is a test" 'while we load the array with string data, we could load it with any data that can contain a 0. B = Len(s) + 1 'get the length and the 0 byte Z = Base64enc(ar(1) , B) 'use an array Print Z Ar(1) = Base64dec(z , B) 'now B will hold the number of elements Print B 'Another example Ar(1) = 0 : Ar(2) = 1 : Ar(3) = 2 Z = Base64enc(ar(1) , 3) 'use an array Print Z Ar(1) = Base64dec(z , B) 'now B will hold the number of elements For J = 1 To B Print Ar(j) Next End
Languages | English • Deutsch |
---|