Base64 encode data: Difference between revisions
Content added Content deleted
(→{{header|Commdore BASIC}}: Add implementation) |
|||
Line 490: | Line 490: | ||
AAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAE= |
AAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAE= |
||
</pre> |
</pre> |
||
=={{header|Commodore BASIC}}== |
|||
Assumes the source file is a PRG on disk, writes encoded file as a SEQ. This is all done in PETSCII; transfer out of Commodore-land will require translation of the Base64-encoded file into ASCII. |
|||
<lang basic>100 rem convert a binary file to base64 |
|||
110 dim a$(63): rem alphabet |
|||
120 dim i(2): rem input bytes |
|||
130 dim o$(3): rem output characters |
|||
140 for i=0 to 25 |
|||
150 : a$(i) = chr$(asc("A")+i) |
|||
160 : a$(26+i) = chr$(asc("a")+i) |
|||
170 : if i < 10 then a$(52+i) = chr$(asc("0")+i) |
|||
180 next i |
|||
190 a$(62) = "+" |
|||
200 a$(63) = "/" |
|||
210 p$="=":rem padding char |
|||
220 input "source file";s$ |
|||
230 open 1,8,2,s$+",p": if st then 450 |
|||
240 input "dest file";d$ |
|||
250 open 2,8,3,d$+",s,w": if st then 450 |
|||
260 for d=0 to 1 step 0: rem while not d(one) |
|||
270 : p=0:for o=0 to 3:o$(o)=p$:next o |
|||
280 : for i=0 to 2 |
|||
290 : i(i)=0 |
|||
300 : if d then 330 |
|||
310 : get#1,i$: if len(i$) then i(i)=asc(i$) |
|||
320 : if st and 64 then p=2-i:d=1 |
|||
330 : next i |
|||
340 : o$(0) = a$( (i(0) and 252) / 4 ) |
|||
350 : o$(1) = a$( (i(0) and 3) * 16 + (i(1) and 240) / 16 ) |
|||
360 : if p<2 then o$(2) = a$( (i(1) and 15) * 4 + (i(2) and 192) / 64 ) |
|||
370 : if p<1 then o$(3) = a$( i(2) and 63 ) |
|||
380 : for o=0 to 3: print o$(o);:print#2, o$(o);:next o |
|||
390 : c=c+4:if c >= 76 then c=0:print:print#2,chr$(13); |
|||
400 next d |
|||
410 print:print#2,chr$(13); |
|||
420 close 1 |
|||
430 close 2 |
|||
440 end |
|||
450 print "error:"st |
|||
460 open 15,8,15:input#15,ds,ds$,a,b:close15 |
|||
470 print ds,ds$,a,b</lang> |
|||
{{Out}} |
|||
<pre>AAABAAIAEBAAAAAAAABoBQAAJgAAACAgAAAAAAAAqAgAAI4FAAAoAAAAEAAAACAAAAABAAgAAAAA |
|||
AEABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wCGiYcARkhHAL/ ...</pre> |
|||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |