How to resolve the algorithm Base64 decode data step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Base64 decode data step by step in the Action! programming language
Table of Contents
Problem Statement
See Base64 encode data. Now write a program that takes the output of the Base64 encode data task as input and regenerate the original file. When working on the VBA implementation I found several 'solutions' on the net, including one from the software maker himself, that showed output with incorrect padding. Obviously with incorrect padding in the output you can not decode correctly to the original file again.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Base64 decode data step by step in the Action! programming language
Source code in the action! programming language
BYTE FUNC FindIndex(BYTE b)
IF b>='A AND b<='Z THEN
RETURN (b-'A)
ELSEIF b>='a AND b<='z THEN
RETURN (b-'a+26)
ELSEIF b>='0 AND b<='9 THEN
RETURN (b-'0+52)
ELSEIF b='+ THEN
RETURN (62)
ELSEIF b='/ THEN
RETURN (63)
FI
RETURN (-1)
PROC PrintChar(CHAR c)
IF c=10 THEN
PutE()
ELSE
Put(c)
FI
RETURN
PROC Decode(CHAR ARRAY s)
BYTE i,b1,b2,b3,b4,i1,i2,i3,i4
CHAR c
IF s(0) MOD 4#0 THEN
PrintE("Invalid length of string!!!")
Break()
FI
i=1
WHILE i<=s(0)
DO
b1=s(i) i==+1
b2=s(i) i==+1
b3=s(i) i==+1
b4=s(i) i==+1
i1=FindIndex(b1)
i2=FindIndex(b2)
c=i1 LSH 2
c==%i2 RSH 4
PrintChar(c)
IF b3#'= THEN
i3=FindIndex(b3)
c=(i2&$0F) LSH 4
c==%i3 RSH 2
PrintChar(c)
IF b4#'= THEN
i4=FindIndex(b4)
c=(i3&$03) LSH 6
c==%i4
PrintChar(c)
FI
FI
OD
RETURN
PROC Test(CHAR ARRAY s)
PrintE("Encoded:")
PrintE(s)
PutE()
PrintE("Decoded:")
Decode(s)
PutE()
RETURN
PROC Main()
Test("VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo")
RETURN
You may also check:How to resolve the algorithm Function definition step by step in the OCaml programming language
You may also check:How to resolve the algorithm Pick random element step by step in the Scala programming language
You may also check:How to resolve the algorithm Distributed programming step by step in the D programming language
You may also check:How to resolve the algorithm 100 prisoners step by step in the J programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the MIPS Assembly programming language