/js/mage/adminhtml/hash.js

https://github.com/jpratt/cal · JavaScript · 160 lines · 91 code · 18 blank · 51 comment · 27 complexity · c7ee6fd0f3bf5c2c21396f6bce38a221 MD5 · raw file

  1. /**
  2. * Magento
  3. *
  4. * NOTICE OF LICENSE
  5. *
  6. * This source file is subject to the Academic Free License (AFL 3.0)
  7. * that is bundled with this package in the file LICENSE_AFL.txt.
  8. * It is also available through the world-wide-web at this URL:
  9. * http://opensource.org/licenses/afl-3.0.php
  10. * If you did not receive a copy of the license and are unable to
  11. * obtain it through the world-wide-web, please send an email
  12. * to license@magentocommerce.com so we can send you a copy immediately.
  13. *
  14. * DISCLAIMER
  15. *
  16. * Do not edit or add to this file if you wish to upgrade Magento to newer
  17. * versions in the future. If you wish to customize Magento for your
  18. * needs please refer to http://www.magentocommerce.com for more information.
  19. *
  20. * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  21. * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
  22. */
  23. /*
  24. * Caudium - An extensible World Wide Web server
  25. * Copyright C 2002 The Caudium Group
  26. *
  27. * This program is free software; you can redistribute it and/or
  28. * modify it under the terms of the GNU General Public License as
  29. * published by the Free Software Foundation; either version 2 of the
  30. * License, or (at your option) any later version.
  31. *
  32. * This program is distributed in the hope that it will be useful, but
  33. * WITHOUT ANY WARRANTY; without even the implied warranty of
  34. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  35. * General Public License for more details.
  36. *
  37. * You should have received a copy of the GNU General Public License
  38. * along with this program; if not, write to the Free Software
  39. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  40. *
  41. */
  42. /*
  43. * base64.js - a JavaScript implementation of the base64 algorithm,
  44. * (mostly) as defined in RFC 2045.
  45. *
  46. * This is a direct JavaScript reimplementation of the original C code
  47. * as found in the Exim mail transport agent, by Philip Hazel.
  48. *
  49. * $Id: base64.js,v 1.7 2002/07/16 17:21:23 kazmer Exp $
  50. *
  51. */
  52. function encode_base64( what )
  53. {
  54. var base64_encodetable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  55. var result = "";
  56. var len = what.length;
  57. var x, y;
  58. var ptr = 0;
  59. while( len-- > 0 )
  60. {
  61. x = what.charCodeAt( ptr++ );
  62. result += base64_encodetable.charAt( ( x >> 2 ) & 63 );
  63. if( len-- <= 0 )
  64. {
  65. result += base64_encodetable.charAt( ( x << 4 ) & 63 );
  66. result += "==";
  67. break;
  68. }
  69. y = what.charCodeAt( ptr++ );
  70. result += base64_encodetable.charAt( ( ( x << 4 ) | ( ( y >> 4 ) & 15 ) ) & 63 );
  71. if ( len-- <= 0 )
  72. {
  73. result += base64_encodetable.charAt( ( y << 2 ) & 63 );
  74. result += "=";
  75. break;
  76. }
  77. x = what.charCodeAt( ptr++ );
  78. result += base64_encodetable.charAt( ( ( y << 2 ) | ( ( x >> 6 ) & 3 ) ) & 63 );
  79. result += base64_encodetable.charAt( x & 63 );
  80. }
  81. return result;
  82. }
  83. function decode_base64( what )
  84. {
  85. var base64_decodetable = new Array (
  86. 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
  87. 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
  88. 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
  89. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 255, 255, 255,
  90. 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  91. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
  92. 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  93. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 255, 255, 255, 255, 255
  94. );
  95. var result = "";
  96. var len = what.length;
  97. var x, y;
  98. var ptr = 0;
  99. while( !isNaN( x = what.charCodeAt( ptr++ ) ) )
  100. {
  101. if( x == 13 || x == 10 )
  102. continue;
  103. if( ( x > 127 ) || (( x = base64_decodetable[x] ) == 255) )
  104. return false;
  105. if( ( isNaN( y = what.charCodeAt( ptr++ ) ) ) || (( y = base64_decodetable[y] ) == 255) )
  106. return false;
  107. result += String.fromCharCode( (x << 2) | (y >> 4) );
  108. if( (x = what.charCodeAt( ptr++ )) == 61 )
  109. {
  110. if( (what.charCodeAt( ptr++ ) != 61) || (!isNaN(what.charCodeAt( ptr ) ) ) )
  111. return false;
  112. }
  113. else
  114. {
  115. if( ( x > 127 ) || (( x = base64_decodetable[x] ) == 255) )
  116. return false;
  117. result += String.fromCharCode( (y << 4) | (x >> 2) );
  118. if( (y = what.charCodeAt( ptr++ )) == 61 )
  119. {
  120. if( !isNaN(what.charCodeAt( ptr ) ) )
  121. return false;
  122. }
  123. else
  124. {
  125. if( (y > 127) || ((y = base64_decodetable[y]) == 255) )
  126. return false;
  127. result += String.fromCharCode( (x << 6) | y );
  128. }
  129. }
  130. }
  131. return result;
  132. }
  133. function wrap76( what )
  134. {
  135. var result = "";
  136. var i;
  137. for(i=0; i < what.length; i+=76)
  138. {
  139. result += what.substring(i, i+76) + String.fromCharCode(13) + String.fromCharCode(10);
  140. }
  141. return result;
  142. }