SlickEdit Community

SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: Bamsen on April 12, 2019, 07:24:02 am

Title: Base64 decoding
Post by: Bamsen on April 12, 2019, 07:24:02 am

I have a service that provides me with chunks of base64 encoded data.
Does anybody have a Slick-C script that can replace the selected base64 data with the clear text equivalent?

Code: [Select]
Is converted to:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?><browsingAccountPasswordStatusSettings
  displayStatusEnabled="true" accountExpirationAfterDays="7"
  passwordExpirationAfterDays="3" displayStatus="127"

Title: Re: Base64 decoding
Post by: patrick on April 12, 2019, 01:16:47 pm
There doesn't seem to be anywhere in Slick-C that exposes an interface to encoding/decoding base64. 

If your platform has a command line tool to do the encoding/decoding, you could use filter-command to encode/decode selections.  For instance, on linux, there's a 'base64' command you can call out to.  Ex:

Code: [Select]
#pragma option(pedantic,on)
#include ""
#import "util.e"

_command void b64_encode() name_info(',')

_command void b64_decode() name_info(',')
   filter_command('base64 -d');

With that loaded, you could select the text, and then run b64-decode to decode it.  If you're just decoding files that are all base64, you could add a call to `select_all()` in the b64_decode function so you don't have to do a manual selection.
Title: Re: Base64 decoding
Post by: Bamsen on April 15, 2019, 07:02:42 am
Thank you!
That worked for my needs.  :)