Base64 encode data: Difference between revisions

Content added Content deleted
(Add entry for SenseTalk)
m (→‎{{header|REXX}}: fixed a typo, added whitespace.)
Line 1,355: Line 1,355:
A much higher value for   '''chunk'''   could be used for modern systems or implementations.
A much higher value for   '''chunk'''   could be used for modern systems or implementations.
<lang rexx>/*REXX program converts text (from a file or the C.L.) to a base64 text string. */
<lang rexx>/*REXX program converts text (from a file or the C.L.) to a base64 text string. */
parse arg iFID @ /*pbtaom optional arguments from the CL*/
parse arg iFID @ /*obtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
chunk=20000 /*# of bytes to read a file at one time*/
chunk= 20000 /*# of bytes to read a file at one time*/
/*If @ isn't a blank, then use CL text.*/
/*If @ isn't a blank, then use CL text.*/
if @='' then do s=1 by chunk until y=='' /* " " is " " " " the file*/
if @='' then do s=1 by chunk until y=='' /* " " is " " " " the file*/
y=charin(iFID, s, chunk) /*read a chunk of the file, assign to Y*/
y= charin(iFID, s, chunk) /*read a chunk of the file, assign to Y*/
@=@ || y /*append the chunk (Y) to the @ var*/
@= @ || y /*append the chunk (Y) to the @ var*/
end /*s*/ /* [↑] read a chunk of the file ──► @ */
end /*s*/ /* [↑] read a chunk of the file ──► @ */
t=base64(@) /*convert the @ string to base 64.*/
t= base64(@) /*convert the @ string to base 64.*/
say center(' input', 79, "─"); say @ /*show the header and the input text.*/
say center(' input', 79, "─"); say @ /*show the header and the input text.*/
say center('base64', 79, "─"); say t /* " " " " " base64 " */
say center('base64', 79, "─"); say t /* " " " " " base64 " */
Line 1,372: Line 1,372:


do i=0 for 64 /*process each char in the Z string. */
do i=0 for 64 /*process each char in the Z string. */
!.i=substr(z, i+1, 1) /*assign a char of Z to a ! element*/
!.i= substr(z, i + 1, 1) /*assign a char of Z to a ! element*/
end /*i*/
end /*i*/


b=x2b( c2x(Q) )0000000000000000 /*Q ──► binary, add some zero padding.*/
b= x2b( c2x(Q) )0000000000000000 /*Q ──► binary, add some zero padding.*/
L=length(Q) * 8 /*compute Q's length (in bits). */
L= length(Q) * 8 /*compute Q's length (in bits). */


do j=1 by 6 to L /*traipse through bit string by six. */
do j=1 by 6 to L /*traipse through bit string by six. */
_=x2d( b2x( substr(b, j, 6) )) /*compute index into the BASE64 table. */
_= x2d( b2x( substr(b, j, 6) ) ) /*compute index into the BASE64 table. */
$=$ || !._ /*append to $ (the output string). */
$= $ || !._ /*append to $ (the output string). */
end /*j*/
end /*j*/
/* [↓] maybe append equal signs to $. */
/* [↓] maybe append equal signs to $. */