Advertisement
Guest User

Class

a guest
Mar 26th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net
  2. {
  3.     import flash.utils.*;
  4.  
  5.     public class Binary extends ByteArray
  6.     {
  7.         public var bitLength:Number;
  8.         public var bitPosition:Number;
  9.         public static var powList:Array;
  10.         public static var __init:Boolean = _init();
  11.  
  12.         public function Binary()
  13.         {
  14.             this.bitLength = 0;
  15.             this.bitPosition = 0;
  16.             return;
  17.         }// end function
  18.  
  19.         public function getDebug() : String
  20.         {
  21.             var _loc_1:* = new Array();
  22.             _loc_1.push(this.bitPosition);
  23.             _loc_1.push(this.bitLength);
  24.             var _loc_2:uint = 0;
  25.             while (_loc_2 < length)
  26.             {
  27.  
  28.                 _loc_1.push(this[_loc_2].toString());
  29.                 _loc_2 = _loc_2 + 1;
  30.             }
  31.             return _loc_1.join("=");
  32.         }// end function
  33.  
  34.         public function setDebug(param1:String)
  35.         {
  36.             var _loc_2:* = param1.split("=");
  37.             this.bitPosition = _loc_2[0];
  38.             this.bitLength = _loc_2[1];
  39.             var _loc_3:uint = 2;
  40.             while (_loc_3 < _loc_2.length)
  41.             {
  42.  
  43.                 this.writeByte(Number(_loc_2[_loc_3]));
  44.                 _loc_3 = _loc_3 + 1;
  45.             }
  46.             return;
  47.         }// end function
  48.  
  49.         public function bitReadString() : String
  50.         {
  51.             var _loc_4:uint = 0;
  52.             var _loc_1:String = "";
  53.             var _loc_2:* = this.bitReadUnsignedInt(16);
  54.             var _loc_3:* = 0;
  55.             while (_loc_3 < _loc_2)
  56.             {
  57.  
  58.                 _loc_4 = this.bitReadUnsignedInt(8);
  59.                 if (_loc_4 == 255)
  60.                 {
  61.                     _loc_4 = 8364;
  62.                 }
  63.                 _loc_1 = _loc_1 + String.fromCharCode(_loc_4);
  64.                 _loc_3 = _loc_3 + 1;
  65.             }
  66.             return _loc_1;
  67.         }// end function
  68.  
  69.         public function bitReadBoolean() : Boolean
  70.         {
  71.             if (this.bitPosition == this.bitLength)
  72.             {
  73.                 return false;
  74.             }
  75.             var _loc_1:* = Math.floor(this.bitPosition / 8);
  76.             var _loc_2:* = this.bitPosition % 8;
  77.             var _loc_3:String = this;
  78.             var _loc_4:* = this.bitPosition + 1;
  79.             _loc_3.bitPosition = _loc_4;
  80.             return (this[_loc_1] >> 7 - _loc_2 & 1) == 1;
  81.         }// end function
  82.  
  83.         public function bitReadUnsignedInt(param1:Number) : Number
  84.         {
  85.             var _loc_4:Number = NaN;
  86.             var _loc_5:Number = NaN;
  87.             var _loc_6:* = undefined;
  88.             var _loc_7:* = undefined;
  89.             var _loc_8:Number = NaN;
  90.             if (this.bitPosition + param1 > this.bitLength)
  91.             {
  92.                 this.bitPosition = this.bitLength;
  93.                 return 0;
  94.             }
  95.             var _loc_2:* = 0;
  96.             var _loc_3:* = param1;
  97.             while (_loc_3 > 0)
  98.             {
  99.  
  100.                 _loc_4 = Math.floor(this.bitPosition / 8);
  101.                 _loc_5 = this.bitPosition % 8;
  102.                 _loc_6 = 8 - _loc_5;
  103.                 _loc_7 = Math.min(_loc_6, _loc_3);
  104.                 _loc_8 = this[_loc_4] >> _loc_6 - _loc_7 & (powList[_loc_7] - 1);
  105.                 _loc_2 = _loc_2 + _loc_8 * powList[_loc_3 - _loc_7];
  106.                 _loc_3 = _loc_3 - _loc_7;
  107.                 this.bitPosition = this.bitPosition + _loc_7;
  108.             }
  109.             return _loc_2;
  110.         }// end function
  111.  
  112.         public function bitReadSignedInt(param1:Number) : Number
  113.         {
  114.             var _loc_2:* = this.bitReadBoolean();
  115.             return this.bitReadUnsignedInt((param1 - 1)) * (_loc_2 ? (1) : (-1));
  116.         }// end function
  117.  
  118.         public function bitReadBinaryData() : Binary
  119.         {
  120.             var _loc_1:* = this.bitReadUnsignedInt(16);
  121.             return this.bitReadBinary(_loc_1);
  122.         }// end function
  123.  
  124.         public function bitReadBinary(param1:uint) : Binary
  125.         {
  126.             var _loc_4:uint = 0;
  127.             var _loc_5:uint = 0;
  128.             var _loc_2:* = new Binary();
  129.             var _loc_3:* = this.bitPosition;
  130.             while (this.bitPosition - _loc_3 < param1)
  131.             {
  132.  
  133.                 if (this.bitPosition == this.bitLength)
  134.                 {
  135.                     return _loc_2;
  136.                 }
  137.                 _loc_5 = Math.min(8, param1 - this.bitPosition + _loc_3);
  138.                 _loc_2.bitWriteUnsignedInt(_loc_5, this.bitReadUnsignedInt(_loc_5));
  139.             }
  140.             return _loc_2;
  141.         }// end function
  142.  
  143.         public function bitWriteString(param1:String) : void
  144.         {
  145.             var _loc_4:uint = 0;
  146.             var _loc_2:* = Math.min(param1.length, (powList[16] - 1));
  147.             this.bitWriteUnsignedInt(16, _loc_2);
  148.             var _loc_3:* = 0;
  149.             while (_loc_3 < _loc_2)
  150.             {
  151.  
  152.                 _loc_4 = param1.charCodeAt(_loc_3);
  153.                 if (_loc_4 == 8364)
  154.                 {
  155.                     _loc_4 = 255;
  156.                 }
  157.                 this.bitWriteUnsignedInt(8, _loc_4);
  158.                 _loc_3 = _loc_3 + 1;
  159.             }
  160.             return;
  161.         }// end function
  162.  
  163.         public function bitWriteSignedInt(param1:Number, param2:Number) : void
  164.         {
  165.             this.bitWriteBoolean(param2 >= 0);
  166.             this.bitWriteUnsignedInt((param1 - 1), Math.abs(param2));
  167.             return;
  168.         }// end function
  169.  
  170.         public function bitWriteUnsignedInt(param1:Number, param2:Number) : void
  171.         {
  172.             var _loc_4:Number = NaN;
  173.             var _loc_5:* = undefined;
  174.             var _loc_6:* = undefined;
  175.             var _loc_7:Number = NaN;
  176.             param2 = Math.min((powList[param1] - 1), param2);
  177.             var _loc_3:* = param1;
  178.             while (_loc_3 > 0)
  179.             {
  180.  
  181.                 _loc_4 = this.bitLength % 8;
  182.                 if (_loc_4 == 0)
  183.                 {
  184.                     writeBoolean(false);
  185.                 }
  186.                 _loc_5 = 8 - _loc_4;
  187.                 _loc_6 = Math.min(_loc_5, _loc_3);
  188.                 _loc_7 = this.Rshift(param2, Number(_loc_3 - _loc_6));
  189.                 this[(this.length - 1)] = this[(this.length - 1)] + _loc_7 * powList[_loc_5 - _loc_6];
  190.                 param2 = param2 - _loc_7 * powList[_loc_3 - _loc_6];
  191.                 _loc_3 = _loc_3 - _loc_6;
  192.                 this.bitLength = this.bitLength + _loc_6;
  193.             }
  194.             return;
  195.         }// end function
  196.  
  197.         public function bitWriteUnsignedIntOLD(param1:Number, param2:Number) : void
  198.         {
  199.             param2 = Math.min((powList[param1] - 1), Math.abs(param2));
  200.             var _loc_3:* = param2.toString(2);
  201.             while (_loc_3.length < param1)
  202.             {
  203.  
  204.                 _loc_3 = "0" + _loc_3;
  205.             }
  206.             var _loc_4:* = 0;
  207.             while (_loc_4 < param1)
  208.             {
  209.  
  210.                 this.bitWriteBoolean(_loc_3.charAt(_loc_4) == "1");
  211.                 _loc_4 = _loc_4 + 1;
  212.             }
  213.             return;
  214.         }// end function
  215.  
  216.         public function bitWriteBoolean(param1:Boolean) : void
  217.         {
  218.             var _loc_2:* = this.bitLength % 8;
  219.             if (_loc_2 == 0)
  220.             {
  221.                 writeBoolean(false);
  222.             }
  223.             if (param1)
  224.             {
  225.                 this[(this.length - 1)] = this[(this.length - 1)] + powList[7 - _loc_2];
  226.             }
  227.             var _loc_3:String = this;
  228.             var _loc_4:* = this.bitLength + 1;
  229.             _loc_3.bitLength = _loc_4;
  230.             return;
  231.         }// end function
  232.  
  233.         public function bitWriteBinaryData(param1:Binary) : void
  234.         {
  235.             var _loc_2:* = Math.min(param1.bitLength, (powList[16] - 1));
  236.             this.bitWriteUnsignedInt(16, _loc_2);
  237.             this.bitWriteBinary(param1);
  238.             return;
  239.         }// end function
  240.  
  241.         public function bitWriteBinary(param1:Binary) : void
  242.         {
  243.             var _loc_3:uint = 0;
  244.             var _loc_4:uint = 0;
  245.             param1.bitPosition = 0;
  246.             var _loc_2:* = param1.bitLength;
  247.             while (_loc_2)
  248.             {
  249.  
  250.                 _loc_3 = Math.min(8, _loc_2);
  251.                 _loc_4 = param1.bitReadUnsignedInt(_loc_3);
  252.                 this.bitWriteUnsignedInt(_loc_3, _loc_4);
  253.                 _loc_2 = _loc_2 - _loc_3;
  254.             }
  255.             return;
  256.         }// end function
  257.  
  258.         public function bitCopyObject(param1:Object)
  259.         {
  260.             this.bitPosition = param1.bitPosition;
  261.             this.bitLength = param1.bitLength;
  262.             param1.position = 0;
  263.             var _loc_2:uint = 0;
  264.             while (_loc_2 < param1.length)
  265.             {
  266.  
  267.                 writeByte(param1.readByte());
  268.                 _loc_2 = _loc_2 + 1;
  269.             }
  270.             return;
  271.         }// end function
  272.  
  273.         public function Rshift(param1:Number, param2:int) : Number
  274.         {
  275.             return Math.floor(param1 / powList[param2]);
  276.         }// end function
  277.  
  278.         public function Lshift(param1:Number, param2:int) : Number
  279.         {
  280.             return param1 * powList[param2];
  281.         }// end function
  282.  
  283.         public static function _init() : Boolean
  284.         {
  285.             powList = new Array();
  286.             var _loc_1:uint = 0;
  287.             while (_loc_1 <= 32)
  288.             {
  289.  
  290.                 powList.push(Math.pow(2, _loc_1));
  291.                 _loc_1 = _loc_1 + 1;
  292.             }
  293.             return true;
  294.         }// end function
  295.  
  296.     }
  297. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement