| 1>1 |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var DEBUG = true |
| var maxdeep = 3 |
| |
| var base64 = WSH.StdIn.ReadAll() |
| var map = [] |
| |
| var len = base64.length |
| var text = compress(base64.replace(/\r\n/gm,''), maxdeep) |
| WSH.StdOut.WriteLine('') |
| WSH.StdOut.WriteLine(text) |
| WSH.StdOut.WriteLine('') |
| WSH.StdOut.WriteLine('#Before = #' + len) |
| WSH.StdOut.WriteLine('#After = #' + text.length) |
| |
| WSH.StdErr.WriteLine(text) |
| |
| |
| function compress(text, deep){ |
| deep = deep || 3 |
| if(deep>36)deep = 36 |
| |
| var from_list = [ |
| [ |
| {from:'#', mode:'#'}, |
| {from:'$', mode:'#'}, |
| {from:'@', mode:'#'}, |
| {from:'|', mode:'#'} |
| ] |
| ] |
| |
| text = convolution(text,from_list[0],0) |
| |
| var len = text.length |
| for(var i=1; i<=deep; i++){ |
| var $len = text.length |
| var from_arr = sample(text, i) |
| from_list.push(from_arr) |
| text = convolution(text,from_arr,i) |
| text = getHead(from_arr,i) + text |
| if(DEBUG)WSH.Echo('\r\n'+len +' -> '+$len+' -> '+text.length+'\r\n') |
| } |
| |
| return text.replace(/^\|+/,'').replace(/\|+/,'|') |
| |
| |
| function getHead(from_arr){ |
| if(!from_arr.length)return '' |
| var head='' |
| |
| for(var i=0; i<from_arr.length; i++){ |
| switch(from_arr[i].mode){ |
| case '$': |
| head+='$'+from_arr[i].map+from_arr[i].from |
| break |
| |
| case '@': |
| head+='@'+from_arr[i].map+from_arr[i].from+from_arr[i].list |
| break |
| } |
| } |
| head+='|' |
| return head |
| } |
| |
| function sample(text, index_deep){ |
| var from_map_repeat = {} |
| var from_map_like = {} |
| var from_map_like_stack = [] |
| |
| if(index_deep==1){ |
| var pattern = /(.+?)\1{2,36}/gm |
| } else { |
| var pattern = /(.+?)\1{2,36}|(..+)(?:[^@]{1,5}?\2)+/gm |
| } |
| pattern.lastIndex = 0 |
| |
| while((matches=pattern.exec(text)) != null){ |
| if(DEBUG)WSH.StdOut.Write('\r\t\t\t\rpattern.lastIndex = ' + pattern.lastIndex) |
| |
| if(matches[1]){ |
| checkrepeat(pattern,matches[0],matches[1]) |
| } else { |
| checklike(pattern,matches[0],matches[2]) |
| } |
| } |
| |
| function checkrepeat(pattern,str,$1){ |
| var cutoff = str.length - $1.length - 7 |
| if('$'+$1 in from_map_repeat){ |
| cutoff = str.length - 4 |
| from_map_repeat['$'+$1].cutoff += cutoff |
| } else { |
| cutoff = str.length - $1.length - 7 |
| from_map_repeat['$'+$1] = {from:$1, mode:'$', cutoff:cutoff} |
| } |
| from_map_like_stack = [] |
| } |
| |
| function checklike(pattern,str,$2){ |
| var $$2 = $2.replace(/\W/gm,'\\$&') |
| |
| var nextIndex = $2.length<2 ? pattern.lastIndex : pattern.lastIndex - str.length + 1 |
| |
| str = str.replace( |
| new RegExp('('+$$2+')(?='+$$2+')$','gm'), |
| function(repeat){pattern.lastIndex-=repeat.length;return ''} |
| ) |
| var list = convolution(str,from_list[0],index_deep).replace(new RegExp($2.replace(/\W/gm,'\\$&'),'gm'),'@') |
| |
| var cutoff |
| if(str in from_map_like){ |
| cutoff = str.length - 4 |
| from_map_like[str].cutoff += str.length - 4 |
| } else { |
| str=list.replace(/@/g,$2.replace(/\W/g,'\\$&')) |
| cutoff = str.length - list.length - 7 |
| from_map_like[str] = {from:$2, mode:'@', str:str, list:list, cutoff:cutoff} |
| } |
| from_map_like[str].$length = $2.length+list.substr(1).search('@') |
| var thisstack = {lastIndex:pattern.lastIndex, $length:$2.length+list.substr(1).search('@'), flag:true, cutoff:cutoff, ref:from_map_like[str]} |
| from_map_like_stack.push(thisstack) |
| |
| for(var i=from_map_like_stack.length;i--;){ |
| var stack = from_map_like_stack[i] |
| var endof = stack.lastIndex+stack.$length |
| |
| if(endof<pattern.lastIndex){ |
| from_map_like_stack.splice(i+1) |
| break |
| } else if(stack.cutoff > cutoff){ |
| if(stack.ref.flag)stack.ref.cutoff -= cutoff |
| stack.ref.flag = false |
| } else { |
| thisstack.ref.cutoff -= cutoff |
| thisstack.flag = false |
| } |
| } |
| |
| pattern.lastIndex = nextIndex |
| |
| return str |
| } |
| |
| var from_arr = [] |
| for(var from in from_map_repeat)from_arr.push(from_map_repeat[from]) |
| for(var from in from_map_like)from_arr.push(from_map_like[from]) |
| |
| for(var i=from_arr.length;i--;)if(from_arr[i].cutoff<2)from_arr.splice(i,1) |
| |
| from_arr = from_arr.sort( |
| function(a,b){ |
| return b.cutoff - a.cutoff |
| } |
| ).sort( |
| function(a,b){return b.from.length - a.from.length} |
| ) |
| |
| if(DEBUG){ |
| WSH.Echo('') |
| WSH.Echo('') |
| WSH.Echo('Deep = '+ index_deep) |
| for(var i in from_arr){ |
| WSH.Echo(from_arr[i].from+'->'+ from_arr[i].mode+index_deep+'(?)') |
| for(var j in from_arr[i]){ |
| WSH.Echo(j + '\t= '+ from_arr[i][j]) |
| } |
| WSH.Echo('') |
| } |
| } |
| |
| return from_arr |
| } |
| |
| |
| function convolution(text,from_arr,index_deep){ |
| for(var i=0,count=0; i<from_arr.length; i++){ |
| from_arr[i].done = false |
| |
| switch(from_arr[i].mode){ |
| case '$': |
| from_arr[i].map = index_deep.toString(36) + count.toString(36) |
| text = text.replace( |
| new RegExp('('+(from_arr[i].from.replace(/\W/gm,'\\$&'))+'){4,36}','gm'), |
| function(str,from){count++;from_arr[i].done=true;return '$'+from_arr[i].map+parseInt(str.length / from.length).toString(36)} |
| ) |
| break |
| |
| case '@': |
| from_arr[i].map = index_deep.toString(36) + count.toString(36) |
| text = text.replace( |
| new RegExp(from_arr[i].str.replace(/\W/gm,'\\$&'),'gm'), |
| function(str,from){count++;from_arr[i].done=true;return '@'+from_arr[i].map} |
| ) |
| break |
| |
| case '#': |
| text = text.replace( |
| new RegExp(from_arr[i].from.replace(/\W/gm,'\\$&'),'gm'), |
| function(str,from){count++;from_arr[i].done=true;return '#'+from_arr[i].map} |
| ) |
| break |
| } |
| |
| if(count>=36){ |
| from_arr.splice(i) |
| break |
| } |
| } |
| |
| for(var i=from_arr.length;i--;){ |
| if(!from_arr[i].done)from_arr.splice(i,1) |
| } |
| |
| return text |
| } |
| }COPY |