Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function code(str){
- var res = '';
- var n = 1;
- for (var i = 0; i < str.length; i++){
- if (n >= 127){
- res += '#' + String.fromCharCode(127) + str.charAt(i);
- n -= 127;
- continue;
- }
- if (str.charCodeAt(i) == str.charCodeAt(i+1)){
- n++;
- continue;
- }
- if (n > 3 || str.charAt(i) == '#'){
- res += '#' + String.fromCharCode(n) + str.charAt(i);
- n = 1;
- }
- else{
- res += str.slice(i - n + 1, i + 1);
- n = 1;
- }
- }
- return res;
- }
- function decode(str){
- var res = '';
- for (var i = 0; i < str.length; i++){
- if (str.charAt(i) == '#'){
- if (str.charCodeAt(i+1) == 127){
- for (var j = 0; j < 128; j++) {
- res += str.charAt(i+2);
- }
- i += 2;
- }
- else{
- for (var j = 0; j < str.charCodeAt(i+1); j++) {
- res += str.charAt(i+2);
- }
- i += 2;
- }
- }
- else{
- res += str.charAt(i);
- }
- }
- return res;
- }
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var name = WSH.Arguments(0);
- var ts = fso.OpenTextFile(WSH.Arguments(1));
- var str = ts.ReadAll();
- ts.Close();
- if (name == 'code'){
- str = code(str);
- }
- if (name == 'decode'){
- str = decode(str);
- }
- ts = fso.OpenTextFile(WSH.Arguments(2), 2, true);
- ts.Writeline(str);
- ts.Close();
- WSH.echo(str);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement