[GRANTED] SC function wish - Base64 encoding/decoding

Features wanted...
admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by admin »

OK, this seems to work for Marco's case:

Code: Select all

$Path = "<curitem>";
 $Encoding = Base64Encode($Path, 2);
 WriteFile("<curitem>.Base64.txt", $Encoding, , "t");
 $File = Base64Decode($Encoding, 0);
 WriteFile("<curitem>.after.txt", $File, , "t");
But does it work in Japanese locale?

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by Enternal »

admin wrote:OK, this seems to work for Marco's case:

Code: Select all

$Path = "<curitem>";
 $Encoding = Base64Encode($Path, 2);
 WriteFile("<curitem>.Base64.txt", $Encoding, , "t");
 $File = Base64Decode($Encoding, 0);
 WriteFile("<curitem>.after.txt", $File, , "t");
But does it work in Japanese locale?
So I tested that and no it does not work. Furthermore, the Base64 file that was created, when I decoded that, the text in the file were the same but when comparing the hex values, it was missing a value. Basically missing a byte.
Results.zip
(1.06 KiB) Downloaded 141 times
When I changed the file ENCODETEST.txt to UTF-16 however, decoding the Base64 file works perfectly. However, the *.after.txt file still does not work.

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by admin »

OK, this one should work (in the next beta -- v14.20.0311):

Code: Select all

// Base64 encode/decode, directly from/to file
 $curitem = <curitem>;
 $Encoding = Base64Encode($curitem, 2, "$curitem.Base64.txt");
 Base64Decode($Encoding, 0, "$curitem.after.txt");
You see a new third optional argument where you can state an output file. This way you can avoid going via a string variable (creating possible locale issues).

Code: Select all

    ' syntax: base64decode(text, [flags], [targetfile])
    '   text: text to decode
    '   flags:
    '     1 = originally encoded string was unicode (no need to convert return string to unicode)
    '     2 = input string points to file
    '   targetfile: write decoded bytes to this file (not affected by return string format)
    '     on exist file is overwritten without asking

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by admin »

PS: Slightly better script that preserves the original extension in the final target file:

Code: Select all

// Base64 encode/decode, directly from/to file
 $curitem = <curitem>;
 $curext = <curext>;
 $Encoding = Base64Encode($curitem, 2, "$curitem.Base64.txt");
 Base64Decode($Encoding, 0, "$curitem.after.$curext");

admin
Site Admin
Posts: 64841
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by admin »

So, is everybody happy now?

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by Marco »

Just tested, everything seems to be working fine :D
Do you have some specific files that you want us (Enternal and me) to test perhaps?
Also... I wonder if hexdump could benefit from such improvements...
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: [GRANTED] SC function wish - Base64 encoding/decoding

Post by Enternal »

Yep everything is peeerrfffeeect! Awesome! :biggrin:

Also, Marco, I can't read what you wrote :ninja:

Post Reply