Waiting for Singularity

Thoughts on science, tech and other preoccupations

Decode This Message

A lesson in Base64 encoding

A recent hackathon offered a sweet discount to developers who could crack the following encoded message:


The last character of the message is “=” which points us to the right direction. Base64 encoding uses “=” as the character for padding.

According to Wikipedia:

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remains intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.

Solution in Python

    >>> import base64
    >>> coded_string = '''bmljZSBkZWNvZGluZyB5b3VuZyBwYWRhd2FuIFVzZSB5b3UgbXVzdCBsZWFybmVyIGZyZWUgdGlja2V0IGNvZGU6IEhBQ0tUQVNUSUM='''
    >>> base64.b64decode(coded_string)
    'nice decoding young padawan Use you must learner free ticket code: HACKTASTIC'

    To encode a message in Ruby: Base64.encode64(message)
    Tested in Python 2.7.2

Solution in Ruby

    2.0.0-p247 :001 > require 'base64'
     => true

    2.0.0-p247 :002 > coded_string = "bmljZSBkZWNvZGluZyB5b3VuZyBwYWRhd2FuIFVzZSB5b3UgbXVzdCBsZWFybmVyIGZyZWUgdGlja2V0IGNvZGU6IEhBQ0tUQVNUSUM="

    2.0.0-p247 :005 > puts Base64.decode64(coded_string)
    nice decoding young padawan Use you must learner free ticket code: HACKTASTIC
     => nil

    To encode a message in Python: base64.b64encode(message)
    Tested in Ruby 2.0.0

More on Base64 encoding in StackOverflow and Ruby-doc.