Advertisement
Guest User

Untitled

a guest
May 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. package demiurg.utils
  2. {
  3. import flash.utils.*;
  4.  
  5. public class Base64 extends Object
  6. {
  7. public static const version:String = "1.1.0";
  8. private static const BASE64_CHARS:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  9.  
  10. public function Base64()
  11. {
  12. throw new Error("Base64 class is static container only");
  13. }// end function
  14.  
  15. public static function encode(param1:String) : String
  16. {
  17. var _loc_2:* = new ByteArray();
  18. _loc_2.writeUTFBytes(param1);
  19. return encodeByteArray(_loc_2);
  20. }// end function
  21.  
  22. public static function encodeByteArray(param1:ByteArray) : String
  23. {
  24. var _loc_3:Array = null;
  25. var _loc_5:uint = 0;
  26. var _loc_6:uint = 0;
  27. var _loc_7:uint = 0;
  28. var _loc_2:String = "";
  29. var _loc_4:* = new Array(4);
  30. param1.position = 0;
  31. while (param1.bytesAvailable > 0)
  32. {
  33.  
  34. _loc_3 = new Array();
  35. _loc_5 = 0;
  36. while (_loc_5 < 3 && param1.bytesAvailable > 0)
  37. {
  38.  
  39. _loc_3[_loc_5] = param1.readUnsignedByte();
  40. _loc_5 = _loc_5 + 1;
  41. }
  42. _loc_4[0] = (_loc_3[0] & 252) >> 2;
  43. _loc_4[1] = (_loc_3[0] & 3) << 4 | _loc_3[1] >> 4;
  44. _loc_4[2] = (_loc_3[1] & 15) << 2 | _loc_3[2] >> 6;
  45. _loc_4[3] = _loc_3[2] & 63;
  46. _loc_6 = _loc_3.length;
  47. while (_loc_6 < 3)
  48. {
  49.  
  50. _loc_4[(_loc_6 + 1)] = 64;
  51. _loc_6 = _loc_6 + 1;
  52. }
  53. _loc_7 = 0;
  54. while (_loc_7 < _loc_4.length)
  55. {
  56.  
  57. _loc_2 = _loc_2 + BASE64_CHARS.charAt(_loc_4[_loc_7]);
  58. _loc_7 = _loc_7 + 1;
  59. }
  60. }
  61. return _loc_2;
  62. }// end function
  63.  
  64. public static function decode(param1:String) : String
  65. {
  66. var _loc_2:* = decodeToByteArray(param1);
  67. return _loc_2.readUTFBytes(_loc_2.length);
  68. }// end function
  69.  
  70. public static function decodeToByteArray(param1:String) : ByteArray
  71. {
  72. var _loc_6:uint = 0;
  73. var _loc_7:uint = 0;
  74. var _loc_2:* = new ByteArray();
  75. var _loc_3:* = new Array(4);
  76. var _loc_4:* = new Array(3);
  77. var _loc_5:uint = 0;
  78. while (_loc_5 < param1.length)
  79. {
  80.  
  81. _loc_6 = 0;
  82. while (_loc_6 < 4 && _loc_5 + _loc_6 < param1.length)
  83. {
  84.  
  85. _loc_3[_loc_6] = BASE64_CHARS.indexOf(param1.charAt(_loc_5 + _loc_6));
  86. while (_loc_3[_loc_6] < 0 && _loc_5 < param1.length)
  87. {
  88.  
  89. _loc_5 = _loc_5 + 1;
  90. _loc_3[_loc_6] = BASE64_CHARS.indexOf(param1.charAt(_loc_5 + _loc_6));
  91. }
  92. _loc_6 = _loc_6 + 1;
  93. }
  94. _loc_4[0] = (_loc_3[0] << 2) + ((_loc_3[1] & 48) >> 4);
  95. _loc_4[1] = ((_loc_3[1] & 15) << 4) + ((_loc_3[2] & 60) >> 2);
  96. _loc_4[2] = ((_loc_3[2] & 3) << 6) + _loc_3[3];
  97. _loc_7 = 0;
  98. while (_loc_7 < _loc_4.length)
  99. {
  100.  
  101. if (_loc_3[(_loc_7 + 1)] == 64)
  102. {
  103. break;
  104. }
  105. _loc_2.writeByte(_loc_4[_loc_7]);
  106. _loc_7 = _loc_7 + 1;
  107. }
  108. _loc_5 = _loc_5 + 4;
  109. }
  110. _loc_2.position = 0;
  111. return _loc_2;
  112. }// end function
  113.  
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement