Base64 encode data: Difference between revisions

m
→‎{{header|REXX}}: fixed a typo, added whitespace.
(Add entry for SenseTalk)
m (→‎{{header|REXX}}: fixed a typo, added whitespace.)
Line 1,355:
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. */
parse arg iFID @ /*pbtaomobtain optional arguments from the CL*/
if iFID=='' | iFID=="," then iFID='favicon.ico' /*Not specified? Then use the default.*/
chunk=20000 20000 /*# of bytes to read a file at one time*/
/*If @ isn't a blank, then use CL text.*/
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 /*append the chunk (Y) to the @ var*/
end /*s*/ /* [↑] read a chunk of the file ──► @ */
t= base64(@) /*convert the @ string to base 64.*/
say center(' input', 79, "─"); say @ /*show the header and the input text.*/
say center('base64', 79, "─"); say t /* " " " " " base64 " */
Line 1,372:
 
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*/
end /*i*/
 
b= x2b( c2x(Q) )0000000000000000 /*Q ──► binary, add some zero padding.*/
L= length(Q) * 8 /*compute Q's length (in bits). */
 
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. */
$= $ || !._ /*append to $ (the output string). */
end /*j*/
/* [↓] maybe append equal signs to $. */