Why Care Block: Happy New Year! We're starting 2016 with a bang, including this three part series on acquiring Fitbit data through Fitbit’s API services. 2015 was a great year and marked the start of this website, and I can guarantee that there will be much more content to come. See the new "Why Care Block"? It’s inspired by a Holiday conversation with family and gives a brief synopsis of why we’re even doing this in the first place. With that, let's talk about the topic of the day: Base64 encoding. Base64 encoding exists for some privacy purpose. That's about all I want to say about Base64 encoding. Let's just look at an example, they’re a lot cooler. Say for instance we have the phrase: “This is kinda boring…” By converting every character to ASCII bytes (and by potentially adding padding), converting each byte to base 2, taking the 8-bit representation of the binary character and convert it to a six bits, converting that back to base 10, and using those numbers (they fall between 0 and 63) to look up the corresponding character of the alphabet plus two other characters, we finally arrive at the following encoded string: "VGhpcyBpcyBraW5kYSBib3JpbmcuLi4=" While they mean the same thing, I think the first phrase was a little more accurate. We can encode this second phrase a second time and it gives us: "VkdocGN5QnBjeUJyYVc1a1lTQmliM0pwYm1jdUxpND0=" Now you can easily send encoded messages to your friend (not plural – I can't imagine that many people would tolerate this type of behavior). I’ve put together a Stata package containing these routines; however, no help file is available upon the first release. Here is a brief overview of the new commands, encode64 and decode64 at work. We first called encode64 on the string "client_id:123456789" to encode this value in Base64. The result shows under the command, but is also callable through the macro r(base64). We create a local macro that contains this encoded value ("Y2xpZW50X2lkOjEyMzQ1Njc4OQ==") and decode this message to get back to our original string. It's a lot less fun than my old Nintendo 64, but trust me, the results will be extremely rewarding! Feel free to download the ado file below.
5 Comments
2/22/2019 04:14:49 pm
This was extremely helpful to get our team to decode base64 images to png. However, Stata didn't really like how long our strings were, and it is more practical in our use case to just use the shell.
Reply
RW
11/17/2021 12:32:49 pm
Was an ado file for decode64 supposed to be somewhere on this page as well? I downloaded encode64 and it works great, but can't seem to find the decode version. Thanks!
Reply
Will
11/17/2021 01:08:37 pm
Hi RW
Reply
RW
11/17/2021 01:16:59 pm
Oh nice, I didn't realize it was in there--I split it out into its own ado and it's working great. Thanks for putting this together! Leave a Reply. |
AuthorWill Matsuoka is the creator of W=M/Stata - he likes creativity and simplicity, taking pictures of food, competition, and anything that can be analyzed. Archives
July 2016
Categories
All
|