Warren Hinchliffe Posted December 7, 2021 Share Posted December 7, 2021 Hi Everyone, I had posted an example in the old forum of a Base64 encoder. Well there is a decoder. Its written in Dialog Manager. and is good for small strings. Have no idea how it would perform on a large string or a CLOB. The encoded string is supplied via the variable &B64_String and is also returned decoded via the same variable. -SET &BitString = '' ; -SET &BASE64CHars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ; -REPEAT ::To:Bits FOR &Cntr FROM 1 TO &B64_String.LENGTH ; -SET &B64Chr = SUBSTRING(&B64_String, &Cntr, 1) ; -SET &B64Num = POSITION(&B64Chr, &BASE64CHars) -1 ; -IF &B64Num EQ -1 THEN GOTO ::To:Bits ; -REPEAT ::Get:Bits FOR &BitCntr FROM 1 TO 6 ; -SET &Div = DECODE &BitCntr(1 32 2 16 3 8 4 4 5 2 6 1) ; -SET &Bit = &B64Num/&Div ; -SET &B64Num= IMOD(&B64Num,&Div,I2) ; -SET &BitString = RTRIM(&BitString) | &Bit ; -::Get:Bits -::To:Bits -SET &B64_String = '' ; -REPEAT ::Get:Byte FOR &Cntr FROM 1 TO &BitString.LENGTH ; -IF &Cntr + 7 GT &BitString.LENGTH THEN GOTO ::Get:Byte ; -SET &Test = SUBSTRING(&BitString,&Cntr+1,1) ; -SET &ByteNum = 128 * SUBSTRING(&BitString,&Cntr ,1) + - 64 * SUBSTRING(&BitString,&Cntr+1,1) + - 32 * SUBSTRING(&BitString,&Cntr+2,1) + - 16 * SUBSTRING(&BitString,&Cntr+3,1) + - 8 * SUBSTRING(&BitString,&Cntr+4,1) + - 4 * SUBSTRING(&BitString,&Cntr+5,1) + - 2 * SUBSTRING(&BitString,&Cntr+6,1) + - 1 * SUBSTRING(&BitString,&Cntr+7,1) ; -SET &Cntr = &Cntr + 7 ; -SET &B64_String = RTRIM(&B64_String) | HEXBYT(&ByteNum, 'A1') ; -::Get:Byte Link to comment Share on other sites More sharing options...
David Beagan Posted December 7, 2021 Share Posted December 7, 2021 Nice, thanks. If you wouldnt mind, could you put code tags around it Link to comment Share on other sites More sharing options...
Warren Hinchliffe Posted December 8, 2021 Author Share Posted December 8, 2021 Bugger, thought I had. All fixed now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now