Skip to main content
6 of 7
Update
GOTO 0
  • 822
  • 5
  • 14

Javascript, 18 characters

alert(btoa('ÛMx'))

Update: in ES6, using a template literal can save two characters:

alert(btoa`ÛMx`)

The code above is fairly easy to understand by keeping in mind that btoa converts a string into another string according to a set of well-defined rules (RFC 4648). To see how the conversion works, we're going to write the input string "ÛMx" as a sequence of binary digits, where each character is rendered as its 8-bit character code.

Input character          |        Û |        M |        x
Character code (decimal) |      219 |       77 |      120
Character code (binary)  | 11011011 | 01001101 | 01111000

After reorganizing the binary digits in the last row in groups of 6, we get the binary representation of 4 new numbers, corresponding to the Base64 indices of the 4 characters in the string "2014".

Base64 index (binary)  | 110110 | 110100 | 110101 | 111000
Base64 index (decimal) |     54 |     52 |     53 |     56
Output character       |      2 |      0 |      1 |      4

As per HTML specification, the output characters can be retrieved from their Base64 indices according to this table: http://dev.w3.org/html5/spec-LC/webappapis.html#base64-table.

If you don't care about the details, you could let the browser do the calculations for you and find out that "ÛMx" is the result of evaluating atob('2014') in Javascript.

GOTO 0
  • 822
  • 5
  • 14