var app = require('express').createServer();

var lightsaber = " \
102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;117;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;110;;;;;;;;;;;;;;;;;;; \
;;;;;;;99;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;116;;;;;; \
;;;105;;;;;;;;:;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;:,::;;;;;;;;;;111;;;;;;;;;;; \
;;;;;;110;;;;:``:;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;,  ,;;;;;;;;;;;;;;;;40;;; \
36;;;;;;;;;;;,  ,;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;,  ,;;;;;;;;;;;;;;;;;;;41 \
;;;;;;;;;;123:  ,;;;;;;;;;;;;;;;;;;;;; \
36;;;;;;;;;;;:  ,;;;;;;;;;;;;;;;;;;;;; \
;;;;61;;;;;;;:  .;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;:` .;;;;;;;;;;;;;;;;;39;; \
;;;;;;;;;;;;;:` .:;;;;;;;;;;;;48;;;;;; \
;;;;120;;;;;;:` .:;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;:` `:;;;;;;;;;39;;;;;;;;; \
;;;43;;;;;;;;:. `:;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;:. `:;;;;;;;;;;36;;;;;;;; \
46;;;;;;;;;;;;.  :;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;.  :;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;,  :;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;,  :;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;,  ,;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;,  ,;;;;;;;;;;;;;;;;;;;; \
;;;;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;;;;;;;;;;53;;;;;;:,;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;+:';;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;`.;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;`.;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;`.;;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;`.;;;;;;;;;;;;;53; \
;;;;;;;;;;;;;;;;;;;;`.:;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;..:;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;..:;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;..:;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;,.:;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;'+';;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;:';;;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;':';;;;;;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;;.,;;;93;;;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;; May the force be with you ;;;; \
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;;;; 愿原力与你同在 ;;;;;;;;;;;;; \
;;;;;;125;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
http://en.wikipedia.org/wiki/Lightsaber\
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \
;;;;;;;;; cfddream@gmaile.com ;;;;;;;; \
;;;;;;;; lightsaber.aws.af.cm ;;;;;;;; \
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;";

app.get('/', function(req, res) {
  var vm  = require('vm')
    , f = lightsaber.match(/\d+/g)
    , sandbox = {
        encode: ucs2encode
      , $: '~(8,8)~'
    }
    , hbo = ''
    // What's this?
    , $ = '4861707079204269727468646179204F70656E537461636B'
    , i = 0
    , l;

  vm.runInNewContext('$ = encode([' + f.toString() + '])', sandbox, 'lightsaber.vm');
  f = new Function("$", sandbox.$.substr(12, 70));
  l = $.length / 6;

  for (; i < l; ++i) {
    hbo += ucs2encode(f($.substr(i * 6).substr(0, 6)));
  }

  res.send(hbo);
});

app.get('/src', function(req, res) {
  res.charset = 'UTF-8';
  res.sendfile(__filename);
});

app.listen(process.env.VCAP_APP_PORT || 3000);

// helper
// ----------------------------------------------------------------------------
var stringFromCharCode = String.fromCharCode;
function ucs2encode(array) {
  var output = '', value;
  for (var i = 0, l = array.length; i < l; ++i) {
    value = array[i];
    if (value > 0xFFFF) {
      value -= 0x10000;
      output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
      value = 0xDC00 | value & 0x3FF;
    }
    output += stringFromCharCode(value);
  }
  return output;
}
