playing with encoding

by Darby Rathbone

HTML

<form action="submit"></form><input id='text' type="text"></input>
<input type='submit' id='button'></input>
<label id='label' for=""></label></form>
<div id='colors'>colors <div style="background:#00ff00">1</div></div>
<div id='decimal'></div>
<div id='string'></div>

CSS

#colors > div{
  display:inline;
}

JavaScript

var text = document.getElementById('text')
	,	button = document.getElementById('button')
  ,	label = document.getElementById('label')
  ,	colors = document.getElementById('colors')
	,	value = ''
  ,	decimal = document.getElementById('decimal')
  ,	string = document.getElementById('string')
  ,	colorstring = '';
function splitString (string, size) {
	var re = new RegExp('.{1,' + size + '}', 'g');
	return string.match(re);
}
text.addEventListener('keypress',function(e){if(e.charCode ==13)button.click();});
  button.addEventListener('click',function(){
  	value = '';
    colorstring = '';
		text.value.split('').forEach(function(e){
    	switch(e.charCodeAt(0).toString().length){
      	case 1:value +="00"+e.charCodeAt(0);break;
      	case 2:value +="0"+e.charCodeAt(0);break;
        case 3:value +=e.charCodeAt(0);break;
      }
	//		value += e.charCodeAt(0);
		});
    value = decToHex(value);
    splitString(value,6).forEach(function(e,i){
    	colorstring +="<div style='background:#"+e+"'>"+e+"</div>";
    });
    decimal.innerHTML = hexToDec(value);
    
    colors.innerHTML = colorstring;
    label.innerHTML = value;
   	string.innerHTML = splitString( hexToDec(value).split('').reverse().join('') ,3).reverse().map( function(e){ return String.fromCharCode( e.split('').reverse().join('') );} ).join('');
});

function add(x, y, base) {
  var z = [];
  var n = Math.max(x.length, y.length);
  var carry = 0;
  var i = 0;
  while (i < n || carry) {
    var xi = i < x.length ? x[i] : 0;
    var yi = i < y.length ? y[i] : 0;
    var zi = carry + xi + yi;
    z.push(zi % base);
    carry = Math.floor(zi / base);
    i++;
  }
  return z;
}

// Returns a*x, where x is an array of decimal digits and a is an ordinary
// JavaScript number. base is the number base of the array x.
function multiplyByNumber(num, x, base) {
  if (num < 0) return null;
  if (num == 0) return [];

  var result = [];
  var power = x;
  while (true) {
    if (num & 1) {
      result = add(result,...