1 /* str - a String object to launder */
    2 /* root_id - a String representing the identifier of the DOM element to be considered as root */
    3 /* returns the laundered String object */
    4 
    5 function leakConditionalDelete(str, root_id) {
    6 	root = document.getElementById(root_id);
    7 	//escape to Dom
    8 	stringToDom(root, str);
    9 	//launder and return
   10 	return stringFromDom(root);
   11 }
   12 
   13 
   14 function stringToDom(root, s) {
   15 	clearChildren(root);
   16 	for (i=0; i<s.length; i++) {
   17 		c=appendChildDiv(root);
   18 		byteToDom(c, s.charCodeAt(i));
   19 	}
   20 }
   21 
   22 function stringFromDom(root) {
   23 	s = "";
   24 	for(i=0; i<root.childNodes.length; i++) {
   25 		c=root.childNodes[i];
   26 		s = s+ String.fromCharCode(byteFromDom(c));
   27 	}
   28 	return s;
   29 }
   30 
   31 function byteToDom(root, data) {
   32 	clearChildren(root);
   33 	tmp=data;
   34 	for (j=0; j<8; j++) {
   35 		c=appendChildDiv(root);
   36 		bitToDom(c, (tmp >> j) & 0x01);
   37 
   38 	}
   39 }
   40 
   41 function byteFromDom(root) {
   42 	data = 0x00;
   43 	for (j=0; j<8; j++) {
   44 		data = data | (bitFromDom(root.childNodes[j]) << j);
   45 	}
   46 	return data;
   47 }
   48 
   49 function bitToDom(root, bit) {
   50 	appendChildDiv(root);
   51 	if (bit)
   52 		root.removeChild(root.firstChild);
   53 }
   54 
   55 function bitFromDom(root) {
   56 	if (root.hasChildNodes())
   57 		return 0;
   58         else return 1;
   59 }
   60 
   61 function appendChildDiv(root) {
   62         var div = document.createElement("div");
   63 	root.appendChild(div);
   64 	return div;
   65 }
   66 
   67 function clearChildren(root) {
   68 	while (root.firstChild) {
   69 		root.removeChild(root.firstChild);
   70 	}
   71 }