开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 9723|回复: 6
收起左侧

[已解决] JS调试提示undefined为空或不是对象?

 关闭 [复制链接]
结帖率:50% (1/2)
发表于 2016-5-30 12:59:33 | 显示全部楼层 |阅读模式   广西壮族自治区南宁市
9精币
调试一个网站JS,加密找到了,改JS的时候总是提示undefined为空或不是对象?
绞尽脑汁也想不通,求大神们指教是怎么回事?
源码是这样的:
var ssRsa = (function (){
/**
  * RSA 클래스
  * @param String key RSA 키(public, private 구분 없이 할당 가능)
  * @see     ASN.1 규약에 의한 sub 데이터 구조 정보는 rfc3447 문서를 참조할 것.
  *       rfc3447: http://tools.ietf.org/html/rfc3447#appendix-A
  */
function RSA ( key )
{
  // 암호문 = pow ( 평문 , this.e ) % this.n
  this.n = null ; // this.n = p * q  
  this.e = null ; // this.e = gcd ( e , l ) , l = lcm ( p - 1 , q - 1 ) 두 개의 소수값에 각각 1을 뺀 후의 최소공배수가 l 이다.
  
  // 평문 = pow ( 암호문 , this.d ) % this.n
  this.d = null ;
  
  // this.n 의 비트 길이 (암호화 가능한 문자열의 길이)
  this.l = null ;
  if ( key )
   this.setKey ( key ) ;
}
RSA.prototype =
{
  /**
   * RSA 키 할당
   * @param String key RSA 키(public, private 구분 없이 할당 가능)
   */
  setKey: function ( key )
  {
   var key = /-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/.exec ( key ) ,
    asn1 = ASN1.decode ( new Stream ( Base64.decode ( key[1] ? key[1] : key[2] ) ) ) ;
   if ( asn1.sub.length === 9 )  // 개인키
   {
    this.n = new BigInt ( asn1.sub[1].getHex () , 16 ) ;
    this.e = new BigInt ( asn1.sub[2].getHex () , 16 ) ;
    this.d = new BigInt ( asn1.sub[3].getHex () , 16 ) ;
   }
   else        // 공개키
   {
    this.n = new BigInt ( asn1.sub[1].sub[0].sub[0].getHex () , 16 ) ;
    this.e = new BigInt ( asn1.sub[1].sub[0].sub[1].getHex () , 16) ;
   }   
   this.l = ( this.n.getBitLength () | 7 ) >> 3 ;
  } ,
  
  /**
   * 평문을 암호화하여 반환한다.
   * @param String text 평문
   * @Return String   암호문
   */
  encrypt: function ( text )
  {
   var byte = [] ;
   if ( text.length > this.l )
    return alert ( '암호화 가능한한 자리 수를 넘었습니다. RSA 암호화 비트 수를 더 크게 설정하세요.' ) ;
   
   // 문자열 표현에 1바이트 이상이 필요한 경우에는 문자열을 분리한다.
   for ( var i = text.length ; i > 0 ; i -- )
   {
    char = text.charCodeAt ( i - 1 ) ;
    if ( char < 128 )
     byte.unshift ( char ) ;
    else if ( ( char > 127 ) && ( char < 2048 ) ) // 192 ~ 223
     byte.unshift ( ( char & 63 ) | 128 ) , byte.unshift ( ( char >> 6 ) | 192 ) ;
    else // 129 ~ 191 , 224 ~ 255
     byte.unshift ( ( char & 63 ) | 128 ) , byte.unshift ( ( ( char >> 6 ) & 63 ) | 128 ) , byte.unshift ( ( char >> 12 ) | 224 ) ;
   }
   byte.unshift ( 0 ) ; // &#44396;&#48516;&#51088; &#52628;&#44032;
   
   // &#50516;&#54840;&#54868; &#44032;&#45733;&#54620; &#47928;&#51088;&#50676;&#51032; &#44600;&#51060;&#48372;&#45796; &#54217;&#47928;&#51060; &#51687;&#51008; &#44221;&#50864;(&#54217;&#47928;&#51060; &#45908; &#44596; &#44221;&#50864;&#50640;&#45716; &#49324;&#49892;&#49345; &#50724;&#47448;&#51076;), &#45224;&#45716; &#50516;&#54840;&#54868; &#44032;&#45733;&#54620; &#44600;&#51060;&#47564;&#53372; &#47004;&#45924;&#54616;&#44172; &#52628;&#44032;&#54620;&#45796;.
   if ( byte.length - 2 < this.l )
    for ( i = this.l - byte.length - 2 ; i > 0 ; i -- )
     byte.unshift ( Math.ceil ( Math.random () * 254 ) ) ;
   
   var bigInt = new BigInt ( [0,2].concat ( byte ) ) ; // &#44396;&#48516;&#51088;(&#51333;&#44208;&#47928;&#51088;) &#52628;&#44032;
   if ( bigInt == null )
    return alert ( '&#50516;&#54840;&#54868;&#50640; &#49892;&#54056;&#54616;&#50688;&#49845;&#45768;&#45796;.' ) ;
   
   var encrypt = bigInt.powMod ( this.e , this.n ) ; // &#50516;&#54840;&#54868;, pow ( &#54217;&#47928; , this.e ) % this.n
   if ( encrypt == null )
    return alert ( '&#50516;&#54840;&#54868;&#50640; &#49892;&#54056;&#54616;&#50688;&#49845;&#45768;&#45796;.' ) ;
   
   return Base64.encode ( encrypt.toString ( 16 ) ) ; // Hex &#48320;&#54872; &#54980;, base64 &#51064;&#53076;&#46377;&#54616;&#50668; &#48152;&#54872;
  } ,
  
  /**
   * &#50516;&#54840;&#47928;&#51012; &#48373;&#54840;&#54868;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
   * @param String text &#50516;&#54840;&#47928;
   * @return String   &#54217;&#47928;
   */
  decrypt: function ( text )
  {
   var bigInt = new BigInt ( Base64.decode ( text ) , 16 ) ,
    decrypt = bigInt.powMod ( this.d , this.n ) , // &#48373;&#54840;&#54868;, pow ( &#50516;&#54840;&#47928; , this.d ) % this.n
    byte = decrypt.getByteArray () ,
    i = 0 ;
   
   // &#46160; &#44060;&#51032; &#44396;&#48516;&#51088;&#44032; &#45208;&#50732;&#46412;&#44620;&#51648; &#45936;&#51060;&#53552;&#47484; &#47924;&#49884;&#54620;&#45796;.
   if ( byte == 0 ) // &#44396;&#48516;&#51088; &#54869;&#51064;
    i ++ ;
   if ( byte != 2 || byte.length != this.l - 1 )
    return alert ( '&#48373;&#54840;&#54868;&#50640; &#49892;&#54056;&#54616;&#50688;&#49845;&#45768;&#45796;.' ) ;
   while ( i < byte.length )
    if ( byte[++ i] == 0 ) // &#44396;&#48516;&#51088; &#54869;&#51064;
     break ;
   
   // &#48516;&#47532;&#54620; &#47928;&#51088;&#50676;&#51012; &#45796;&#49884; &#51312;&#54633;&#54620;&#45796;.
   var result = '' ;
   for ( i ++ ; i < byte.length ; i ++ )
   {
    var char = byte & 255 ;
    if ( char < 128 )
     result += String.fromCharCode ( char ) ;
    else if ( char > 191 && char < 224 )
     result += String.fromCharCode ( ( ( char & 31 ) << 6 ) | ( byte[++ i] & 63 ) ) ;
    else // &#48373;&#54840;&#54868;&#54620; &#44221;&#50864;, &#51020;&#49688;(256 &#44592;&#51456; &#48372;&#49688; &#44050;)&#47196; &#45208;&#50728;&#45796;.
     result += String.fromCharCode ( ( ( char & 15 ) << 12 ) | ( ( byte[++ i] & 63 ) << 6 ) | ( byte[++ i] & 63 ) ) ;
   }
   return result ;
  }
}


/**
  * Base64 &#53364;&#47000;&#49828;
  */
var Base64 = {
  map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ,
  
  /**
   * Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)&#51012; Base64 &#47928;&#51088;&#50676;&#47196; &#51064;&#53076;&#46377;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
   * @param String hex Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)
   * @return String  Base64 &#47928;&#51088;&#50676;
   */
  encode: function ( hex )
  {
   if ( ( hex.length & 1 ) != 0 )
    hex = '0' + hex ;
   var i , char , result = '' ;
   for ( i = 0 ; i + 3 <= hex.length ; i += 3 )
   {
    char = parseInt ( hex.substring ( i , i + 3 ) , 16 ) ;
    result += this.map[char >> 6] + this.map[char & 63] ;
   }
   if ( hex.length - 1 == i )
   {
    char = parseInt ( hex.substring ( i , hex.length ) , 16 ) ;
    result += this.map[char << 2] ;
   }
   else if ( hex.length - 2 == i )
   {
    char = parseInt ( hex.substring ( i , hex.length ) , 16 ) ;
    result += this.map[char >> 2] + this.map[( char & 3 ) << 4] ;
   }
   while ( ( result.length & 3 ) > 0 )
    result += '=' ;
   return result ;
  } ,
  
  /**
   * Base64 &#47928;&#51088;&#50676;&#51012; Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)&#47196; &#46356;&#53076;&#46377;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
   * @param String string Base64 &#47928;&#51088;&#50676;
   * @return String   Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)
   */
  decode: function ( string )
  {
   var char , remain , result = '' ;
   string = string.replace ( /[= \f\n\r\t\u00A0\u2028\u2029]/g , '' ) ; // &#48520;&#54596;&#50836;&#54620; &#47928;&#51088;&#50676; &#51228;&#44144;
   for ( var i = 0 , j = 0 ; i < string.length ; i ++ , j ++ )
   {
    char = this.map.indexOf ( string ) ;
    switch ( j )
    {
     case 0 :
      result += ( char >> 2 ).toString ( 16 ) ;
      remain = char & 3 ;
      break ;
     case 1 :
      result += ( ( remain << 2 ) | ( char >> 4 ) ).toString ( 16 ) ;
      remain = char & 15 ;
      break ;
     case 2 :
      result += ( remain ).toString ( 16 ) + ( char >> 2 ).toString ( 16 ) ;
      remain = char & 3 ;
      break ;
     case 3 :
      result += ( ( remain << 2 ) | ( char >> 4 ) ).toString ( 16 ) + ( char & 15 ).toString ( 16 ) ;
      j = -1 ;
      break ;
    }
   }
   if ( j == 1 )
    result += ( remain << 2 ).toString ( 16 ) ;
   if ( ( result.length & 1 ) != 0 )
    result = '0' + result ;
   return result ;
  }
}

/**
  * ASN.1 Stream &#53364;&#47000;&#49828;
  * @param Object obj Stream &#44061;&#52404; &#54841;&#51008; Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)
  */
function Stream ( obj )
{
  if ( typeof obj == 'string' )
  {
   this.pos = 0 ;
   this.data = [] ;
   for ( var i = 0 ; i < obj.length ; i += 2 )
    this.data.push ( parseInt ( obj.substr ( i , 2 ) , 16 ) ) ;
  }
  else
  {
   this.data = obj.data ;
   this.pos = obj.pos ;
  }
}
Stream.prototype =
{
  /**
   * &#54788;&#51116; &#45936;&#51060;&#53552;&#47484; &#48152;&#54872;&#54616;&#44256;, &#45796;&#51020; &#50948;&#52824;&#47196; &#51060;&#46041;&#54620;&#45796;.
   */
  getData: function ()
  {
   return this.data[this.pos ++] ;
  } ,
  
  /**
   * &#53468;&#44536;&#51032; &#44600;&#51060; &#44050;&#51012; &#44228;&#49328;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
   */
  getLength: function ()
  {
   var tag = this.getData () ,
    length = tag & 127 ;
   if ( length == tag )
    return length ;
   if ( length === 0 )
    return -1 ;
   for ( var i = 0 , tag = 0 ; i < length ; i ++ )
    tag = ( tag << 8 ) | this.getData () ;
   return tag ;
  } ,
  
  /**
   * &#49436;&#48652; &#45936;&#51060;&#53552;&#47196; &#49373;&#49457;&#54624; &#45236;&#50857;&#51060; &#51316;&#51116;&#54616;&#45716;&#51648; &#54869;&#51064;&#54620;&#45796;.
   * @param Integer tag  &#53468;&#44536;
   * @param Integer length &#44600;&#51060;
   */
  has: function ( tag , length )
  {
   if ( tag & 32 )
    return true ;
   if ( tag < 3 || tag > 4 )
    return false ;
   var p = new Stream ( this ) ;
   if ( tag == 3 )
    p.getData() ;
   var sub = p.getData () ;
   if ( ( sub >> 6 ) & 1 )
    return false ;
   var l = p.getLength () ;
   return ( ( p.pos - this.pos ) + l == length ) ;
  }
}

/**
  * ASN.1 &#53364;&#47000;&#49828;
  * @param Array sub  &#49436;&#48652; &#45936;&#51060;&#53552;
  * @param Stream stream &#45936;&#51060;&#53552; &#49828;&#53944;&#47548;
  * @param Integer start &#49884;&#51089; &#50948;&#52824;
  * @param Integer end  &#51333;&#47308; &#50948;&#52824;
  */
function ASN1 ( sub , stream , start , end )
{
  if ( sub.length != 0 )
   this.sub = sub ;
  this.stream = stream ;
  this.stream.start = start ;
  this.stream.end = end ;
}
ASN1.prototype =
{
  /**
   * Hex &#47928;&#51088;&#50676;(16&#51652;&#49688;)&#47196; &#48320;&#54872;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
   */
  getHex: function ()
  {
   var end = this.stream.pos + this.stream.start + Math.abs ( this.stream.end ) ,
    result = '' , h , i ;
   for ( i = this.stream.pos ; i < end ; i ++ )
   {
    h = this.stream.data ;
    result += Convert.decimalToHex ( ( h >> 4 ) & 15 ) + Convert.decimalToHex ( h & 15 ) ;
   }
   return result.substr ( this.stream.start * 2 , this.stream.end * 2 ) ;
  }
}

/**
  * ASN.1 &#44508;&#44201;&#51012; &#46356;&#53076;&#46377;&#54616;&#50668; ASN.1 &#44061;&#52404;&#47196; &#48152;&#54872;&#54620;&#45796;.
  * @param Mixed stream &#45936;&#51060;&#53552; &#49828;&#53944;&#47548; &#54841;&#51008; Hex &#47928;&#51088;&#50676;(ASN.1 &#44508;&#44201;)
  */
ASN1.decode = function ( stream )
{
  var clone = new Stream ( stream ) ,
   tag = stream.getData () ,
   end = stream.getLength () ,
   start = stream.pos - clone.pos ,
   sub = [] ;
  if ( ! stream.has ( tag , end ) )
   stream.pos += end ;
  else
  {
   var temp = stream.pos + end ;
   if ( tag == 3 )
    stream.getData () ;
   while ( stream.pos < temp )
    sub.push ( ASN1.decode ( stream ) ) ;
  }
  return new ASN1 ( sub , clone , start , end ) ;
} ;


/**
  * BigInt &#49373;&#49457;&#51088; &#48320;&#49688;
  */
var BigInt = (function (){

  /**
   * BigInt &#53364;&#47000;&#49828;
   * @param Mixed value &#44050;
   * @param Integer base &#51652;&#49688; ( 2&#51228;&#44273;&#47564; &#44032;&#45733;&#54616;&#45796;. &#50696;) 2, 4, 8, 16, 24 ... 256 )
   */
  function BigInt ( value , base )
  {
   
   base = 256 ;
   
   
   this.total = 0 ;
   this.start = 0 ;
      
   var unit = ( base >> 1 ).toString( 2 ).length , shift = 0 , t ;
   for ( i = value.length - 1 ; i > -1 ; i -- )
   {
    t = base == 16 ? Convert.hexToDecimal ( value ) : value & 255 ;
    if ( shift == 0 )
     this[this.total ++] = t ;
    else if ( shift + unit > BIT )
    {     
     this[this.total ++] = ( t >> ( BIT - shift ) ) ;
     this[this.total - 2] += ( t & ( ( 1 << ( BIT - shift ) ) - 1 ) ) << shift ;
    }
    else
     this[this.total - 1] += t << shift ;
    shift += unit ;
    if ( shift >= BIT )
     shift -= BIT ;
   }
   this.reset () ;
  }
  BigInt.prototype =
  {
   /**
    * &#54788;&#51116; &#44050;&#50640;&#49436; target &#51012; &#48768; &#54980;, &#44208;&#44284;&#47484; &#48152;&#54872;&#54620;&#45796;.
    * @param BigInt target &#48772; &#44050;
    * @return BigInt   &#45224;&#51008; &#44050; ( this - target ) ;
    * @see  &#54788;&#51116; &#44050;&#50640; &#50689;&#54693;&#51012; &#51452;&#51648; &#50506;&#45716;&#45796;.
    */
   minus: function ( target )
   {
    var result = new BigInt ,
     min = Math.min ( target.total , this.total ) ;
    for ( var i = t = 0 ; i < min ; i ++ , t >>= BIT )
     result = ( t += this - target ) & BITMASK ;
    if ( target.total < this.total )
    {
     for ( t -= target.start ; i < this.total ; i ++ , t >>= BIT )
      result = ( t += this ) & BITMASK ;
     t += this.start ;
    }
    else
    {
     for ( t += this.start ; i < target.total ; i ++ , t >>= BIT )
      result = ( t -= target ) & BITMASK ;
     t -= target.start ;
    }
    if ( t < -1 )
     result[i ++] = BITMAX + t ;
    else if ( t > 0 )
     result[i ++] = t ;
    result.reset ( i , t < 0 ? -1 : 0 ) ;
    return result ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#44284; &#51064;&#49688;&#47196; &#51204;&#45804;&#46108; &#44050;&#51012; &#48708;&#44368;&#54616;&#50668; &#52264;&#51060; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;.
    * @param BigInt target &#48708;&#44368; &#44050;
    * @return Integer   &#52264;&#51060; &#44050;
    * @see  &#45936;&#51060;&#53552; &#44396;&#51312;&#50640;&#49436; &#47784;&#46304; &#44050;&#51012; &#54633;&#54616;&#50668; &#44536; &#52264;&#51060;&#44050;&#51012; &#48152;&#54872;&#54616;&#51648; &#50506;&#45716;&#45796;.
    *    &#44536;&#47084;&#48064;&#47196;, &#46160; &#49688;&#51032; &#44050;&#51060; &#45796;&#47480;&#51648; &#48708;&#44368;&#54616;&#44592; &#50948;&#54620; &#50857;&#46020;&#47196; &#49324;&#50857;&#54620;&#45796;.
    */
   diff: function ( target )
   {
    var diff = this.start - target.start ;
    if ( diff != 0 )
     return diff ;
    diff = this.total - target.total ;
    if ( diff != 0 )
     return this.start < 0 ? - diff : diff ;
    for ( var i = this.total - 1 ; i > -1 ; i -- )
     if ( ( diff = this - target ) != 0 )
      return diff ;
    return 0 ;
   } ,
   
   /**
    * &#45936;&#51060;&#53552; &#44396;&#51312;&#47484; &#51116; &#51221;&#51032;&#54616;&#44256; &#51221;&#47532;&#54620;&#45796;.
    * @param Integer total &#48176;&#50676; &#52509; &#49688;
    * @param Integer start &#49884;&#51089; &#50948;&#52824;
    */
   reset: function ( total , start )
   {
    if ( total != undefined )
     this.total = total ;
    if ( start != undefined )
     this.start = start ;
    if ( this.total <= 0 )
     return ;
    var start = this.start & BITMASK ;
    while ( this[this.total - 1] == start )
     this.total -- ;
   } ,
   
   /**
    * &#45936;&#51060;&#53552; &#44396;&#51312;&#51032; &#44033; &#48176;&#50676;&#51012; &#45934;&#50612;&#50420;&#45796;.
    * @param BigInt value &#45934;&#50612; &#50424; &#44050;
    */
   overwrite: function ( value )
   {
    for ( var i = 0 ; i < value.total ; i ++ )
     this = value ;
    this.reset ( value.total , value.start ) ;
   } ,
   
   /**
    * &#45936;&#51060;&#53552; &#44396;&#51312;&#51032; &#50896;&#49548;&#47484; move &#47564;&#53372; &#51340;&#52769;(&#51613;&#44032;)&#51004;&#47196; &#51060;&#46041;&#54616;&#44256;, &#44536; &#44208;&#44284;&#47484; result &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param Integer move &#51060;&#46041; &#49688;
    * @param BigInt result &#44208;&#44284; &#44050;
    * @see  result &#51032; &#44592;&#51316; &#45936;&#51060;&#53552;&#47484; &#52488;&#44592;&#54868;&#54616;&#51648; &#50506;&#45716;&#45796;.
    */
   moveLeftTo: function ( move , result )
   {
    for ( var i = 0 ; i < move ; i ++ )
     result = 0 ;
    for ( i = 0 ; i < this.total ; i ++ )
     result[i + move] = this ;
    result.reset ( this.total + move , this.start ) ;
   } ,
   
   /**
    * &#45936;&#51060;&#53552; &#44396;&#51312;&#51032; &#50896;&#49548;&#47484; move &#47564;&#53372; &#50864;&#52769;(&#51613;&#44032;)&#51004;&#47196; &#51060;&#46041;&#54616;&#44256;, &#44536; &#44208;&#44284;&#47484; result &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param Integer move &#51060;&#46041; &#49688;
    * @param BigInt result &#44208;&#44284; &#44050;
    * @see  result &#51032; &#44592;&#51316; &#45936;&#51060;&#53552;&#47484; &#52488;&#44592;&#54868;&#54616;&#51648; &#50506;&#45716;&#45796;.
    */
   moveRightTo: function ( move , result )
   {
    for ( var i = move ; i < this.total ; i ++ )
     result[i - move] = this ;
    result.reset ( this.total > move ? this.total - move : 0 , this.start ) ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#50640; &#50812;&#51901;&#51004;&#47196; &#48708;&#53944; &#49884;&#54532;&#53944; &#50672;&#49328;&#51012; &#49688;&#54665;&#54616;&#44256;, &#44536; &#44208;&#44284;&#47484; result &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param Integer shift &#51060;&#46041; &#49688;
    * @param BigInt result &#44208;&#44284; &#44050;
    * @see  result &#51032; &#44592;&#51316; &#45936;&#51060;&#53552;&#47484; &#52488;&#44592;&#54868;&#54616;&#51648; &#50506;&#45716;&#45796;.
    */
   shiftLeftTo: function ( shift , result )
   {   
    var pos = Math.floor ( shift / BIT ) ,
     split = shift & BIT ,
     mod = BIT - split ,
     bit = ( 1 << mod ) - 1 ,
     remain = ( this.start << split ) & BITMASK ;   
    for ( var i = this.total - 1 ; i > -1 ; i -- )
    {
     result[i + pos + 1] = ( this >> mod ) + remain ;
     remain = ( this & bit ) << split ;
    }
    result[pos] = remain ;
    for ( i = pos - 1 ; i > -1 ; i -- ) // &#51088;&#47532;&#49688; &#52292;&#50864;&#44592;
     result = 0 ;
    result.reset ( this.total + pos + 1 , this.start ) ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#50640; &#50724;&#47480;&#51901;&#51004;&#47196; &#48708;&#53944; &#49884;&#54532;&#53944; &#50672;&#49328;&#51012; &#49688;&#54665;&#54616;&#44256;, &#44536; &#44208;&#44284;&#47484; result &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param Integer shift &#51060;&#46041; &#49688;
    * @param BigInt result &#44208;&#44284; &#44050;
    * @see  result &#51032; &#44592;&#51316; &#45936;&#51060;&#53552;&#47484; &#52488;&#44592;&#54868;&#54616;&#51648; &#50506;&#45716;&#45796;.
    */
   shiftRightTo: function ( shift , result )
   {
    var pos = Math.floor ( shift / BIT ) ;
    if ( pos >= this.total )
     return result.total = 0 ;
    var split = shift & BIT ,
     mod = BIT - split ,
     bit = ( 1 << split ) - 1 ;   
    result[0] = this[pos] >> split ;
    for ( var i = pos + 1 ; i < this.total ; i ++ )
    {
     result[i - pos - 1] += ( this & bit ) << mod ;
     result[i - pos] = this >> split ;
    }
    if ( split > 0 )
     result[this.total - pos - 1] += ( this.start & bit ) << mod ;
    result.reset ( this.total - pos , this.start ) ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#51012; &#51064;&#49688;&#47196; &#51204;&#45804;&#46108; &#51652;&#49688; &#47928;&#51088;&#50676;&#47196; &#48320;&#54872;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
    * @param Integer base &#51652;&#49688; ( 2&#51228;&#44273;&#47564; &#44032;&#45733;&#54616;&#45796;. &#50696;) 2, 4, 8, 16, 24 ... 256 )
    * @return String
    */
   toString: function ( base )
   {
    if ( this.start < 0 )
     return '-0' ;
   
    var bit = ( base - 1 ).toString ( 2 ) ;
    if ( bit.indexOf ( '0' ) != -1 )
     return alert ( base + '&#51652;&#49688; &#48320;&#54872;&#51012; &#54624; &#49688; &#50630;&#49845;&#45768;&#45796;.' ) ;
    bit = bit.length ;
     
    var unit = ( 1 << bit ) - 1 ,
     block = BIT - ( this.total * BIT ) & ( bit - 1 ) ,
     i = this.total , result = '' , byte , add = false  ;
    if ( i -- > 0 )
    {
     byte = this >> block ;
     if ( block < BIT && byte > 0 )
      add = true , result = byte.toString ( 16 ) ;
     while ( i > -1 )
     {
      if ( block < bit )
       byte = ( this & ( ( 1 << block ) - 1 ) ) << ( bit - block ) ,
       byte += this[--i] >> ( block += BIT - bit ) ;
      else
      {
       byte = ( this >> ( block -= bit ) ) & unit ;
       if ( block <= 0 )
        block += BIT , i -- ;
      }
      if ( add || ( add = byte > 0 ) )
       result += byte.toString ( 16 ) ;
     }
    }
    return add ? result : '0' ;
   } ,
   
   /**
    * &#51204;&#52404; &#48708;&#53944; &#49688;&#47484; &#44228;&#49328;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
    * @return Integer &#51204;&#52404; &#48708;&#53944; &#49688;
    */
   getBitLength: function ()
   {
    if ( this.total <= 0 )
     return 0 ;
    return BIT * ( this.total - 1 ) + ( this[this.total - 1] ^ ( this.start & BITMASK ) ).toString ( 2 ).length ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#51012; 256&#51652;&#49688;&#47196; &#48320;&#54872;&#54616;&#50668; &#48176;&#50676;&#47196; &#48152;&#54872;&#54620;&#45796;.
    * @return Array &#54788;&#51116; &#44050;(256&#51652;&#49688;)
    */
   getByteArray: function ()
   {
    var block = BIT - ( ( this.total * BIT ) & 7 ) ,
     byte , total = this.total ,
     result = [] , i = 0 ;
    result[0] = this.start ;
    if ( total -- > 0 )
    {
     byte = this[total] >> block ;
     if ( block < BIT && byte != ( this.start & BITMASK ) >> block )
      result[i ++] = byte | ( this.start << ( BIT - block ) ) ;
     while ( total > -1 )
     {
      if ( block < 8 )
      {
       byte = ( this[total] & ( ( 1 << block ) - 1 ) ) << ( 8 - block ) ;
       byte += this[-- total] >> ( block += BIT - 8 ) ;
      }
      else
      {
       byte = ( this[total] >> ( block -= 8 ) ) & HEX['8'] ;
       if ( block <= 0 )
        block += BIT , total -- ;
      }
      if ( ( byte & 128 ) != 0 )
       byte += -256 ;
      if ( i == 0 && ( this.start & 128 ) != ( byte & 128 ) )
       i ++ ;
      if ( i > 0 || byte != this.start )
       result[i ++] = byte ;
     }
    }
    return result ;
   } ,
   
   /**
    * &#47680;&#54000; &#48708;&#53944;&#47484; &#44228;&#49328;&#54616;&#50668; &#48152;&#54872;&#54620;&#45796;.
    * @param Integer i  &#54788;&#51116; &#44061;&#52404; &#49692;&#48264;
    * @param Integer value &#44592;&#51456; &#44050;
    * @param BigInt target &#54624;&#45817; &#44061;&#52404;
    * @param Integer j  &#54624;&#45817; &#44061;&#52404; &#49692;&#48264;
    * @param Integer result &#45824;&#52404; &#44050;
    * @param Integer repeat &#48152;&#48373; &#49688;
    */
   getMultiBit: function ( i , value , target , j , result , repeat )
   {
    var bit = BIT / 2 ,
     mask = value & HEX[bit] ,
     quar = value >> bit ;
    for ( var l , q , m ; repeat > 0 ; repeat -- )
    {
     l = this & HEX[bit] ;
     q = this[i ++] >> bit ;
     m = quar * l + q * mask ;
     l = mask * l
      + ( ( m & HEX[bit] ) << bit )
      + target[j]
      + ( BIT == 30 ? result & HEX[BIT] : result ) ;
     result = ( l >>> BIT )
      + ( m >>> bit )
      + ( quar * q )
      + ( BIT == 30 ? result >>> BIT : 0 ) ;
     target[j ++] = l & HEX[BIT] ;
    }
    return result ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#51012; &#51064;&#49688; n &#51004;&#47196; &#45208;&#45576; &#45208;&#47672;&#51648; &#44050;&#51012; remain &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param BigInt n  &#45208;&#45580; &#44050; ( RSA &#50516;/&#48373;&#54840;&#54868; &#44277;&#53685;&#53412; n &#51076; )
    * @param BigInt remain &#45208;&#47672;&#51648; &#44050;
    * @see  remain &#51032; &#44592;&#51316; &#45936;&#51060;&#53552;&#47484; &#52488;&#44592;&#54868;&#54616;&#51648; &#50506;&#45716;&#45796;.
    */
   modTo: function ( n , remain )
   {
    if ( n.total <= 0 )
     return ;
    if ( this.total < n.total && remain != null )
     return remain.overwrite ( this ) ;
   
    var t = new BigInt ,
     bit = BIT - n[n.total - 1].toString ( 2 ).length ;
    if ( bit > 0 )
    {
     n.shiftLeftTo ( bit , t ) ;
     this.shiftLeftTo ( bit , remain ) ;
    }
    else
    {
     t.overwrite ( n ) ;
     remain.overwrite ( this ) ;
    }
   
    var total = t.total , last = t[total - 1] ;
    if ( last == 0 )
     return ;
     
    var key = last * CAL + ( total > 1 ? t[total - 2] >> UNIT : 0 ) ,
     j = remain.total ,
     i = j - total ,
     m = new BigInt ;
    t.moveLeftTo ( i , m ) ;
    if ( remain.diff ( m ) > -1 )
    {
     remain[remain.total ++ ] = 1 ;
     remain = remain.minus ( m ) ;
    }
   
    ONE.moveLeftTo ( total , m ) ;
    t = m.minus ( t ) ;
    while ( t.total < total )
     t[t.total ++] = 0 ;
   
    var v , c = CAL / key , p = POW / key , u = 1 << UNIT ;
    for ( i -- , j -- ; i > -1 ; i -- , j -- )
    {
     v = remain[j] == last
      ? BITMASK
      : Math.floor ( remain[j] * p + ( remain[j - 1] + u ) * c ) ;
     if ( v <= ( remain[j] += t.getMultiBit ( 0 , v , remain , i , 0 , total ) ) )
      continue ;
     t.moveLeftTo ( i , m ) ;
     remain = remain.minus ( m ) ;
     for ( ; v >= remain[j] ; v -- )
      remain = remain.minus ( m ) ;
    }
   
    remain.reset ( total ) ;   
    if ( bit > 0 )
     remain.shiftRightTo ( bit , remain ) ;
    if ( this.start < 0 )
     remain = ZERO.minus ( remain ) ;
   } ,
   
   /**
    * &#54788;&#51116; &#44050;&#51012; e &#47196; &#51228;&#44273;&#54616;&#44256; n &#51004;&#47196; &#45208;&#45576; &#45208;&#47672;&#51648; &#44050;&#51012; &#48152;&#54872;&#54620;&#45796;.
    * @param BigInt e &#51228;&#44273; &#44050;
    * @param BigInt n &#45208;&#45580; &#44050; ( RSA &#50516;/&#48373;&#54840;&#54868; &#44277;&#53685;&#53412; n &#51076; )
    * @see  pow ( &#47928;&#51088;&#50676; , e ) % this.n
    */
   powMod: function ( e , n )
   {
    var bit = e.getBitLength () , lem = 6 ;
    if ( bit < 18 )
     lem = 1 ;
    else if ( bit < 48 )
     lem = 3 ;
    else if ( bit < 144 )
     lem = 4 ;
    else if ( bit < 768 )
     lem = 5 ;
   
    var value = [] , lm = lem - 1 , lk = ( 1 << lem ) - 1 ,   
     t = new BigInt , i ;   
    this.moveLeftTo ( n.total , t ) ;
    t.modTo ( n , t ) ;
    n.modular () ;
    value[1] = this.start < 0 && t.diff ( ZERO ) > 0 ? n.minus ( t ) : t ;
   
    if ( lem > 1 )
    {
     t = new BigInt ;
     n.squareTo ( value[1] , t ) ;
     for ( i = 3 ; i <= lk ; i += 2 )
      n.multiplyTo ( t , value[i - 2] , value = new BigInt ) ;
    }

    var r1 = new BigInt ( 1 ) , r2 = new BigInt ,
     j = e.total - 1 , q , k ;
    for ( i = e[j].toString ( 2 ).length - 1 ; j >= 0 ; )
    {
     q = i >= lm
      ? ( e[j] >> ( i - lm ) ) & lk
      : ( ( e[j] & ( ( 1 << ( i + 1 ) ) - 1 ) ) << ( lm - i ) ) + ( j > 0 ? e[j - 1] >> ( BIT + i - lm ) : 0 ) ;
     for ( k = lem ; ( q & 1 ) == 0 ; k -- )
      q >>= 1 ;
     if ( ( i -= k ) < 0 )
      i += BIT , j -- ;
     if ( r1.total == 1 )
      r1.overwrite ( value[q] ) ;
     else
     {
      for ( ; k > 1 ; k -= 2 )
       n.squareTo ( r1 , r2 ) , n.squareTo ( r2 , r1 ) ;
      if ( k > 0 )
       n.squareTo ( r1 , r2 ) ;
      else
       r1 = [r2 , r2 = r1][0] ;
      n.multiplyTo ( r2 , value[q] , r1 ) ;
     }
     while ( j > -1 && ( e[j] & ( 1 << i ) ) == 0 )
     {
      n.squareTo ( r1 , r2 ) ;
      r1 = [r2 , r2 = r1][0] ;
      if ( -- i < 0 )
       i = BIT - 1 , j -- ;
     }
    }
    n.reduce ( r1 ) ;
    return r1 ;
   } ,
   
   /**
    * &#47805;&#44256;&#47700;&#47532;(Montgomery) &#47784;&#46280;&#47084; &#52488;&#44592;&#54868;
    */
   modular: function ()
   {
    if ( this.point )
     return ;
    if ( this.total < 1 || ( this[0] & 1 ) == 0 )
     this.point = 0 ;
    else
    {
     var x = this[0] & 3 ;
     for ( var i = 4 ; i < 17 ; i = i * 2 )
      x = x * ( 2 - ( this[0] & HEX ) * x ) & HEX ;
     x = x * ( 2 - this[0] * x & BITMASK ) & BITMASK ;
     this.point = x > 0 ? BITMAX - x : -x ;
    }
    this.split = this.point & HEX['15'] ;
    this.mod = this.point >> 15 ;
    this.mask = ( 1 << ( BIT - 15 ) ) -1 ;
    this.double = 2 * this.total ;
   } ,
   
   /**
    * &#47784;&#46280;&#47084; &#44273; &#50672;&#49328; &#44208;&#44284;&#47484; result &#50640; &#54624;&#45817;&#54620;&#45796;.
    * @param BitInt source &#44273;&#54624; &#44050;
    * @param BitInt target &#44273;&#54624; &#44050;
    * @param BitInt result &#44208;&#44284; &#44050;
    */
   multiplyTo: function ( source , target , result )
   {
    for ( var i = 0 ; i < source.total ; i ++ )
     result = 0 ;
    for ( i = 0 ; i < target.total ; i ++ )
     result[i + source.total] = source.getMultiBit ( 0 , target , result , i , 0 , source.total ) ;
    result.reset ( source.total + target.total , 0 ) ;
    this.reduce ( source.start == target.start ? result : ZERO.minus ( result ) ) ;
   } ,
   
   /**
    * &#47784;&#46280;&#47084; &#51228;&#44273;&#44540;(&#47336;&#53944;) &#50672;&#49328; &#44208;&#44284;&#47484; result &#50640;&#54624; &#54624;&#45817;&#54620;&#45796;.
    * @param BitInt target &#51228;&#44273;&#44540;
    * @param BitInt result &#44208;&#44284; &#44050;
    */
   squareTo: function ( target , result )
   {
    result.total = target.total * 2 ;
    for ( i = result.total - 1 ; i > -1 ; i -- )
     result = 0 ;
    var total = target.total - 1 ;
    for ( i = 0 ; i < total ; i ++ )
    {
     var c = target.getMultiBit ( i , target , result , 2 * i , 0 , 1 ) ;
     if ( ( result[i + target.total] += target.getMultiBit ( i + 1 , 2 * target , result , 2 * i + 1 , c , target.total - i - 1 ) ) > BITMASK )
     {
      result[i + target.total] -= BITMAX ;
      result[i + target.total + 1] = 1 ;
     }
    }
    if ( result.total > 0 )
     result[result.total - 1] += target.getMultiBit ( i , target , result , 2 * i , 0 , 1 ) ;
    result.reset ( result.total , 0 ) ;
    this.reduce ( result ) ;
   } ,
   
   /**
    * &#47784;&#46280;&#47140; &#50672;&#49328;&#51012; &#49688;&#54665;&#54620;&#45796;.
    * @param BigInt target &#50672;&#49328; &#45824;&#49345; &#44050;
    */
   reduce: function ( target )
   {
    while ( target.total <= this.double )
     target[target.total ++] = 0 ;
    for ( var i = 0 , j , v ; i < this.total ; i ++ )
    {
     j = target & HEX['15'] ;
     v = j * this.split + ( ( j * this.mod + ( target >> 15 ) * this.split & this.mask ) << 15 ) & BITMASK ;
     j = i + this.total ;
     target[j] += this.getMultiBit ( 0 , v , target , i , 0 , this.total ) ;
     while ( target[j] > BITMASK )
      target[j] -= BITMAX , target[++ j] ++ ;
    }
    target.reset () ;
    target.moveRightTo ( this.total , target ) ;
    if ( target.diff ( this ) > -1 )
     target = target.minus ( this ) ;
   }
  }
  
  /**
   * &#48708;&#53944; &#47560;&#49828;&#53356; &#50672;&#49328; &#49688;&#54665;&#51012; &#50948;&#54620; &#54532;&#47532;&#49483;
   */
  var HEX =
  {
   '4': 0xf ,
   '8': 0xff ,
   '14': 0x3fff ,
   '15': 0x7fff ,
   '16': 0xffff ,
   '26': 0x3ffffff ,
   '28': 0xfffffff ,
   '30': 0x3fffffff ,
   '32': 0xffffffff
  } ;
  
  /**
   * &#48652;&#46972;&#50864;&#51200;&#50640; &#46384;&#47480; &#48708;&#53944; &#49688; &#51228;&#54620;&#44284; &#47680;&#54000;&#48708;&#53944; &#52628;&#52636; &#54632;&#49688; &#44368;&#52404;
   */
  var BIT = 28 ,
   FAR = ( ( 0xdeadbeefcafe & HEX['28'] ) == 0xefcafe ) ;
  if ( FAR && navigator.appName == 'Microsoft Internet Explorer' )
   BIT = 30 ;
  else if ( FAR && navigator.appName != 'Netscape' )
  {
   BIT = 26 ;
   BigInt.prototype.getMultiBit = function ( i , value , target , j , result , repeat )
   {
    for ( var v ; repeat > 0 ; repeat -- )
    {
     v = value * this[i ++] + target[j] + result ;
     result = Math.floor ( v / 0x4000000 ) ;
     target[j ++] = v & HEX[BIT] ;
    }
    return result ;
   }
  }
  
  /**
   * &#49345;&#49688; &#49440;&#50616;
   */
  var BITMAX = 1 << BIT ,
   BITMASK = ( BITMAX ) - 1 ,  
   UNIT = 2 * BIT - 52 ,  // 28bit = 100, 30bit = 1000, 26bit = 0
   POW = Math.pow ( 2 , 52 ) ,
   CAL = 1 << 52 - BIT ,
   ZERO = new BigInt ( 0 ) ,
   ONE = new BigInt ( 1 ) ;
  
  return BigInt ;

})() ;


/**
  * &#45936;&#51060;&#53552; &#48320;&#54872;&#50857; &#53364;&#47000;&#49828;
  */
var Convert = {
  preset: {'0':'0', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6', '7':'7', '8':'8', '9':'9', '10':'A', '11':'B', '12':'C', '13':'D', '14':'E', '15':'F', 'A':10, 'B':11, 'C':12, 'D':13, 'E':14, 'F':15} ,
  
  hexToDecimal: function ( hex )
  {
   return parseInt ( this.preset[hex.toUpperCase ()] , 10 ) ;
  } ,
  
  decimalToHex: function ( decimal )
  {
   return this.preset[decimal] ;
  }
}

return RSA ;

})();
function getpass(m){
var a = ssRsa();
return a.encrypt(m);
}
源码上传了,谢谢!
主要是测一下自己的JS调试能力,太小白了(大神们不要笑话),调试的是这个网址:http://pz-2015.com/main_login.php?move_pc_screen=

新建文本文档 (4).txt

25.63 KB, 下载次数: 6

123.JPG

最佳答案


回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:100% (1/1)

签到天数: 1 天

发表于 2016-5-30 12:59:34 | 显示全部楼层   广东省汕头市
很明显的RSA

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:100% (1/1)

签到天数: 1 天

发表于 2016-5-30 13:11:04 | 显示全部楼层   广东省汕头市
这不是定制区100块的单子么  key都没要加什么密。。
回复

使用道具 举报

结帖率:50% (1/2)
 楼主| 发表于 2016-5-30 13:12:21 | 显示全部楼层   广西壮族自治区南宁市
明明明明 发表于 2016-5-30 13:11
这不是定制区100块的单子么  key都没要加什么密。。

是的,我找来练练手,我找到问题了, 是没有new对象-_-!
回复

使用道具 举报

结帖率:50% (1/2)
 楼主| 发表于 2016-5-30 13:13:44 | 显示全部楼层   广西壮族自治区南宁市
明明明明 发表于 2016-5-30 13:11
这不是定制区100块的单子么  key都没要加什么密。。

这个是base64加密的也要Key吗??求指教
回复

使用道具 举报

结帖率:50% (1/2)
 楼主| 发表于 2016-5-30 13:17:52 | 显示全部楼层   广西壮族自治区南宁市

哦,我还以为是base64加密呢,我在研究研究
回复

使用道具 举报

结帖率:100% (3/3)

签到天数: 28 天

发表于 2016-5-30 13:42:41 | 显示全部楼层   江苏省苏州市
我发现你了练手练得很有水准,这单子还没有人接,你要是有好心人帮你解出来了,正好100块劳务费。
js调试
http://bbs.125.la/thread-13901601-1-1.html
(出处: 精易论坛)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表