반응형
  1. XHTML1.1 에서 사용하면 안되는 것들
    1. 일반적으로 범하기 쉬운 오류
      1. 닫히지 않은 빈요소 - Not closing empty elements (elements without closing tags)
      2. 닫히지 않은 꽉 찬 요소 - Not closing non-empty elements
      3. 부적합한 함유 요소 - Improperly nesting elements (elements must be closed in reverse order)
      4. 대체 텍스트가 기술되지 않음 - Not specifying alternate text for images (using the alt attribute, which helps make pages accessible for devices that don't load images or screen-readers for the blind)
      5. 본문에 직접 텍스트를 삽입 - Putting text directly in the body of the document
      6. 인라인 요소에 블록-레벨 요소를 포함 - Nesting block-level elements within inline elements
      7. 속성 값을 인용부호로 감싸지 않음 - Not putting quotation marks around attribute values
      8. '&' 문자를 직접 사용 ('&'로 대체) - Using the ampersand outside of entities (use & to display the ampersand character)
      9. 태그 이름이나 태그 속성에 대문자를 사용 - Using uppercase tag names and/or tag attributes
      10. 간소화된 속성 사용 - Attribute minimization
    2. 그 외의 오류들
      1. <form 에 name속성 사용하지 못함 - 2009/02/21 07:28:08
      2. <style> 사용 불가능
      3. URL 주소에서도 '&' 문자를 직접 사용하면 안됨.
      4. <form 에서 method="POST/post"
      5. width= 엘리먼트 허용하지 않음

 

XHTML1.1 에서 사용하면 안되는 것들#

 XHTML에서 사용하면 안되는 것들이 있다. 여기에 나열해 보자.

 

일반적으로 범하기 쉬운 오류#

 아래는 일반적으로 범하기 쉬운 오류로 위키백과에 소개된 내용이다. - http://ko.wikipedia.org/wiki/XHTML

 

닫히지 않은 빈요소 - Not closing empty elements (elements without closing tags)#
  • 틀림: <br>
  • 옳음: <br />

 

닫히지 않은 꽉 찬 요소 - Not closing non-empty elements#
  • 틀림: <p>This is a paragraph.<p>This is another paragraph.
  • 옳음: <p>This is a paragraph.</p><p>This is another paragraph.</p>

 

부적합한 함유 요소 - Improperly nesting elements (elements must be closed in reverse order)#
  • 틀림: <em><strong>This is some text.</em></strong>
  • 옳음: <em><strong>This is some text.</strong></em>

 

대체 텍스트가 기술되지 않음 - Not specifying alternate text for images (using the alt attribute, which helps make pages accessible for devices that don't load images or screen-readers for the blind)#
  • 틀림: <img src="/skins/common/images/poweredby_mediawiki_88x31.png" />
  • 옳음: <img src="/skins/common/images/poweredby_mediawiki_88x31.png" alt="MediaWiki" />

 

본문에 직접 텍스트를 삽입 - Putting text directly in the body of the document#
  • 틀림: <body>Welcome to my page.</body>
  • 옳음: <body><p>Welcome to my page.</p></body>

 

인라인 요소에 블록-레벨 요소를 포함 - Nesting block-level elements within inline elements#
  • 틀림: <em><h2>Introduction</h2></em>
  • 옳음: <h2><em>Introduction</em></h2>

 

속성 값을 인용부호로 감싸지 않음 - Not putting quotation marks around attribute values#
  • 틀림: <td rowspan=3>
  • 옳음: <td rowspan="3">

 

'&' 문자를 직접 사용 ('&amp;'로 대체) - Using the ampersand outside of entities (use &amp; to display the ampersand character)#
  • 틀림: <title>Cars & Trucks</title>
  • 옳음: <title>Cars &amp; Trucks</title>

 

태그 이름이나 태그 속성에 대문자를 사용 - Using uppercase tag names and/or tag attributes#
  • 틀림: <BODY><P>The Best Page Ever</P></BODY>
  • 옳음: <body><p>The Best Page Ever</p></body>

 

간소화된 속성 사용 - Attribute minimization#
  • 틀림: <textarea readonly>READ-ONLY</textarea>
  • 옳음: <textarea readonly="readonly">READ-ONLY</textarea>

 

 

그 외의 오류들#

 그 외에 직접 작정하면서 오류가 났던 부분을 정리한다.

 

<form 에 name속성 사용하지 못함 - 2009/02/21 07:28:08#
  • 흔히 <form name="fname" ... 이런식으로 정의해서 사용하지만 form에 name속성은 원래 허용하지 않는 속성인가보다. id속성은 무관하니 id로 해결해야 겠다.

 

<style> 사용 불가능#
  • css파일 이외의 style은 사용불가능 하다. 대신 inline style은 허용하니 inline 아니면 css파일로 스타일을 정의해야 한다.

 

URL 주소에서도 '&' 문자를 직접 사용하면 안됨.#
  • URL 링크를 생성하는데에도.. &문자를 바로 사용불가능함.
  • & => &amp; 바꾸어야함.

 

<form 에서 method="POST/post"#
  • form 태그에서 method정의시 대문자를 입력하면 안된 post/get과 같이 소문자로만 입력해야 함

 

td width= 어트리뷰트 허용하지 않음#
  • 보통 <td width 이런식으로 너비를 정하지만 이렇게 정의하지 못하게 되어 있음
  • <td>태그에서는 width 어트리뷰트를 허용하지 않음
  • Attribute "width" exists, but can not be used for this element. 에러를 낸다.



출처 : http://bequietzero.springnote.com/pages/2758810

 

Posted by 1010
반응형
<input type="text" autocomplete="off"/> <- 직접 기술한 건 잘못된 예


<input type="text" onfocus="this.setAttribute('autocomplete', 'off');"   /> <- 올바른 방법

Posted by 1010
반응형

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
 function test(obj){
  var tc = document.getElementsByName(obj.name);
  for(var i=0; tc.length; i++){
   if(tc[i] == obj){
    var j = i;
    break;
   }
  }
  alert(j);

 }
//-->
</SCRIPT>
 <BODY>
  <INPUT TYPE="text" NAME="aaa" ONCLICK="test(this);"><INPUT TYPE="button" name="btn" VALUE="" ONCLICK="test(this);">
   <INPUT TYPE="text" NAME="aaa" ONCLICK="test(this);"><INPUT TYPE="button"  name="btn" VALUE="" ONCLICK="test(this);">
 </BODY>
</HTML>

Posted by 1010
반응형
디비에 넣을때 변환

String contents = comment.getContent().replace( "\r\n", "<BR/>" );
comment.setContent(contents);


화면상에 뿌려줄때 변환 (수정모드시)
String contents = qnaComment.getContent().replace( "<BR/>", "\r\n" );
qnaComment.setContent(contents);

일반화면
<%=contents>
Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 3005 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>DES Crypt</title>
    <!-- des.js -->
   
    <script language="Javascript">
function dP(){
  salt=document.CRYPT.Salt.value;
  pw_salt=this.crypt(salt,document.CRYPT.PW.value);

  document.CRYPT.ENC_PW.value=pw_salt[0];
  document.CRYPT.Salt.value=pw_salt[1];
  return false;
}

function bTU(b){
      value=Math.floor(b);
      return (value>=0?value:value+256);
}
function fBTI(b,offset){
      value=this.byteToUnsigned(b[offset++]);
      value|=(this.byteToUnsigned(b[offset++])<<8);
      value|=(this.byteToUnsigned(b[offset++])<<16);
      value|=(this.byteToUnsigned(b[offset++])<<24);
      return value;
}
function iTFB(iValue,b,offset){
      b[offset++]=((iValue)&0xff);
      b[offset++]=((iValue>>>8)&0xff);
      b[offset++]=((iValue>>>16)&0xff);
      b[offset++]=((iValue>>>24)&0xff);
}
function P_P(a,b,n,m,results){
      t=((a>>>n)^b)&m;
      a^=t<<n;
      b^=t;
      results[0]=a;
      results[1]=b;
}
function H_P(a,n,m){
      t=((a<<(16-n))^a)&m;
      a=a^t^(t>>>(16-n));
      return a;
}
function d_s_k(key){
      schedule=new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
      c=this.fourBytesToInt(key,0);
      d=this.fourBytesToInt(key,4);
      results=new Array(0,0);
      this.PERM_OP(d,c,4,0x0f0f0f0f,results);
      d=results[0];c=results[1];
      c=this.HPERM_OP(c,-2,0xcccc0000);
      d=this.HPERM_OP(d,-2,0xcccc0000);
      this.PERM_OP(d,c,1,0x55555555,results);
      d=results[0];c=results[1];
      this.PERM_OP(c,d,8,0x00ff00ff,results);
      c=results[0];d=results[1];
      this.PERM_OP(d,c,1,0x55555555,results);
      d=results[0];c=results[1];
      d=(((d&0x000000ff)<<16)|(d&0x0000ff00)|((d&0x00ff0000)>>>16)|((c&0xf0000000)>>>4));
      c&=0x0fffffff;
      s=0;t=0;
      j=0;
      for(i=0;i<this.ITERATIONS;i++){
         if(this.shifts2[i]){
            c=(c>>>2)|(c<<26);
            d=(d>>>2)|(d<<26);
         }else{
            c=(c>>>1)|(c<<27);
            d=(d>>>1)|(d<<27);
         }
         c&=0x0fffffff;
         d&=0x0fffffff;
         s=this.skb[0][c&0x3f]|this.skb[1][((c>>>6)&0x03)|((c>>>7)&0x3c)]|this.skb[2][((c>>>13)&0x0f)|((c>>>14)&0x30)]|this.skb[3][((c>>>20)&0x01)|((c>>>21)&0x06)|((c>>>22)&0x38)];
         t=this.skb[4][d&0x3f]|this.skb[5][((d>>>7)&0x03)|((d>>>8)&0x3c)]|this.skb[6][(d>>>15)&0x3f]|this.skb[7][((d>>>21)&0x0f)|((d>>>22)&0x30)];
         schedule[j++]=((t<< 16)|(s&0x0000ffff))&0xffffffff;
         s=((s>>>16)|(t&0xffff0000));
         s=(s<<4)|(s>>>28);
         schedule[j++]=s&0xffffffff;
      }
      return schedule;
}
function D_E(L,R,S,E0,E1,s){
      v=R^(R>>>16);
      u=v&E0;
      v=v&E1;
      u=(u^(u<<16))^R^s[S];
      t=(v^(v<<16))^R^s[S+1];
      t=(t>>>4)|(t<<28);
      L^=this.SPtrans[1][t&0x3f]|this.SPtrans[3][(t>>>8)&0x3f]|this.SPtrans[5][(t>>>16)&0x3f]|this.SPtrans[7][(t>>>24)&0x3f]|this.SPtrans[0][u&0x3f]|this.SPtrans[2][(u>>>8)&0x3f]|this.SPtrans[4][(u>>>16)&0x3f]|this.SPtrans[6][(u>>>24)&0x3f];
      return L;
}
function bdy(schedule,Eswap0,Eswap1) {
  left=0;
  right=0;
  t=0;
      for(j=0;j<25;j++){
         for(i=0;i<this.ITERATIONS*2;i+=4){
            left=this.D_ENCRYPT(left, right,i,Eswap0,Eswap1,schedule);
            right=this.D_ENCRYPT(right,left,i+2,Eswap0,Eswap1,schedule);
         }
         t=left;
         left=right;
         right=t;
      }
      t=right;
      right=(left>>>1)|(left<<31);
      left=(t>>>1)|(t<<31);
      left&=0xffffffff;
      right&=0xffffffff;
      results=new Array(0,0);
      this.PERM_OP(right,left,1,0x55555555,results);
      right=results[0];left=results[1];
      this.PERM_OP(left,right,8,0x00ff00ff,results);
      left=results[0];right=results[1];
      this.PERM_OP(right,left,2,0x33333333,results);
      right=results[0];left=results[1];
      this.PERM_OP(left,right,16,0x0000ffff,results);
      left=results[0];right=results[1];
      this.PERM_OP(right,left,4,0x0f0f0f0f,results);
      right=results[0];left=results[1];
      out=new Array(0,0);
      out[0]=left;out[1]=right;
      return out;
}
function rC(){ return this.GOODCHARS[Math.floor(64*Math.random())]; }
function cript(salt,original){
  if(salt.length>=2) salt=salt.substring(0,2);
  while(salt.length<2) salt+=this.randChar();
  re=new RegExp("[^./a-zA-Z0-9]","g");
  if(re.test(salt)) salt=this.randChar()+this.randChar();
  charZero=salt.charAt(0)+'';
      charOne=salt.charAt(1)+'';
  ccZ=charZero.charCodeAt(0);
  ccO=charOne.charCodeAt(0);
  buffer=charZero+charOne+"           ";
      Eswap0=this.con_salt[ccZ];
      Eswap1=this.con_salt[ccO]<<4;
      key=new Array(0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0);
      for(i=0;i<key.length&&i<original.length;i++){
         iChar=original.charCodeAt(i);
         key[i]=iChar<<1;
      }
      schedule=this.des_set_key(key);
      out=this.body(schedule,Eswap0,Eswap1);
      b=new Array(0,0,0,0,0,0,0,0,0);
      this.intToFourBytes(out[0],b,0);
      this.intToFourBytes(out[1],b,4);
      b[8]=0;
      for(i=2,y=0,u=0x80;i<13;i++){
         for(j=0,c=0;j<6;j++){
            c<<=1;
            if((b[y]&u)!=0) c|=1;
            u>>>=1;
            if(u==0){
               y++;
               u=0x80;
            }
            buffer=buffer.substring(0,i)+String.fromCharCode(this.cov_2char[c])+buffer.substring(i+1,buffer.length);
         }
      }
  ret=new Array(buffer,salt);
      return ret;
}

function Crypt() {
this.ITERATIONS=16;
this.GOODCHARS=new Array(
  ".","/","0","1","2","3","4","5","6","7",
  "8","9","A","B","C","D","E","F","G","H",
  "I","J","K","L","M","N","O","P","Q","R",
  "S","T","U","V","W","X","Y","Z","a","b",
  "c","d","e","f","g","h","i","j","k","l",
  "m","n","o","p","q","r","s","t","u","v",
  "w","x","y","z");
this.con_salt=new Array(
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
      0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
      0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
      0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
      0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
      0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
      0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
      0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
      0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
      0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
      0x3D,0x3E,0x3F,0x00,0x00,0x00,0x00,0x00 );
this.shifts2=new Array(
  false,false,true,true,true,true,true,true,
  false,true, true,true,true,true,true,false );
this.skb=new Array(0,0,0,0,0,0,0,0);
  this.skb[0]=new Array(
         0x00000000,0x00000010,0x20000000,0x20000010,
         0x00010000,0x00010010,0x20010000,0x20010010,
         0x00000800,0x00000810,0x20000800,0x20000810,
         0x00010800,0x00010810,0x20010800,0x20010810,
         0x00000020,0x00000030,0x20000020,0x20000030,
         0x00010020,0x00010030,0x20010020,0x20010030,
         0x00000820,0x00000830,0x20000820,0x20000830,
         0x00010820,0x00010830,0x20010820,0x20010830,
         0x00080000,0x00080010,0x20080000,0x20080010,
         0x00090000,0x00090010,0x20090000,0x20090010,
         0x00080800,0x00080810,0x20080800,0x20080810,
         0x00090800,0x00090810,0x20090800,0x20090810,
         0x00080020,0x00080030,0x20080020,0x20080030,
         0x00090020,0x00090030,0x20090020,0x20090030,
         0x00080820,0x00080830,0x20080820,0x20080830,
         0x00090820,0x00090830,0x20090820,0x20090830 );
  this.skb[1]=new Array(
         0x00000000,0x02000000,0x00002000,0x02002000,
         0x00200000,0x02200000,0x00202000,0x02202000,
         0x00000004,0x02000004,0x00002004,0x02002004,
         0x00200004,0x02200004,0x00202004,0x02202004,
         0x00000400,0x02000400,0x00002400,0x02002400,
         0x00200400,0x02200400,0x00202400,0x02202400,
         0x00000404,0x02000404,0x00002404,0x02002404,
         0x00200404,0x02200404,0x00202404,0x02202404,
         0x10000000,0x12000000,0x10002000,0x12002000,
         0x10200000,0x12200000,0x10202000,0x12202000,
         0x10000004,0x12000004,0x10002004,0x12002004,
         0x10200004,0x12200004,0x10202004,0x12202004,
         0x10000400,0x12000400,0x10002400,0x12002400,
         0x10200400,0x12200400,0x10202400,0x12202400,
         0x10000404,0x12000404,0x10002404,0x12002404,
         0x10200404,0x12200404,0x10202404,0x12202404 );
  this.skb[2]=new Array(
         0x00000000,0x00000001,0x00040000,0x00040001,
         0x01000000,0x01000001,0x01040000,0x01040001,
         0x00000002,0x00000003,0x00040002,0x00040003,
         0x01000002,0x01000003,0x01040002,0x01040003,
         0x00000200,0x00000201,0x00040200,0x00040201,
         0x01000200,0x01000201,0x01040200,0x01040201,
         0x00000202,0x00000203,0x00040202,0x00040203,
         0x01000202,0x01000203,0x01040202,0x01040203,
         0x08000000,0x08000001,0x08040000,0x08040001,
         0x09000000,0x09000001,0x09040000,0x09040001,
         0x08000002,0x08000003,0x08040002,0x08040003,
         0x09000002,0x09000003,0x09040002,0x09040003,
         0x08000200,0x08000201,0x08040200,0x08040201,
         0x09000200,0x09000201,0x09040200,0x09040201,
         0x08000202,0x08000203,0x08040202,0x08040203,
         0x09000202,0x09000203,0x09040202,0x09040203 );
  this.skb[3]=new Array(
         0x00000000,0x00100000,0x00000100,0x00100100,
         0x00000008,0x00100008,0x00000108,0x00100108,
         0x00001000,0x00101000,0x00001100,0x00101100,
         0x00001008,0x00101008,0x00001108,0x00101108,
         0x04000000,0x04100000,0x04000100,0x04100100,
         0x04000008,0x04100008,0x04000108,0x04100108,
         0x04001000,0x04101000,0x04001100,0x04101100,
         0x04001008,0x04101008,0x04001108,0x04101108,
         0x00020000,0x00120000,0x00020100,0x00120100,
         0x00020008,0x00120008,0x00020108,0x00120108,
         0x00021000,0x00121000,0x00021100,0x00121100,
         0x00021008,0x00121008,0x00021108,0x00121108,
         0x04020000,0x04120000,0x04020100,0x04120100,
         0x04020008,0x04120008,0x04020108,0x04120108,
         0x04021000,0x04121000,0x04021100,0x04121100,
         0x04021008,0x04121008,0x04021108,0x04121108 );
  this.skb[4]=new Array(
         0x00000000,0x10000000,0x00010000,0x10010000,
         0x00000004,0x10000004,0x00010004,0x10010004,
         0x20000000,0x30000000,0x20010000,0x30010000,
         0x20000004,0x30000004,0x20010004,0x30010004,
         0x00100000,0x10100000,0x00110000,0x10110000,
         0x00100004,0x10100004,0x00110004,0x10110004,
         0x20100000,0x30100000,0x20110000,0x30110000,
         0x20100004,0x30100004,0x20110004,0x30110004,
         0x00001000,0x10001000,0x00011000,0x10011000,
         0x00001004,0x10001004,0x00011004,0x10011004,
         0x20001000,0x30001000,0x20011000,0x30011000,
         0x20001004,0x30001004,0x20011004,0x30011004,
         0x00101000,0x10101000,0x00111000,0x10111000,
         0x00101004,0x10101004,0x00111004,0x10111004,
         0x20101000,0x30101000,0x20111000,0x30111000,
         0x20101004,0x30101004,0x20111004,0x30111004 );
  this.skb[5]=new Array(
         0x00000000,0x08000000,0x00000008,0x08000008,
         0x00000400,0x08000400,0x00000408,0x08000408,
         0x00020000,0x08020000,0x00020008,0x08020008,
         0x00020400,0x08020400,0x00020408,0x08020408,
         0x00000001,0x08000001,0x00000009,0x08000009,
         0x00000401,0x08000401,0x00000409,0x08000409,
         0x00020001,0x08020001,0x00020009,0x08020009,
         0x00020401,0x08020401,0x00020409,0x08020409,
         0x02000000,0x0A000000,0x02000008,0x0A000008,
         0x02000400,0x0A000400,0x02000408,0x0A000408,
         0x02020000,0x0A020000,0x02020008,0x0A020008,
         0x02020400,0x0A020400,0x02020408,0x0A020408,
         0x02000001,0x0A000001,0x02000009,0x0A000009,
         0x02000401,0x0A000401,0x02000409,0x0A000409,
         0x02020001,0x0A020001,0x02020009,0x0A020009,
         0x02020401,0x0A020401,0x02020409,0x0A020409 );
  this.skb[6]=new Array(
         0x00000000,0x00000100,0x00080000,0x00080100,
         0x01000000,0x01000100,0x01080000,0x01080100,
         0x00000010,0x00000110,0x00080010,0x00080110,
         0x01000010,0x01000110,0x01080010,0x01080110,
         0x00200000,0x00200100,0x00280000,0x00280100,
         0x01200000,0x01200100,0x01280000,0x01280100,
         0x00200010,0x00200110,0x00280010,0x00280110,
         0x01200010,0x01200110,0x01280010,0x01280110,
         0x00000200,0x00000300,0x00080200,0x00080300,
         0x01000200,0x01000300,0x01080200,0x01080300,
         0x00000210,0x00000310,0x00080210,0x00080310,
         0x01000210,0x01000310,0x01080210,0x01080310,
         0x00200200,0x00200300,0x00280200,0x00280300,
         0x01200200,0x01200300,0x01280200,0x01280300,
         0x00200210,0x00200310,0x00280210,0x00280310,
         0x01200210,0x01200310,0x01280210,0x01280310 );
  this.skb[7]=new Array(
         0x00000000,0x04000000,0x00040000,0x04040000,
         0x00000002,0x04000002,0x00040002,0x04040002,
         0x00002000,0x04002000,0x00042000,0x04042000,
         0x00002002,0x04002002,0x00042002,0x04042002,
         0x00000020,0x04000020,0x00040020,0x04040020,
         0x00000022,0x04000022,0x00040022,0x04040022,
         0x00002020,0x04002020,0x00042020,0x04042020,
         0x00002022,0x04002022,0x00042022,0x04042022,
         0x00000800,0x04000800,0x00040800,0x04040800,
         0x00000802,0x04000802,0x00040802,0x04040802,
         0x00002800,0x04002800,0x00042800,0x04042800,
         0x00002802,0x04002802,0x00042802,0x04042802,
         0x00000820,0x04000820,0x00040820,0x04040820,
         0x00000822,0x04000822,0x00040822,0x04040822,
         0x00002820,0x04002820,0x00042820,0x04042820,
         0x00002822,0x04002822,0x00042822,0x04042822 );
this.SPtrans=new Array(0,0,0,0,0,0,0,0);
  this.SPtrans[0]=new Array(
         0x00820200,0x00020000,0x80800000,0x80820200,
         0x00800000,0x80020200,0x80020000,0x80800000,
         0x80020200,0x00820200,0x00820000,0x80000200,
         0x80800200,0x00800000,0x00000000,0x80020000,
         0x00020000,0x80000000,0x00800200,0x00020200,
         0x80820200,0x00820000,0x80000200,0x00800200,
         0x80000000,0x00000200,0x00020200,0x80820000,
         0x00000200,0x80800200,0x80820000,0x00000000,
         0x00000000,0x80820200,0x00800200,0x80020000,
         0x00820200,0x00020000,0x80000200,0x00800200,
         0x80820000,0x00000200,0x00020200,0x80800000,
         0x80020200,0x80000000,0x80800000,0x00820000,
         0x80820200,0x00020200,0x00820000,0x80800200,
         0x00800000,0x80000200,0x80020000,0x00000000,
         0x00020000,0x00800000,0x80800200,0x00820200,
         0x80000000,0x80820000,0x00000200,0x80020200 );
  this.SPtrans[1]=new Array(
         0x10042004,0x00000000,0x00042000,0x10040000,
         0x10000004,0x00002004,0x10002000,0x00042000,
         0x00002000,0x10040004,0x00000004,0x10002000,
         0x00040004,0x10042000,0x10040000,0x00000004,
         0x00040000,0x10002004,0x10040004,0x00002000,
         0x00042004,0x10000000,0x00000000,0x00040004,
         0x10002004,0x00042004,0x10042000,0x10000004,
         0x10000000,0x00040000,0x00002004,0x10042004,
         0x00040004,0x10042000,0x10002000,0x00042004,
         0x10042004,0x00040004,0x10000004,0x00000000,
         0x10000000,0x00002004,0x00040000,0x10040004,
         0x00002000,0x10000000,0x00042004,0x10002004,
         0x10042000,0x00002000,0x00000000,0x10000004,
         0x00000004,0x10042004,0x00042000,0x10040000,
         0x10040004,0x00040000,0x00002004,0x10002000,
         0x10002004,0x00000004,0x10040000,0x00042000 );
  this.SPtrans[2]=new Array(
         0x41000000,0x01010040,0x00000040,0x41000040,
         0x40010000,0x01000000,0x41000040,0x00010040,
         0x01000040,0x00010000,0x01010000,0x40000000,
         0x41010040,0x40000040,0x40000000,0x41010000,
         0x00000000,0x40010000,0x01010040,0x00000040,
         0x40000040,0x41010040,0x00010000,0x41000000,
         0x41010000,0x01000040,0x40010040,0x01010000,
         0x00010040,0x00000000,0x01000000,0x40010040,
         0x01010040,0x00000040,0x40000000,0x00010000,
         0x40000040,0x40010000,0x01010000,0x41000040,
         0x00000000,0x01010040,0x00010040,0x41010000,
         0x40010000,0x01000000,0x41010040,0x40000000,
         0x40010040,0x41000000,0x01000000,0x41010040,
         0x00010000,0x01000040,0x41000040,0x00010040,
         0x01000040,0x00000000,0x41010000,0x40000040,
         0x41000000,0x40010040,0x00000040,0x01010000 );
  this.SPtrans[3]=new Array(
         0x00100402,0x04000400,0x00000002,0x04100402,
         0x00000000,0x04100000,0x04000402,0x00100002,
         0x04100400,0x04000002,0x04000000,0x00000402,
         0x04000002,0x00100402,0x00100000,0x04000000,
         0x04100002,0x00100400,0x00000400,0x00000002,
         0x00100400,0x04000402,0x04100000,0x00000400,
         0x00000402,0x00000000,0x00100002,0x04100400,
         0x04000400,0x04100002,0x04100402,0x00100000,
         0x04100002,0x00000402,0x00100000,0x04000002,
         0x00100400,0x04000400,0x00000002,0x04100000,
         0x04000402,0x00000000,0x00000400,0x00100002,
         0x00000000,0x04100002,0x04100400,0x00000400,
         0x04000000,0x04100402,0x00100402,0x00100000,
         0x04100402,0x00000002,0x04000400,0x00100402,
         0x00100002,0x00100400,0x04100000,0x04000402,
         0x00000402,0x04000000,0x04000002,0x04100400 );
  this.SPtrans[4]=new Array(
         0x02000000,0x00004000,0x00000100,0x02004108,
         0x02004008,0x02000100,0x00004108,0x02004000,
         0x00004000,0x00000008,0x02000008,0x00004100,
         0x02000108,0x02004008,0x02004100,0x00000000,
         0x00004100,0x02000000,0x00004008,0x00000108,
         0x02000100,0x00004108,0x00000000,0x02000008,
         0x00000008,0x02000108,0x02004108,0x00004008,
         0x02004000,0x00000100,0x00000108,0x02004100,
         0x02004100,0x02000108,0x00004008,0x02004000,
         0x00004000,0x00000008,0x02000008,0x02000100,
         0x02000000,0x00004100,0x02004108,0x00000000,
         0x00004108,0x02000000,0x00000100,0x00004008,
         0x02000108,0x00000100,0x00000000,0x02004108,
         0x02004008,0x02004100,0x00000108,0x00004000,
         0x00004100,0x02004008,0x02000100,0x00000108,
         0x00000008,0x00004108,0x02004000,0x02000008 );

  this.SPtrans[5]=new Array(
         0x20000010,0x00080010,0x00000000,0x20080800,
         0x00080010,0x00000800,0x20000810,0x00080000,
         0x00000810,0x20080810,0x00080800,0x20000000,
         0x20000800,0x20000010,0x20080000,0x00080810,
         0x00080000,0x20000810,0x20080010,0x00000000,
         0x00000800,0x00000010,0x20080800,0x20080010,
         0x20080810,0x20080000,0x20000000,0x00000810,
         0x00000010,0x00080800,0x00080810,0x20000800,
         0x00000810,0x20000000,0x20000800,0x00080810,
         0x20080800,0x00080010,0x00000000,0x20000800,
         0x20000000,0x00000800,0x20080010,0x00080000,
         0x00080010,0x20080810,0x00080800,0x00000010,
         0x20080810,0x00080800,0x00080000,0x20000810,
         0x20000010,0x20080000,0x00080810,0x00000000,
         0x00000800,0x20000010,0x20000810,0x20080800,
         0x20080000,0x00000810,0x00000010,0x20080010 );
  this.SPtrans[6]=new Array(
         0x00001000,0x00000080,0x00400080,0x00400001,
         0x00401081,0x00001001,0x00001080,0x00000000,
         0x00400000,0x00400081,0x00000081,0x00401000,
         0x00000001,0x00401080,0x00401000,0x00000081,
         0x00400081,0x00001000,0x00001001,0x00401081,
         0x00000000,0x00400080,0x00400001,0x00001080,
         0x00401001,0x00001081,0x00401080,0x00000001,
         0x00001081,0x00401001,0x00000080,0x00400000,
         0x00001081,0x00401000,0x00401001,0x00000081,
         0x00001000,0x00000080,0x00400000,0x00401001,
         0x00400081,0x00001081,0x00001080,0x00000000,
         0x00000080,0x00400001,0x00000001,0x00400080,
         0x00000000,0x00400081,0x00400080,0x00001080,
         0x00000081,0x00001000,0x00401081,0x00400000,
         0x00401080,0x00000001,0x00001001,0x00401081,
         0x00400001,0x00401080,0x00401000,0x00001001 );
  this.SPtrans[7]=new Array(
         0x08200020,0x08208000,0x00008020,0x00000000,
         0x08008000,0x00200020,0x08200000,0x08208020,
         0x00000020,0x08000000,0x00208000,0x00008020,
         0x00208020,0x08008020,0x08000020,0x08200000,
         0x00008000,0x00208020,0x00200020,0x08008000,
         0x08208020,0x08000020,0x00000000,0x00208000,
         0x08000000,0x00200000,0x08008020,0x08200020,
         0x00200000,0x00008000,0x08208000,0x00000020,
         0x00200000,0x00008000,0x08000020,0x08208020,
         0x00008020,0x08000000,0x00000000,0x00208000,
         0x08200020,0x08008020,0x08008000,0x00200020,
         0x08208000,0x00000020,0x00200020,0x08008000,
         0x08208020,0x00200000,0x08200000,0x08000020,
         0x00208000,0x00008020,0x08008020,0x08200000,
         0x00000020,0x08208000,0x00208020,0x00000000,
         0x08000000,0x08200020,0x00008000,0x00208020 );
this.cov_2char=new Array(
      0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
      0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
      0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
      0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
      0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
      0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
      0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
      0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A );
this.byteToUnsigned=bTU;
this.fourBytesToInt=fBTI;
this.intToFourBytes=iTFB;
this.PERM_OP=P_P;
this.HPERM_OP=H_P;
this.des_set_key=d_s_k;
this.D_ENCRYPT=D_E;
this.body=bdy;
this.randChar=rC;
this.crypt=cript;
this.displayPassword=dP;
}
Javacrypt=new Crypt();

    </script>
  </head>
  <body>
    <form name="CRYPT">
      <strong>Text: </strong><input type="text" name="PW">
      <input type="button" value="Encrypt" onClick="Javacrypt.displayPassword()"><br>
      <strong>Encrypted: </strong><input type="text" name="ENC_PW"><br>
      <strong>Salt: </strong><input type="text" name="Salt">
    </form>
    <br>
    <b>NOTE</b>: If you do not enter a salt, one will be randomly generated.
  </body>
</html>
Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>SHA-1 Crypt</title>
  </head>
  <body>
      <!-- sha1.js -->
    <script language="JavaScript">
/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
 * in FIPS PUB 180-1
 * Version 2.1 Copyright Paul Johnston 2000 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 */

var hexcase = 0;
var b64pad  = "";
var chrsz   = 8;

function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}

function sha1_vm_test()
{
  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}

function core_sha1(x, len)
{
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
                       safe_add(safe_add(e, w[j]), sha1_kt(j)));
      e = d;
      d = c;
      c = rol(b, 30);
      b = a;
      a = t;
    }

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
    e = safe_add(e, olde);
  }
  return Array(a, b, c, d, e);
 
}

function sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

function sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}  

function core_hmac_sha1(key, data)
{
  var bkey = str2binb(key);
  if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
  return core_sha1(opad.concat(hash), 512 + 160);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

function str2binb(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
  return bin;
}

function binb2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (24 - i%32)) & mask);
  return str;
}

function binb2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8  )) & 0xF);
  }
  return str;
}

function binb2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * (3 -  i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

    </script>
    <form>
      <font color=#000000 size=3>Input</font>
      <input type=text name=input size=40><br>
      <font color=#000000 size=3>Result</font>
      <input type=text name=hash size=50><br>
      <input type=button value="SHA-1 It!" onclick="hash.value = hex_sha1(input.value)">
    </form>
  </body>
</html>

Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>MD5 Hashing</title>
  </head>
  <body>
      <!-- md5.js -->
    <script language="JavaScript">
/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

var hexcase = 0;
var b64pad  = "";
var chrsz   = 8;

function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

function core_md5(x, len)
{
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

    </script>
    <form>
      <font color=#000000 size=3>Input</font>  </td><td > <input type=text name=input size=40><br>
      <font color=#000000 size=3>Result</font> </td><td > <input type=text name=hash size=40><br>
      <input type=button value="MD5 It!" onclick="hash.value = hex_md5(input.value)">
    </form>
  </body>
</html>

Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>MD4 Hashing</title>
  </head>
  <body>
      <!-- md4.js -->
    <script language="JavaScript">
/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD4 Message
 * Digest Algorithm, as defined in RFC 1320.
 * Version 2.1 Copyright (C) Jerrad Pierce, Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

var hexcase = 0;
var b64pad  = "";
var chrsz   = 8;

function hex_md4(s){ return binl2hex(core_md4(str2binl(s), s.length * chrsz));}
function b64_md4(s){ return binl2b64(core_md4(str2binl(s), s.length * chrsz));}
function str_md4(s){ return binl2str(core_md4(str2binl(s), s.length * chrsz));}
function hex_hmac_md4(key, data) { return binl2hex(core_hmac_md4(key, data)); }
function b64_hmac_md4(key, data) { return binl2b64(core_hmac_md4(key, data)); }
function str_hmac_md4(key, data) { return binl2str(core_hmac_md4(key, data)); }

function md4_vm_test()
{
  return hex_md4("abc") == "a448017aaf21d8525fc10ae87aa6729d";
}

function core_md4(x, len)
{
  x[len >> 5] |= 0x80 << (len % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;
 
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md4_ff(a, b, c, d, x[i+ 0], 3 );
    d = md4_ff(d, a, b, c, x[i+ 1], 7 );
    c = md4_ff(c, d, a, b, x[i+ 2], 11);
    b = md4_ff(b, c, d, a, x[i+ 3], 19);
    a = md4_ff(a, b, c, d, x[i+ 4], 3 );
    d = md4_ff(d, a, b, c, x[i+ 5], 7 );
    c = md4_ff(c, d, a, b, x[i+ 6], 11);
    b = md4_ff(b, c, d, a, x[i+ 7], 19);
    a = md4_ff(a, b, c, d, x[i+ 8], 3 );
    d = md4_ff(d, a, b, c, x[i+ 9], 7 );
    c = md4_ff(c, d, a, b, x[i+10], 11);
    b = md4_ff(b, c, d, a, x[i+11], 19);
    a = md4_ff(a, b, c, d, x[i+12], 3 );
    d = md4_ff(d, a, b, c, x[i+13], 7 );
    c = md4_ff(c, d, a, b, x[i+14], 11);
    b = md4_ff(b, c, d, a, x[i+15], 19);

    a = md4_gg(a, b, c, d, x[i+ 0], 3 );
    d = md4_gg(d, a, b, c, x[i+ 4], 5 );
    c = md4_gg(c, d, a, b, x[i+ 8], 9 );
    b = md4_gg(b, c, d, a, x[i+12], 13);
    a = md4_gg(a, b, c, d, x[i+ 1], 3 );
    d = md4_gg(d, a, b, c, x[i+ 5], 5 );
    c = md4_gg(c, d, a, b, x[i+ 9], 9 );
    b = md4_gg(b, c, d, a, x[i+13], 13);
    a = md4_gg(a, b, c, d, x[i+ 2], 3 );
    d = md4_gg(d, a, b, c, x[i+ 6], 5 );
    c = md4_gg(c, d, a, b, x[i+10], 9 );
    b = md4_gg(b, c, d, a, x[i+14], 13);
    a = md4_gg(a, b, c, d, x[i+ 3], 3 );
    d = md4_gg(d, a, b, c, x[i+ 7], 5 );
    c = md4_gg(c, d, a, b, x[i+11], 9 );
    b = md4_gg(b, c, d, a, x[i+15], 13);

    a = md4_hh(a, b, c, d, x[i+ 0], 3 );
    d = md4_hh(d, a, b, c, x[i+ 8], 9 );
    c = md4_hh(c, d, a, b, x[i+ 4], 11);
    b = md4_hh(b, c, d, a, x[i+12], 15);
    a = md4_hh(a, b, c, d, x[i+ 2], 3 );
    d = md4_hh(d, a, b, c, x[i+10], 9 );
    c = md4_hh(c, d, a, b, x[i+ 6], 11);
    b = md4_hh(b, c, d, a, x[i+14], 15);
    a = md4_hh(a, b, c, d, x[i+ 1], 3 );
    d = md4_hh(d, a, b, c, x[i+ 9], 9 );
    c = md4_hh(c, d, a, b, x[i+ 5], 11);
    b = md4_hh(b, c, d, a, x[i+13], 15);
    a = md4_hh(a, b, c, d, x[i+ 3], 3 );
    d = md4_hh(d, a, b, c, x[i+11], 9 );
    c = md4_hh(c, d, a, b, x[i+ 7], 11);
    b = md4_hh(b, c, d, a, x[i+15], 15);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);

  }
  return Array(a, b, c, d);

}

function md4_cmn(q, a, b, x, s, t)
{
  return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
}
function md4_ff(a, b, c, d, x, s)
{
  return md4_cmn((b & c) | ((~b) & d), a, 0, x, s, 0);
}
function md4_gg(a, b, c, d, x, s)
{
  return md4_cmn((b & c) | (b & d) | (c & d), a, 0, x, s, 1518500249);
}
function md4_hh(a, b, c, d, x, s)
{
  return md4_cmn(b ^ c ^ d, a, 0, x, s, 1859775393);
}

/*
 * Calculate the HMAC-MD4, of a key and some data
 */
function core_hmac_md4(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md4(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md4(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md4(opad.concat(hash), 512 + 128);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

    </script>
    <form>
      <font color=#000000 size=3>Input</font>  </td><td > <input type=text name=input size=40><br>
      <font color=#000000 size=3>Result</font> </td><td > <input type=text name=hash size=40><br>
      <input type=button value="MD4 It!" onclick="hash.value = hex_md4(input.value)">
    </form>
  </body>
</html>

Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>ASCII/Binary Converter</title>
  </head>
  <body text="black" link="blue" vlink="blue" alink="red"><br><br>
    <script language="JavaScript1.2">
function dobin(text,sepa) {
var letbin = ""
for (i=0; i<text.length;i++) {

let = text.substr(i,1);
if (i>0) {
var sep = sepa;
if (i % 10 == 0) {
  letbin=letbin+''
}
}
else {
var sep = "";
}

//Ascii -- Binary Code
if (let ==  "A") {letbin = letbin + sep + '01000001'}
if (let ==  "B") {letbin = letbin + sep + '01000010'}
if (let ==  "C") {letbin = letbin + sep + '01000011'}
if (let ==  "D") {letbin = letbin + sep + '01000100'}
if (let ==  "E") {letbin = letbin + sep + '01000101'}
if (let ==  "F") {letbin = letbin + sep + '01000110'}
if (let ==  "G") {letbin = letbin + sep + '01000111'}
if (let ==  "H") {letbin = letbin + sep + '01001000'}
if (let ==  "I") {letbin = letbin + sep + '01001001'}
if (let ==  "J") {letbin = letbin + sep + '01001010'}
if (let ==  "K") {letbin = letbin + sep + '01001011'}
if (let ==  "L") {letbin = letbin + sep + '01001100'}
if (let ==  "M") {letbin = letbin + sep + '01001101'}
if (let ==  "N") {letbin = letbin + sep + '01001110'}
if (let ==  "O") {letbin = letbin + sep + '01001111'}
if (let ==  "P") {letbin = letbin + sep + '01010000'}
if (let ==  "Q") {letbin = letbin + sep + '01010001'}
if (let ==  "R") {letbin = letbin + sep + '01010010'}
if (let ==  "S") {letbin = letbin + sep + '01010011'}
if (let ==  "T") {letbin = letbin + sep + '01010100'}
if (let ==  "U") {letbin = letbin + sep + '01010101'}
if (let ==  "V") {letbin = letbin + sep + '01010110'}
if (let ==  "W") {letbin = letbin + sep + '01010111'}
if (let ==  "X") {letbin = letbin + sep + '01011000'}
if (let ==  "Y") {letbin = letbin + sep + '01011001'}
if (let ==  "Z") {letbin = letbin + sep + '01011010'}
if (let ==  "a") {letbin = letbin + sep + '01100001'}
if (let ==  "b") {letbin = letbin + sep + '01100010'}
if (let ==  "c") {letbin = letbin + sep + '01100011'}
if (let ==  "d") {letbin = letbin + sep + '01100100'}
if (let ==  "e") {letbin = letbin + sep + '01100101'}
if (let ==  "f") {letbin = letbin + sep + '01100110'}
if (let ==  "g") {letbin = letbin + sep + '01100111'}
if (let ==  "h") {letbin = letbin + sep + '01101000'}
if (let ==  "i") {letbin = letbin + sep + '01101001'}
if (let ==  "j") {letbin = letbin + sep + '01101010'}
if (let ==  "k") {letbin = letbin + sep + '01101011'}
if (let ==  "l") {letbin = letbin + sep + '01101100'}
if (let ==  "m") {letbin = letbin + sep + '01101101'}
if (let ==  "n") {letbin = letbin + sep + '01101110'}
if (let ==  "o") {letbin = letbin + sep + '01101111'}
if (let ==  "p") {letbin = letbin + sep + '01110000'}
if (let ==  "q") {letbin = letbin + sep + '01110001'}
if (let ==  "r") {letbin = letbin + sep + '01110010'}
if (let ==  "s") {letbin = letbin + sep + '01110011'}
if (let ==  "t") {letbin = letbin + sep + '01110100'}
if (let ==  "u") {letbin = letbin + sep + '01110101'}
if (let ==  "v") {letbin = letbin + sep + '01110110'}
if (let ==  "w") {letbin = letbin + sep + '01110111'}
if (let ==  "x") {letbin = letbin + sep + '01111000'}
if (let ==  "y") {letbin = letbin + sep + '01111001'}
if (let ==  "z") {letbin = letbin + sep + '01111010'}
if (let ==  " ") {letbin = letbin + sep + '00100000'}

//Numbers:
if (let ==  "0") {letbin = letbin + sep + '00110000'}
if (let ==  "1") {letbin = letbin + sep + '00110001'}
if (let ==  "2") {letbin = letbin + sep + '00110010'}
if (let ==  "3") {letbin = letbin + sep + '00110011'}
if (let ==  "4") {letbin = letbin + sep + '00110100'}
if (let ==  "5") {letbin = letbin + sep + '00110101'}
if (let ==  "6") {letbin = letbin + sep + '00110110'}
if (let ==  "7") {letbin = letbin + sep + '00110111'}
if (let ==  "8") {letbin = letbin + sep + '00111000'}
if (let ==  "9") {letbin = letbin + sep + '00111001'}

//Special Characters:
if (let ==  "!") {letbin = letbin + sep + '00100001'}
if (let ==  "\"") {letbin = letbin + sep + '00100010'}
if (let ==  "#") {letbin = letbin + sep + '00100011'}
if (let ==  "$") {letbin = letbin + sep + '00100100'}
if (let ==  "%") {letbin = letbin + sep + '00100101'}
if (let ==  "&") {letbin = letbin + sep + '00100110'}
if (let ==  "'") {letbin = letbin + sep + '00100111'}
if (let ==  "(") {letbin = letbin + sep + '00101000'}
if (let ==  ")") {letbin = letbin + sep + '00101001'}
if (let ==  "*") {letbin = letbin + sep + '00101001'}
if (let ==  "+") {letbin = letbin + sep + '00101011'}
if (let ==  ",") {letbin = letbin + sep + '00101100'}
if (let ==  "-") {letbin = letbin + sep + '00101101'}
if (let ==  ".") {letbin = letbin + sep + '00101110'}
if (let ==  "/") {letbin = letbin + sep + '00101111'}
if (let ==  ":") {letbin = letbin + sep + '00111010'}
if (let ==  ";") {letbin = letbin + sep + '00111011'}
if (let ==  "<") {letbin = letbin + sep + '00111100'}
if (let ==  "=") {letbin = letbin + sep + '00111101'}
if (let ==  ">") {letbin = letbin + sep + '00111110'}
if (let ==  "?") {letbin = letbin + sep + '00111111'}
if (let ==  "@") {letbin = letbin + sep + '01000000'}
if (let ==  "[") {letbin = letbin + sep + '01011011'}
if (let ==  "\\") {letbin = letbin + sep + '01011100'}
if (let ==  "]") {letbin = letbin + sep + '01011101'}
if (let ==  "^") {letbin = letbin + sep + '01011110'}
if (let ==  "_") {letbin = letbin + sep + '01011111'}
if (let ==  "`") {letbin = letbin + sep + '01100000'}
if (let ==  "{") {letbin = letbin + sep + '01111011'}
if (let ==  "|") {letbin = letbin + sep + '01111100'}
if (let ==  "}") {letbin = letbin + sep + '01111101'}
if (let ==  "~") {letbin = letbin + sep + '01111110'}
if (let ==  "�") {letbin = letbin + sep + '10000000'}
if (let ==  "¡") {letbin = letbin + sep + '10100001'}
if (let ==  "¢") {letbin = letbin + sep + '10100010'}
if (let ==  "£") {letbin = letbin + sep + '10100011'}
if (let ==  "�") {letbin = letbin + sep + '10100100'}
if (let ==  "�") {letbin = letbin + sep + '10100101'}
if (let ==  "�") {letbin = letbin + sep + '10100110'}
if (let ==  "§") {letbin = letbin + sep + '10100111'}
if (let ==  "�") {letbin = letbin + sep + '10100111'}
if (let ==  "�") {letbin = letbin + sep + '10101001'}
if (let ==  "�") {letbin = letbin + sep + '10101010'}
if (let ==  "«") {letbin = letbin + sep + '10101011'}
if (let ==  "�") {letbin = letbin + sep + '10101100'}
if (let ==  "�") {letbin = letbin + sep + '10101101'}
if (let ==  "�") {letbin = letbin + sep + '10101110'}
if (let ==  "�") {letbin = letbin + sep + '10101111'}
if (let ==  "�") {letbin = letbin + sep + '10110000'}
if (let ==  "�") {letbin = letbin + sep + '10110001'}
if (let ==  "�") {letbin = letbin + sep + '10110010'}
if (let ==  "�") {letbin = letbin + sep + '10110011'}
if (let ==  "�") {letbin = letbin + sep + '10110100'}
if (let ==  "�") {letbin = letbin + sep + '10110101'}
if (let ==  "�") {letbin = letbin + sep + '10110110'}
if (let ==  "�") {letbin = letbin + sep + '10110111'}
if (let ==  "�") {letbin = letbin + sep + '10111000'}
if (let ==  "�") {letbin = letbin + sep + '10111001'}
if (let ==  "�") {letbin = letbin + sep + '10111010'}
if (let ==  "»") {letbin = letbin + sep + '10111011'}
if (let ==  "�") {letbin = letbin + sep + '10111100'}
if (let ==  "�") {letbin = letbin + sep + '10111101'}
if (let ==  "�") {letbin = letbin + sep + '10111110'}
if (let ==  "�") {letbin = letbin + sep + '10111111'}
if (let ==  "�") {letbin = letbin + sep + '11000000'}
if (let ==  "�") {letbin = letbin + sep + '11000001'}
if (let ==  "�") {letbin = letbin + sep + '11000010'}
if (let ==  "�") {letbin = letbin + sep + '11000011'}
if (let ==  "Ä") {letbin = letbin + sep + '11000100'}
if (let ==  "Å") {letbin = letbin + sep + '11000101'}
if (let ==  "Æ") {letbin = letbin + sep + '11000110'}
if (let ==  "Ç") {letbin = letbin + sep + '11000111'}
if (let ==  "�") {letbin = letbin + sep + '11001000'}
if (let ==  "�") {letbin = letbin + sep + '11001001'}
if (let ==  "�") {letbin = letbin + sep + '11001010'}
if (let ==  "Ë") {letbin = letbin + sep + '11001011'}
if (let ==  "�") {letbin = letbin + sep + '11001100'}
if (let ==  "�") {letbin = letbin + sep + '11001101'}
if (let ==  "�") {letbin = letbin + sep + '11001110'}
if (let ==  "�") {letbin = letbin + sep + '11001111'}
if (let ==  "�") {letbin = letbin + sep + '11010000'}
if (let ==  "�") {letbin = letbin + sep + '11010001'}
if (let ==  "�") {letbin = letbin + sep + '11010010'}
if (let ==  "�") {letbin = letbin + sep + '11010011'}
if (let ==  "�") {letbin = letbin + sep + '11010100'}
if (let ==  "�") {letbin = letbin + sep + '11010101'}
if (let ==  "Ö") {letbin = letbin + sep + '11010110'}
if (let ==  "�") {letbin = letbin + sep + '11010111'}
if (let ==  "Ø") {letbin = letbin + sep + '11011000'}
if (let ==  "�") {letbin = letbin + sep + '11011001'}
if (let ==  "�") {letbin = letbin + sep + '11011010'}
if (let ==  "�") {letbin = letbin + sep + '11011011'}
if (let ==  "Ü") {letbin = letbin + sep + '11011100'}
if (let ==  "�") {letbin = letbin + sep + '11011101'}
if (let ==  "�") {letbin = letbin + sep + '11011110'}
if (let ==  "ß") {letbin = letbin + sep + '11011111'}
if (let ==  "à") {letbin = letbin + sep + '11100000'}
if (let ==  "á") {letbin = letbin + sep + '11100001'}
if (let ==  "â") {letbin = letbin + sep + '11100010'}
if (let ==  "�") {letbin = letbin + sep + '11100011'}
if (let ==  "ä") {letbin = letbin + sep + '11100100'}
if (let ==  "å") {letbin = letbin + sep + '11100101'}
if (let ==  "æ") {letbin = letbin + sep + '11100110'}
if (let ==  "ç") {letbin = letbin + sep + '11100111'}
if (let ==  "è") {letbin = letbin + sep + '11101000'}
if (let ==  "é") {letbin = letbin + sep + '11101001'}
if (let ==  "ê") {letbin = letbin + sep + '11101010'}
if (let ==  "ë") {letbin = letbin + sep + '11101011'}
if (let ==  "ì") {letbin = letbin + sep + '11101100'}
if (let ==  "í") {letbin = letbin + sep + '11101101'}
if (let ==  "î") {letbin = letbin + sep + '11101110'}
if (let ==  "�") {letbin = letbin + sep + '11101111'}
if (let ==  "�") {letbin = letbin + sep + '11110000'}
if (let ==  "ñ") {letbin = letbin + sep + '11110001'}
if (let ==  "ò") {letbin = letbin + sep + '11110010'}
if (let ==  "ó") {letbin = letbin + sep + '11110011'}
if (let ==  "ô") {letbin = letbin + sep + '11110100'}
if (let ==  "�") {letbin = letbin + sep + '11110101'}
if (let ==  "ö") {letbin = letbin + sep + '11110110'}
if (let ==  "�") {letbin = letbin + sep + '11110111'}
if (let ==  "ø") {letbin = letbin + sep + '11111000'}
if (let ==  "ù") {letbin = letbin + sep + '11111001'}
if (let ==  "ú") {letbin = letbin + sep + '11111010'}
if (let ==  "û") {letbin = letbin + sep + '11111011'}
if (let ==  "û") {letbin = letbin + sep + '11111100'}
if (let ==  "�") {letbin = letbin + sep + '11111101'}
if (let ==  "�") {letbin = letbin + sep + '11111110'}
if (let ==  "�") {letbin = letbin + sep + '11111111'}

}
document.asc2bin.binary.value = letbin
return false;
}

function doasc(text) {

if (text.length % 8 != 0) {
  alert (text + " is not an even binary.\n\nYou may have missed a digit or maybe added an additional digit/character.\n\nSeparaters are NOT required here.")
  return false;
  last;
}
var letasc = ""
lettot = text.length / 8
j=0
for (i=0; i<lettot;i++) {

let = text.substr(j,8);



if (let ==  "01000001") {letasc = letasc + 'A'}
if (let ==  "01000010") {letasc = letasc + 'B'}
if (let ==  "01000011") {letasc = letasc + 'C'}
if (let ==  "01000100") {letasc = letasc + 'D'}
if (let ==  "01000101") {letasc = letasc + 'E'}
if (let ==  "01000110") {letasc = letasc + 'F'}
if (let ==  "01000111") {letasc = letasc + 'G'}
if (let ==  "01001000") {letasc = letasc + 'H'}
if (let ==  "01001001") {letasc = letasc + 'I'}
if (let ==  "01001010") {letasc = letasc + 'J'}
if (let ==  "01001011") {letasc = letasc + 'K'}
if (let ==  "01001100") {letasc = letasc + 'L'}
if (let ==  "01001101") {letasc = letasc + 'M'}
if (let ==  "01001110") {letasc = letasc + 'N'}
if (let ==  "01001111") {letasc = letasc + 'O'}
if (let ==  "01010000") {letasc = letasc + 'P'}
if (let ==  "01010001") {letasc = letasc + 'Q'}
if (let ==  "01010010") {letasc = letasc + 'R'}
if (let ==  "01010011") {letasc = letasc + 'S'}
if (let ==  "01010100") {letasc = letasc + 'T'}
if (let ==  "01010101") {letasc = letasc + 'U'}
if (let ==  "01010110") {letasc = letasc + 'V'}
if (let ==  "01010111") {letasc = letasc + 'W'}
if (let ==  "01011000") {letasc = letasc + 'X'}
if (let ==  "01011001") {letasc = letasc + 'Y'}
if (let ==  "01011010") {letasc = letasc + 'Z'}
if (let ==  "01100001") {letasc = letasc + 'a'}
if (let ==  "01100010") {letasc = letasc + 'b'}
if (let ==  "01100011") {letasc = letasc + 'c'}
if (let ==  "01100100") {letasc = letasc + 'd'}
if (let ==  "01100101") {letasc = letasc + 'e'}
if (let ==  "01100110") {letasc = letasc + 'f'}
if (let ==  "01100111") {letasc = letasc + 'g'}
if (let ==  "01101000") {letasc = letasc + 'h'}
if (let ==  "01101001") {letasc = letasc + 'i'}
if (let ==  "01101010") {letasc = letasc + 'j'}
if (let ==  "01101011") {letasc = letasc + 'k'}
if (let ==  "01101100") {letasc = letasc + 'l'}
if (let ==  "01101101") {letasc = letasc + 'm'}
if (let ==  "01101110") {letasc = letasc + 'n'}
if (let ==  "01101111") {letasc = letasc + 'o'}
if (let ==  "01110000") {letasc = letasc + 'p'}
if (let ==  "01110001") {letasc = letasc + 'q'}
if (let ==  "01110010") {letasc = letasc + 'r'}
if (let ==  "01110011") {letasc = letasc + 's'}
if (let ==  "01110100") {letasc = letasc + 't'}
if (let ==  "01110101") {letasc = letasc + 'u'}
if (let ==  "01110110") {letasc = letasc + 'v'}
if (let ==  "01110111") {letasc = letasc + 'w'}
if (let ==  "01111000") {letasc = letasc + 'x'}
if (let ==  "01111001") {letasc = letasc + 'y'}
if (let ==  "01111010") {letasc = letasc + 'z'}
if (let ==  "00100000") {letasc = letasc + ' '}

//Numbers:
if (let ==  "00110000") {letasc = letasc + '0'}
if (let ==  "00110001") {letasc = letasc + '1'}
if (let ==  "00110010") {letasc = letasc + '2'}
if (let ==  "00110011") {letasc = letasc + '3'}
if (let ==  "00110100") {letasc = letasc + '4'}
if (let ==  "00110101") {letasc = letasc + '5'}
if (let ==  "00110110") {letasc = letasc + '6'}
if (let ==  "00110111") {letasc = letasc + '7'}
if (let ==  "00111000") {letasc = letasc + '8'}
if (let ==  "00111001") {letasc = letasc + '9'}

//Special Characters:
if (let ==  "00100001") {letasc = letasc + '!'}
if (let ==  "00100010") {letasc = letasc + '\"'}
if (let ==  "00100011") {letasc = letasc + '#'}
if (let ==  "00100100") {letasc = letasc + '$'}
if (let ==  "00100101") {letasc = letasc + '%'}
if (let ==  "00100110") {letasc = letasc + '&'}
if (let ==  "00100111") {letasc = letasc + '\''}
if (let ==  "00101000") {letasc = letasc + '('}
if (let ==  "00101001") {letasc = letasc + ')'}
if (let ==  "00101001") {letasc = letasc + '*'}
if (let ==  "00101011") {letasc = letasc + '+'}
if (let ==  "00101100") {letasc = letasc + ','}
if (let ==  "00101101") {letasc = letasc + '-'}
if (let ==  "00101110") {letasc = letasc + '.'}
if (let ==  "00101111") {letasc = letasc + '/'}
if (let ==  "00111010") {letasc = letasc + ':'}
if (let ==  "00111011") {letasc = letasc + ';'}
if (let ==  "00111100") {letasc = letasc + '<'}
if (let ==  "00111101") {letasc = letasc + '='}
if (let ==  "00111110") {letasc = letasc + '>'}
if (let ==  "00111111") {letasc = letasc + '?'}
if (let ==  "01000000") {letasc = letasc + '@'}
if (let ==  "01011011") {letasc = letasc + '['}
if (let ==  "01011100") {letasc = letasc + '\\'}
if (let ==  "01011101") {letasc = letasc + ']'}
if (let ==  "01011110") {letasc = letasc + '^'}
if (let ==  "01011111") {letasc = letasc + '_'}
if (let ==  "01100000") {letasc = letasc + '`'}
if (let ==  "01111011") {letasc = letasc + '{'}
if (let ==  "01111100") {letasc = letasc + '|'}
if (let ==  "01111101") {letasc = letasc + '}'}
if (let ==  "01111110") {letasc = letasc + '~'}
if (let ==  "10000000") {letasc = letasc + '�'}
if (let ==  "10100001") {letasc = letasc + '¡'}
if (let ==  "10100010") {letasc = letasc + '¢'}
if (let ==  "10100011") {letasc = letasc + '£'}
if (let ==  "10100100") {letasc = letasc + '�'}
if (let ==  "10100101") {letasc = letasc + '�'}
if (let ==  "10100110") {letasc = letasc + '�'}
if (let ==  "10100111") {letasc = letasc + '§'}
if (let ==  "10100111") {letasc = letasc + '�'}
if (let ==  "10101001") {letasc = letasc + '�'}
if (let ==  "10101010") {letasc = letasc + '�'}
if (let ==  "10101011") {letasc = letasc + '«'}
if (let ==  "10101100") {letasc = letasc + '�'}
if (let ==  "10101101") {letasc = letasc + '�'}
if (let ==  "10101110") {letasc = letasc + '�'}
if (let ==  "10101111") {letasc = letasc + '�'}
if (let ==  "10110000") {letasc = letasc + '�'}
if (let ==  "10110001") {letasc = letasc + '�'}
if (let ==  "10110010") {letasc = letasc + '�'}
if (let ==  "10110011") {letasc = letasc + '�'}
if (let ==  "10110100") {letasc = letasc + '�'}
if (let ==  "10110101") {letasc = letasc + '�'}
if (let ==  "10110110") {letasc = letasc + '�'}
if (let ==  "10110111") {letasc = letasc + '�'}
if (let ==  "10111000") {letasc = letasc + '�'}
if (let ==  "10111001") {letasc = letasc + '�'}
if (let ==  "10111010") {letasc = letasc + '�'}
if (let ==  "10111011") {letasc = letasc + '»'}
if (let ==  "10111100") {letasc = letasc + '�'}
if (let ==  "10111101") {letasc = letasc + '�'}
if (let ==  "10111110") {letasc = letasc + '�'}
if (let ==  "10111111") {letasc = letasc + '�'}
if (let ==  "11000000") {letasc = letasc + '�'}
if (let ==  "11000001") {letasc = letasc + '�'}
if (let ==  "11000010") {letasc = letasc + '�'}
if (let ==  "11000011") {letasc = letasc + '�'}
if (let ==  "11000100") {letasc = letasc + 'Ä'}
if (let ==  "11000101") {letasc = letasc + 'Å'}
if (let ==  "11000110") {letasc = letasc + 'Æ'}
if (let ==  "11000111") {letasc = letasc + 'Ç'}
if (let ==  "11001000") {letasc = letasc + '�'}
if (let ==  "11001001") {letasc = letasc + '�'}
if (let ==  "11001010") {letasc = letasc + '�'}
if (let ==  "11001011") {letasc = letasc + 'Ë'}
if (let ==  "11001100") {letasc = letasc + '�'}
if (let ==  "11001101") {letasc = letasc + '�'}
if (let ==  "11001110") {letasc = letasc + '�'}
if (let ==  "11001111") {letasc = letasc + '�'}
if (let ==  "11010000") {letasc = letasc + '�'}
if (let ==  "11010001") {letasc = letasc + '�'}
if (let ==  "11010010") {letasc = letasc + '�'}
if (let ==  "11010011") {letasc = letasc + '�'}
if (let ==  "11010100") {letasc = letasc + '�'}
if (let ==  "11010101") {letasc = letasc + '�'}
if (let ==  "11010110") {letasc = letasc + 'Ö'}
if (let ==  "11010111") {letasc = letasc + '�'}
if (let ==  "11011000") {letasc = letasc + 'Ø'}
if (let ==  "11011001") {letasc = letasc + '�'}
if (let ==  "11011010") {letasc = letasc + '�'}
if (let ==  "11011011") {letasc = letasc + '�'}
if (let ==  "11011100") {letasc = letasc + 'Ü'}
if (let ==  "11011101") {letasc = letasc + '�'}
if (let ==  "11011110") {letasc = letasc + '�'}
if (let ==  "11011111") {letasc = letasc + 'ß'}
if (let ==  "11100000") {letasc = letasc + 'à'}
if (let ==  "11100001") {letasc = letasc + 'á'}
if (let ==  "11100010") {letasc = letasc + 'â'}
if (let ==  "11100011") {letasc = letasc + '�'}
if (let ==  "11100100") {letasc = letasc + 'ä'}
if (let ==  "11100101") {letasc = letasc + 'å'}
if (let ==  "11100110") {letasc = letasc + 'æ'}
if (let ==  "11100111") {letasc = letasc + 'ç'}
if (let ==  "11101000") {letasc = letasc + 'è'}
if (let ==  "11101001") {letasc = letasc + 'é'}
if (let ==  "11101010") {letasc = letasc + 'ê'}
if (let ==  "11101011") {letasc = letasc + 'ë'}
if (let ==  "11101100") {letasc = letasc + 'ì'}
if (let ==  "11101101") {letasc = letasc + 'í'}
if (let ==  "11101110") {letasc = letasc + 'î'}
if (let ==  "11101111") {letasc = letasc + '�'}
if (let ==  "11110000") {letasc = letasc + '�'}
if (let ==  "11110001") {letasc = letasc + 'ñ'}
if (let ==  "11110010") {letasc = letasc + 'ò'}
if (let ==  "11110011") {letasc = letasc + 'ó'}
if (let ==  "11110100") {letasc = letasc + 'ô'}
if (let ==  "11110101") {letasc = letasc + '�'}
if (let ==  "11110110") {letasc = letasc + 'ö'}
if (let ==  "11110111") {letasc = letasc + '�'}
if (let ==  "11111000") {letasc = letasc + 'ø'}
if (let ==  "11111001") {letasc = letasc + 'ù'}
if (let ==  "11111010") {letasc = letasc + 'ú'}
if (let ==  "11111011") {letasc = letasc + 'û'}
if (let ==  "11111100") {letasc = letasc + 'û'}
if (let ==  "11111101") {letasc = letasc + '�'}
if (let ==  "11111110") {letasc = letasc + '�'}
if (let ==  "11111111") {letasc = letasc + '�'}
if (letasc == "") {
  alert ("not found")
  break;
}
j=j+8
}
document.bin2asc.ascii.value = letasc
return false;
}
    </script>
    <form name="asc2bin">
      <strong>Convert to Binary</strong><br>
      Enter Text: <input type="Text" name="text" size="92"><br>
      <input type="hidden" name="separater" maxlength="1" size="1">
      <input type="button" value="Convert" onclick="dobin(document.asc2bin.text.value,document.asc2bin.separater.value);">
      <br><br>
      Binary Output: <input type="Text" name="binary" size="90">
    </form>
    <br><br>
    <form name="bin2asc">
      <strong>Convert to Ascii</strong><br>
      Enter Binary: <input type="Text" name="text" size="90"><br>
      <input type="button" value="Convert" onclick="doasc(document.bin2asc.text.value);">
      <br><br>
      ASCII Output: <input type="Text" name="ascii" size="90">
    </form>
    <br><br>
  </body>
</html>
         
Posted by 1010
반응형
<html>
  <head>
    <!--
      CryptoMX Tools
      Copyright (C) 2004 - 2006 Derek Buitenhuis

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation; either version 2
      of the License, or (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    -->
    <title>Base64 Encoding/Decoding</title>
  </head>
  <body>
   <script type="text/javascript"><!--

   var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

   function encode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      do {
         chr1 = input.charCodeAt(i++);
         chr2 = input.charCodeAt(i++);
         chr3 = input.charCodeAt(i++);

         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;

         if (isNaN(chr2)) {
            enc3 = enc4 = 64;
         } else if (isNaN(chr3)) {
            enc4 = 64;
         }

         output = output +
            keyStr.charAt(enc1) +
            keyStr.charAt(enc2) +
            keyStr.charAt(enc3) +
            keyStr.charAt(enc4);
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
      } while (i < input.length);

      return output;
   }

   function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
      if (base64test.exec(input)) {
         alert("There were invalid base64 characters in the input text.\n" +
               "Valid base64 characters are A-Z, a-z, 0-9, �+�, �/�, and �=�\n" +
               "Expect errors in decoding.");
      }
      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
   }

   //--></script>
    <form name="base64Form">
      <center>
        Type in the message you want to encode in Base64, or paste<br>
        Base64 encoded text into the text field, select Encode or Decode, <br>
        and click the button! You can use Base64 encoded messages with<br>
        the <a href="stegano.html">Steganography</a> page.<br>
        <br>
        <textarea name="theText" cols="40" rows="6"></textarea><br>
        <input type="button" name="encode" value="Encode to base64"
          onClick="document.base64Form.theText.value=encode64(document.base64Form.theText.value);">
        <input type="button" name="decode" value="Decode from base64"
          onClick="document.base64Form.theText.value=decode64(document.base64Form.theText.value);">
      <center>
    </form>
  </body>
</html>
           

Posted by 1010
반응형
<HTML>
<HEAD>
<TITLE>TextRange.compareEndPoints() Method</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var fixedRange
function setAndShowRangeData() {
    var selectedRange = document.selection.createRange()
    var result1 = fixedRange.compareEndPoints("StartToEnd", selectedRange)
    var result2 = fixedRange.compareEndPoints("StartToStart", selectedRange)
    var result3 = fixedRange.compareEndPoints("EndToStart", selectedRange)
    var result4 = fixedRange.compareEndPoints("EndToEnd", selectedRange)
   
    B1.innerText = result1
    compare1.innerText = getDescription(result1)
    B2.innerText = result2
    compare2.innerText = getDescription(result2)
    B3.innerText = result3
    compare3.innerText = getDescription(result3)
    B4.innerText = result4
    compare4.innerText = getDescription(result4)
}
function getDescription(comparisonValue) {
    switch (comparisonValue) {
        case -1 :
            return "comes before"
            break
        case 0 :
            return "is the same as"
            break
        case 1 :
            return "comes after"
            break
        default :
            return "vs."    
    }
}
function init() {
    fixedRange = document.body.createTextRange()
    fixedRange.moveToElementText(fixedRangeElem)
}
</SCRIPT>
</HEAD>
<BODY onLoad="init()">
<H1>TextRange.compareEndPoints() Method</H1>
<HR>
<P>Select text in the paragraph in various places relative to
the fixed text range (shown in red).</P>
<TABLE ID="results" BORDER=1 >
<TR><TH>Property</TH><TH>Returned Value</TH><TH>Fixed Range vs. Selection</TR>
<TR>
    <TD CLASS="propName">StartToEnd</TD>
    <TD CLASS="count" ID="B1">&nbsp;</TD>
    <TD CLASS="count" ID="C1">Start of Fixed
    <SPAN ID="compare1">vs.</SPAN> End of Selection</TD>
</TR>
<TR>
    <TD CLASS="propName">StartToStart</TD>
    <TD CLASS="count" ID="B2">&nbsp;</TD>

<TD CLASS="count" ID="C2">Start of Fixed
    <SPAN ID="compare2">vs.</SPAN> Start of Selection</TD>
</TR>
<TR>
    <TD CLASS="propName">EndToStart</TD>
    <TD CLASS="count" ID="B3">&nbsp;</TD>
    <TD CLASS="count" ID="C3">End of Fixed
    <SPAN ID="compare3">vs.</SPAN> Start of Selection</TD>
</TR>
<TR>
    <TD CLASS="propName">EndToEnd</TD>
    <TD CLASS="count" ID="B4">&nbsp;</TD>
    <TD CLASS="count" ID="C4">End of Fixed
    <SPAN ID="compare4">vs.</SPAN> End of Selection</TD>
</TR>
</TABLE>
<HR>
<P onMouseUp="setAndShowRangeData()">
Text, Text,Text,Text,Text,Text,Text,Text,Text,Text,<SPAN ID="fixedRangeElem">
Text,Text,Text,Text,Text,Text,Text,Text,</SPAN>,
Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,Text,</P>
</BODY>
</HTML>

Posted by 1010
반응형
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
-->
<html>
<head>
<title>Recipe 14.7</title>
<link rel="stylesheet" id="mainStyle" href="../css/cookbook.css" type="text/css" />
<style type="text/css">
table {table-collapse:collapse; border-spacing:0}
td {border:2px groove black; padding:7px; background-color:#ccffcc}
th {border:2px groove black; padding:7px; background-color:#ffffcc}
.ctr {text-align:center}
</style>
<script type="text/javascript">
// Table data -- an array of objects
var jsData = new Array();
jsData[0] = {location:"Uruguay", year:1930, winner:"Uruguay", winScore:4,
             loser:"Argentina", losScore:2};
jsData[1] = {location:"Italy", year:1934, winner:"Italy", winScore:2,
             loser:"Czechoslovakia", losScore:1};
jsData[2] = {location:"France", year:1938, winner:"Italy", winScore:4,
             loser:"Hungary", losScore:2};
jsData[3] = {location:"Brazil", year:1950, winner:"Uruguay", winScore:2,
             loser:"Brazil", losScore:1};
jsData[4] = {location:"Switzerland", year:1954, winner:"West Germany", winScore:3,
             loser:"Hungary", losScore:2};

// Draw table from 'jsData' array of objects
function drawTable(tbody) {
    var tr, td;
    tbody = document.getElementById(tbody);
    // loop through data source
    for (var i = 0; i < jsData.length; i++) {
        tr = tbody.insertRow(tbody.rows.length);
        td = tr.insertCell(tr.cells.length);
        td.setAttribute("align", "center");
        td.innerHTML = jsData[i].year;
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = jsData[i].location;
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = jsData[i].winner;
        td = tr.insertCell(tr.cells.length);
        td.innerHTML = jsData[i].loser;
        td = tr.insertCell(tr.cells.length);
        td.setAttribute("align", "center");
        td.innerHTML = jsData[i].winScore + " - " + jsData[i].losScore;
    }
}

</script>
</head>
<body onload="drawTable('matchData')">
<h1>Transforming JavaScript Data into HTML Tables</h1>
<hr />

<table id="cupFinals">
<thead>
<tr><th>Year</th>
    <th>Host Country</th>
    <th>Winner</th>
    <th>Loser</th>
    <th>Score (Win - Lose)</th>
</tr>
</thead>
<tbody id="matchData"></tbody>
</table>

</body>
</html>



Posted by 1010
반응형
<head>
<title></title>
</script>
</head>
<body>
<div id="thetable"></div>
<script type = "text/javascript" >
var table = document.createElement("table");
table.border = "1";
var tbody = document.createElement("tbody");

table.appendChild(tbody);
var row = document.createElement("tr");

for (i = 1; i < 3; i++) {
    var row = document.createElement("tr");
    for (j = 1; j < 3; j++) {
        var td = document.createElement("td");
        var data = document.createTextNode("Row " + i + ", Column " + j);
        td.appendChild(data);
        row.appendChild(td);
    }
    tbody.appendChild(row);
}
document.getElementById("thetable").appendChild(table);
</script>
</body>

Posted by 1010
반응형

/*
JavaScript Bible, Fourth Edition
by Danny Goodman

John Wiley & Sons CopyRight 2001
*/

<HTML>
<HEAD>
<TITLE>Modifying Table Cell Content</TITLE>
<STYLE TYPE="text/css">
.absoluteWrap {position:absolute}
.relativeWrap {position:relative}
.total {color:red}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
var Ver4 = parseInt(navigator.appVersion) == 4
var Ver4Up = parseInt(navigator.appVersion) >= 4
var Nav4 = ((navigator.appName == "Netscape") && Ver4)
var modifiable
// calculate and display a row's total
function showTotal(qtyList) {
    var qty = qtyList.options[qtyList.selectedIndex].value
    var prodID = qtyList.name
    var total = "US$" +
        (qty * parseFloat(qtyList.form.elements[prodID + "Price"].value))
    var newCellHTML = "<SPAN CLASS='total'>" + total + "</SPAN>"
    if(Nav4) {
        document.layers[prodID + "TotalWrapper"].document.layers[prodID + 
            "Total"].document.write(newCellHTML)
        document.layers[prodID + "TotalWrapper"].document.layers[prodID + 
            "Total"].document.close()
    } else if (modifiable) {
        if (document.all) {
            document.all(prodID + "Total").innerHTML = newCellHTML
        } else {
            document.getElementById(prodID + "Total").innerHTML = newCellHTML
        }
    }
}
// initialize global flag for browsers capable of modifiable content
function init() {
    modifiable  = (Ver4Up && document.body && document.body.innerHTML)
}
// display content for all products (e.g., in case of Back navigation)
function showAllTotals(form) {
    for (var i = 0; i < form.elements.length; i++) {
        if (form.elements[i].type == "select-one") {       
            showTotal(form.elements[i])
        }        
    }
}
</SCRIPT>
</HEAD>
<BODY onLoad="init(); showAllTotals(document.orderForm)">
<H1>Modifying Table Cell Content</H1>
<HR>
<FORM NAME="orderForm">
<TABLE BORDER=1>
<COLGROUP WIDTH=150>
<COLGROUP WIDTH=100>
<COLGROUP WIDTH=50>
<COLGROUP WIDTH=100
<TR>
    <TH>Product Description</TH>
    <TH>Price Each</TH>
    <TH>Quantity</TH>
    <TH>Total</TH>
</TR>
<TR>
    <TD>Wonder Widget 9000</TD>
    <TD>US$125.00</TD>
    <TD><SELECT NAME="ww9000" onChange="showTotal(this)">
        <OPTION VALUE="0">0
        <OPTION VALUE="1">1
        <OPTION VALUE="2">2
        <OPTION VALUE="3">3
        </SELECT>
        <INPUT TYPE="hidden" NAME="ww9000Price" VALUE="125.00"></TD>
    <TD>
    <SCRIPT LANGUAGE="JavaScript">
    if (Nav4) {

var placeHolder = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
        placeHolder += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
        document.write("<SPAN ID='ww9000TotalWrapper' CLASS='relativeWrap'>")
        document.write("<SPAN ID='ww9000Total' CLASS='absoluteWrap'></SPAN>")
        document.write("<SPAN>" + placeHolder + "</SPAN></SPAN>")
    } else {
        document.write("<SPAN ID='ww9000Total' CLASS='relativeWrap'>" +
          "<P>&nbsp;</P></SPAN>")
    }
    </SCRIPT>
    </TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>


Posted by 1010
반응형
<html>
<head>
<script type="text/javascript">
function deleteRow(i){
    document.getElementById('myTable').deleteRow(i)
}
</script>
</head>

<body>
<table id="myTable" border="1">
<tr>
  <td>Row 1</td>
  <td><input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)"></td>
</tr>
<tr>
  <td>Row 2</td>
  <td><input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)"></td>
</tr>
<tr>
  <td>Row 3</td>
  <td><input type="button" value="Delete" onclick="deleteRow(this.parentNode.parentNode.rowIndex)"></td>
</tr>
</table>
</body>

</html>
Posted by 1010
반응형
<html>
<head>
<script type="text/javascript">
function aboveFrames(){
    document.getElementById('myTable').frame="above"
}
function belowFrames(){
    document.getElementById('myTable').frame="below"
}
</script>
</head>

<body>
<table id="myTable">
    <tr>
        <td>a</td>
        <td>b</td>
    </tr>
    <tr>
        <td>c</td>
        <td>d</td>
    </tr>
</table>
<form>
    <input type="button" onclick="aboveFrames()" value="Show above frames">
    <input type="button" onclick="belowFrames()" value="Show below frames">
</form>
</body>
</html>

Posted by 1010
반응형
<HTML>
<HEAD>
<TITLE>Using Properties</TITLE></HEAD>
<BODY>
<H1>Using Properties</H1>
<FORM>
<P><INPUT TYPE="BUTTON" NAME="red" VALUE="Red"
 ONCLICK='document.bgColor="red"'></P>
<P><INPUT TYPE="BUTTON" NAME="white" VALUE="White"
 ONCLICK='document.bgColor="white"'></P>
<P><INPUT TYPE="BUTTON" NAME="blue" VALUE="Blue"
 ONCLICK='document.bgColor="blue"'></P>
</FORM>
</BODY>
</HTML>

Posted by 1010
반응형
<html>
<body>
<button onclick="this.disabled='true'; alert(this.isDisabled);">Disable Me</button>
</body>
</html>

   
Posted by 1010
반응형


/*--

 Copyright (C) 2001 Brett McLaughlin.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions, and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions, and the disclaimer that follows
    these conditions in the documentation and/or other materials
    provided with the distribution.

 3. The name "Java and XML" must not be used to endorse or promote products
    derived from this software without prior written permission.  For
    written permission, please contact brett@newInstance.com.
 
 In addition, we request (but do not require) that you include in the
 end-user documentation provided with the redistribution and/or in the
 software itself an acknowledgement equivalent to the following:
     "This product includes software developed for the
      'Java and XML' book, by Brett McLaughlin (O'Reilly & Associates)."

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 */
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.jdom.Attribute;
import org.jdom.Comment;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import org.jdom.output.XMLOutputter;

/**
 * <b><code>PropsToXML</code></b> takes a standard Java properties
 *   file, and converts it into an XML format. This makes properties
 *   like <code>enhydra.classpath.separator</code> "groupbable" by
 *   "enhydra", "classpath", and by the key name, "separator", which
 *   the standard Java <code>java.util.Properties</code> class does
 *   not allow.
 */
public class PropsToXML {
   
    /**
     * <p> This will take the supplied properties file, and
     *   convert that file to an XML representation, which is
     *   then output to the supplied XML document filename. </p>
     *
     * @param propertiesFilename file to read in as Java properties.
     * @param xmlFilename file to output XML representation to.
     * @throws <code>IOException</code> - when errors occur.
     */
    public void convert(String propertiesFilename, String xmlFilename)
        throws IOException {
           
        // Get Java Properties object
        FileInputStream input = new FileInputStream(propertiesFilename);
        Properties props = new Properties();
        props.load(input);
       
        // Convert to XML
        convertToXML(props, xmlFilename);
    }        
   
    /**
     * <p> This will handle the detail of conversion from a Java
     *  <code>Properties</code> object to an XML document. </p>
     *
     * @param props <code>Properties</code> object to use as input.
     * @param xmlFilename file to output XML to.
     * @throws <code>IOException</code> - when errors occur.
     */
    private void convertToXML(Properties props, String xmlFilename)
        throws IOException {
   
        // Create a new JDOM Document with a root element "properties"
        Element root = new Element("properties");
        Document doc = new Document(root);
       
        // Get the property names
        Enumeration propertyNames = props.propertyNames();
        while (propertyNames.hasMoreElements()) {
            String propertyName = (String)propertyNames.nextElement();
            String propertyValue = props.getProperty(propertyName);
            createXMLRepresentation(root, propertyName, propertyValue);
        }        
       
        // Output document to supplied filename
        XMLOutputter outputter = new XMLOutputter("  ", true);
        FileOutputStream output = new FileOutputStream(xmlFilename);
        outputter.output(doc, output);
    }
   
    /**
     * <p> This will convert a single property and its value to
     *  an XML element and textual value. </p>
     *
     * @param root JDOM root <code>Element</code> to add children to.
     * @param propertyName name to base element creation on.
     * @param propertyValue value to use for property.
     */
    private void createXMLRepresentation(Element root,
                                         String propertyName,
                                         String propertyValue) {
       
        /*          
        Element element = new Element(propertyName);
        element.setText(propertyValue);
        root.addContent(element);
        */
       
        int split;
        String name = propertyName;
        Element current = root;
        Element test = null;
             
        while ((split = name.indexOf(".")) != -1) {
            String subName = name.substring(0, split);
            name = name.substring(split+1);
           
            // Check for existing element            
            if ((test = current.getChild(subName)) == null) {
                Element subElement = new Element(subName);
                current.addContent(subElement);
                current = subElement;
            } else {
                current = test;
            }
        }
       
        // When out of loop, what's left is the final element's name        
        Element last = new Element(name);                        
        // last.setText(propertyValue);
        last.setAttribute("value", propertyValue);
        current.addContent(last);
    }
                                       
    /**
     * <p> Provide a static entry point for running. </p>
     */
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Usage: java PropsToXML " +
                "[properties file] [XML file for output]");
            System.exit(0);
        }
       
        try {
            PropsToXML propsToXML = new PropsToXML();
            propsToXML.convert(args[0], args[1]);
        } catch (Exception e) {
            e.printStackTrace();
        }        
    }
}
/*--

 Copyright (C) 2001 Brett McLaughlin.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions, and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions, and the disclaimer that follows
    these conditions in the documentation and/or other materials
    provided with the distribution.

 3. The name "Java and XML" must not be used to endorse or promote products
    derived from this software without prior written permission.  For
    written permission, please contact brett@newInstance.com.
 
 In addition, we request (but do not require) that you include in the
 end-user documentation provided with the redistribution and/or in the
 software itself an acknowledgement equivalent to the following:
     "This product includes software developed for the
      'Java and XML' book, by Brett McLaughlin (O'Reilly & Associates)."

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 */

/**
 * <b><code>XMLProperties</code></b> extends Java's
 *  <code>java.util.Properties</code> class, and provides
 *  behavior similar to properties but that use XML as the
 *  input and output format.
 */
class XMLProperties extends Properties {
   
    /**
     * <p> This overrides the default <code>load()</code>
     *   behavior to read from an XML document. </p>
     *
     * @param reader the reader to read XML from
     * @throws <code>IOException</code> - when errors occur reading.
     */
    public void load(Reader reader)
        throws IOException {
       
        try {
            // Load XML into JDOM Document
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(reader);
           
            // Turn into properties objects
            loadFromElements(doc.getRootElement().getChildren(),
                new StringBuffer(""));
           
        } catch (JDOMException e) {
            throw new IOException(e.getMessage());
        }        
    }    

    /**
     * <p> This overrides the default <code>load()</code>
     *   behavior to read from an XML document. </p>
     *
     * @param inputStream the input stream
     * @throws <code>IOException</code> - when errors occur reading.
     */
    public void load(InputStream inputStream)
        throws IOException {
         
        load(new InputStreamReader(inputStream));    
    }
   
    /**
     * <p> This overrides the default <code>load()</code>
     *   behavior to read from an XML document. </p>
     *
     * @param xmlDocument the XML document to read
     * @throws <code>IOException</code> - when errors occur reading.
     */
    public void load(File xmlDocument)
        throws IOException {
       
        load(new FileReader(xmlDocument));    
    }  
   
    /**
     * <p>This helper method loads the XML properties from a specific
     *   XML element, or set of elements.</p>
     *
     * @param elements <code>List</code> of elements to load from.
     * @param baseName the base name of this property.
     */
    private void loadFromElements(List elements, StringBuffer baseName) {
        // Iterate through each element
        for (Iterator i = elements.iterator(); i.hasNext(); ) {
            Element current = (Element)i.next();
            String name = current.getName();
            String text = current.getTextTrim();
            // String text = current.getAttributeValue("value");            
           
            // Don't add "." if no baseName
            if (baseName.length() > 0) {
                baseName.append(".");
            }            
            baseName.append(name);
           
            // See if we have an element value
            if ((text == null) || (text.equals(""))) {
                // If no text, recurse on children
                loadFromElements(current.getChildren(),
                                 baseName);
            } else {                
                // If text, this is a property
                setProperty(baseName.toString(),
                            text);
            }            
           
            // On unwind from recursion, remove last name
            if (baseName.length() == name.length()) {
                baseName.setLength(0);
            } else {                
                baseName.setLength(baseName.length() -
                    (name.length() + 1));
            }            
        }        
    }    
   
    /**
     * @deprecated This method does not throw an IOException
     *   if an I/O error occurs while saving the property list.
     *   As of the Java 2 platform v1.2, the preferred way to save
     *   a properties list is via the
     *   <code>{@link store(OutputStream out, String header}</code>
     *   method.
     */
    public void save(OutputStream out, String header) {
        try {            
            store(out, header);
        } catch (IOException ignored) {
            // Deprecated version doesn't pass errors
        }        
    }  
   
    /**
     * <p> This will output the properties in this object
     *   as XML to the supplied output writer. </p>
     *
     * @param writer the writer to output XML to.
     * @param header comment to add at top of file
     * @throws <code>IOException</code> - when writing errors occur.
     */
    public void store(Writer writer, String header)
        throws IOException {
           
        // Create a new JDOM Document with a root element "properties"
        Element root = new Element("properties");
        Document doc = new Document(root);
       
        // Add in header information
        Comment comment = new Comment(header);
        doc.getContent().add(0, comment);
       
        // Get the property names
        Enumeration propertyNames = propertyNames();
        while (propertyNames.hasMoreElements()) {
            String propertyName = (String)propertyNames.nextElement();
            String propertyValue = getProperty(propertyName);
            createXMLRepresentation(root, propertyName, propertyValue);
        }        
       
        // Output document to supplied filename
        XMLOutputter outputter = new XMLOutputter("  ", true);
        outputter.output(doc, writer);
        writer.flush();
    }    
   
    /**
     * <p> This will output the properties in this object
     *   as XML to the supplied output stream. </p>
     *
     * @param out the output stream.
     * @param header comment to add at top of file
     * @throws <code>IOException</code> - when writing errors occur.
     */
    public void store(OutputStream out, String header)
        throws IOException {
           
        store(new OutputStreamWriter(out), header);
    }
   
    /**
     * <p> This will output the properties in this object
     *   as XML to the supplied output file. </p>
     *
     * @param xmlDocument XML file to output to.
     * @param header comment to add at top of file
     * @throws <code>IOException</code> - when writing errors occur.
     */
    public void store(File xmlDocument, String header)
        throws IOException {
           
        store(new FileWriter(xmlDocument), header);
    }    
   
    /**
     * <p> This will convert a single property and its value to
     *  an XML element and textual value. </p>
     *
     * @param root JDOM root <code>Element</code> to add children to.
     * @param propertyName name to base element creation on.
     * @param propertyValue value to use for property.
     */
    private void createXMLRepresentation(Element root,
                                         String propertyName,
                                         String propertyValue) {
       
        int split;
        String name = propertyName;
        Element current = root;
        Element test = null;
             
        while ((split = name.indexOf(".")) != -1) {
            String subName = name.substring(0, split);
            name = name.substring(split+1);
           
            // Check for existing element            
            if ((test = current.getChild(subName)) == null) {
                Element subElement = new Element(subName);
                current.addContent(subElement);
                current = subElement;
            } else {
                current = test;
            }
        }
       
        // When out of loop, what's left is the final element's name        
        Element last = new Element(name);                        
        last.setText(propertyValue);
        /** Uncomment this for Attribute usage */
        /*
        last.setAttribute("value", propertyValue);
        */
        current.addContent(last);
    }                
}

/*--

 Copyright (C) 2001 Brett McLaughlin.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions, and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions, and the disclaimer that follows
    these conditions in the documentation and/or other materials
    provided with the distribution.

 3. The name "Java and XML" must not be used to endorse or promote products
    derived from this software without prior written permission.  For
    written permission, please contact brett@newInstance.com.
 
 In addition, we request (but do not require) that you include in the
 end-user documentation provided with the redistribution and/or in the
 software itself an acknowledgement equivalent to the following:
     "This product includes software developed for the
      'Java and XML' book, by Brett McLaughlin (O'Reilly & Associates)."

 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.

 */

/**
 * <b><code>TestXMLProperties</code></b> is a simple class that tests
 *   usage of the <code>{@link XMLProperties}</code> class for reading
 *   XML property files.
 */
class TestXMLProperties {

    /**
     * <p>Provide a static entry point for testing.</p>
     */
    public static void main(String[] args) {
        if (args.length != 2) {
            System.out.println("Usage: java TestXMLProperties " +
                "[XML input document] [XML output document]");
            System.exit(0);
        }
   
        try {
            // Create and load properties
            System.out.println("Reading XML properties from " + args[0]);
            XMLProperties props = new XMLProperties();
            props.load(new FileInputStream(args[0]));
           
            // Print out properties and values
            System.out.println("\n\n---- Property Values ----");
            Enumeration names = props.propertyNames();
            while (names.hasMoreElements()) {
                String name = (String)names.nextElement();
                String value = props.getProperty(name);
                System.out.println("Property Name: " + name + 
                                   " has value " + value);
            }            
           
            // Store properties
            System.out.println("\n\nWriting XML properies to " + args[1]);
            props.store(new FileOutputStream(args[1]),
                "Testing XMLProperties class");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

// Demo file: enhydra.properties

/*

#
# This file has several Enhydra-specific properties
#   to make available to Java programs running with
#   knowledge of this properties file.
#

# sax parser implementing class
org.xml.sax.parser="org.apache.xerces.parsers.SAXParser"

# Class used to start the server
org.enhydra.initialclass=org.enhydra.multiServer.bootstrap.Bootstrap

# initial arguments passed to the server
org.enhydra.initialargs="./bootstrap.conf"

# Classpath for the parent top enhydra classloader
org.enhydra.classpath="."

# separator for the classpath above
org.enhydra.classpath.separator=":"


*/


           

Posted by 1010
반응형
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.util.Properties;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.util.Properties;
import java.util.Enumeration;
import org.apache.xerces.parsers.*;

public class ParseNonXML extends DefaultHandler {

  public static void main(String args[]) throws SAXException {

    PropertyFileParser pfp = new PropertyFileParser();
    pfp.setContentHandler(new ParseNonXML());
    pfp.parse(buildProperties());
  }

  public static Properties buildProperties() {
    Properties props = new Properties();
    for (int i = 0; i < 10; i++)
      props.setProperty("key" + i, "value" + i);
    return props;
  }

  public void startDocument() {
    System.out.println("<keys>");
  }

  public void endDocument() {
    System.out.println("</keys>");
  }

  public void characters(char[] data, int start, int end) {
    String str = new String(data, start, end);
    System.out.print(str);
  }

  public void startElement(String uri, String qName, String lName, Attributes atts) {
    System.out.print("<" + lName + ">");
  }

  public void endElement(String uri, String qName, String lName) {
    System.out.println("</" + lName + ">");
  }
}

class PropertyFileParser extends SAXParser {

  private Properties props = null;

  private ContentHandler handler = null;

  public void parse(Properties props) throws SAXException {
    handler = getContentHandler();
    handler.startDocument();
    Enumeration e = props.propertyNames();
    while (e.hasMoreElements()) {
      String key = (String) e.nextElement();
      String val = (String) props.getProperty(key);
      handler.startElement("", key, key, new AttributesImpl());
      char[] chars = getChars(val);
      handler.characters(chars, 0, chars.length);
      handler.endElement("", key, key);
    }
    handler.endDocument();
  }

  private char[] getChars(String value) {
    char[] chars = new char[value.length()];
    value.getChars(0, value.length(), chars, 0);
    return chars;
  }

}
Posted by 1010
반응형

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class MainClass {

  public static void main(String[] args) {

    try {
      Class.forName("COM.cloudscape.core.JDBCDriver").newInstance();

      Connection conn = DriverManager.getConnection("jdbc:cloudscape:GAMETRADER");

      Statement s = conn.createStatement();

      ResultSet rs = s.executeQuery("SELECT * FROM tableName");

      while (rs.next()) {
        int id = rs.getInt("ID");
        InputStream bis = rs.getAsciiStream("MANUAL");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        int ch = 0;
        while ((ch = bis.read()) != -1)
          bos.write(ch);
        System.out.println("GAMEID: " + id + "\n" + "MANUAL: " + new String(bos.toByteArray()));
      }

    } catch (Throwable e) {
      System.out.println("exception thrown");
      System.out.println(e);
    }
  }
}




Posted by 1010
반응형


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;

public class MainClass {

  public static void main(String[] args) throws Exception{
      Class.forName("COM.cloudscape.core.JDBCDriver").newInstance();

      Connection conn = DriverManager.getConnection("jdbc:cloudscape:GAMETRADER");

      conn.setAutoCommit(false);

      Statement s = conn.createStatement();
      s.executeUpdate("CREATE TABLE MANUALS(GAMEID INT, MANUAL LONG VARCHAR)");
      conn.commit();

      File file = new File("manuals.xml");
      InputStream is = new FileInputStream(file);

      PreparedStatement ps = conn.prepareStatement("INSERT INTO MANUALS VALUES(?,?)");

      ps.setInt(1, 1285757);

      ps.setAsciiStream(2, is, (int) file.length());

      ps.execute();
      conn.commit();
  }
}

Posted by 1010
반응형
import java.sql.*;
import java.io.*;
import org.apache.xerces.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class XMLDBDOM {

  public static void main(String[] args) throws Exception{

      Class.forName("COM.cloudscape.core.JDBCDriver").newInstance();

      Connection conn = DriverManager.getConnection("jdbc:cloudscape:GAMETRADER");

      conn.setAutoCommit(false);

      Statement s = conn.createStatement();
      s.executeUpdate("CREATE TABLE XMLData(GAMEID INT, MANUAL SERIALIZE(org.w3c.dom.Document))");
      conn.commit();

      File file = new File("XMLData.xml");
      InputStream is = new FileInputStream(file);

      PreparedStatement ps = conn.prepareStatement("INSERT INTO XMLData VALUES(?,?)");

      ps.setInt(1, 1285757);

      DOMParser parser = new DOMParser();
      parser.parse("XMLData.xml");
      Document manual = parser.getDocument();
      ps.setObject(2, manual);

      ps.execute();

      conn.commit();
  }
}

Posted by 1010
반응형
//ie8 
var isOldIE = false;
if(Prototype.Browser.IE) {
  if(parseFloat(navigator.appVersion.split("MSIE")[1].split(";")[0].split(" ").join("")) <= 7) {
    isOldIE = true;
  }
}
Posted by 1010
반응형

<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">

 // InternetVersion
 function getInternetVersion(ver) {
  var rv = -1; // Return value assumes failure.     
  var ua = navigator.userAgent; 
  var re = null;
  if(ver == "MSIE"){
   re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  }else{
   re = new RegExp(ver+"/([0-9]{1,}[\.0-9]{0,})");
  }
  if (re.exec(ua) != null){
   rv = parseFloat(RegExp.$1);
  }
  return rv; 
 }
 
 //브라우저 종류 및 버전확인 
 function browserCheck(){
  var ver = 0; // 브라우저  버전정보
  if(navigator.appName.charAt(0) == "N"){
   if(navigator.userAgent.indexOf("Chrome") != -1){
    ver = getInternetVersion("Chrome");
    alert("Chrome"+ver+"입니다.");
   }else if(navigator.userAgent.indexOf("Firefox") != -1){
    ver = getInternetVersion("Firefox");
    alert("Firefox"+ver+"입니다.");
   }else if(navigator.userAgent.indexOf("Safari") != -1){
    ver = getInternetVersion("Safari");
    alert("Safari"+ver+"입니다.");
   }
  }else if(navigator.appName.charAt(0) == "M"){
   ver = getInternetVersion("MSIE");
   alert("MSIE"+ver+"입니다.");
  }
  }
</script>  
</head>
<body>  
 <input type="button" value="브라우저판별" onclick="browserCheck();">  
</body>
</html>

Posted by 1010
반응형
<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">
 function getInternetExplorerVersion() {
  var rv = -1; // Return value assumes failure.  
 
  
  if (navigator.appName == 'Microsoft Internet Explorer') {
   var ua = navigator.userAgent;
   alert(ua); 
   var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
   if (re.exec(ua) != null)
    rv = parseFloat(RegExp.$1);
  }
  return rv;
 }
 function checkVersion() {
  var msg = "You're not using Windows Internet Explorer.";
  var ver = getInternetExplorerVersion();
  if (ver > -1) {
   if (ver >= 8.0)
    msg = "You're using a recent copy of Windows Internet Explorer.";
   else
    msg = "You should upgrade your copy of Windows Internet Explorer.";
  }
  alert(msg);
 }
 function IsIE8Browser() {
  var rv = -1;
  var ua = navigator.userAgent;
  var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");
  if (re.exec(ua) != null) {
   rv = parseFloat(RegExp.$1);
  }
  alert(ua);
  alert(re);
  alert("re.exec(ua) : "+re.exec(ua));
  alert(rv);
  return (rv == 4);
 }
</script>
</head>
<body>
<input type="button" value="브라우저테스트1" onclick="checkVersion();">
<input type="button" value="브라우저테스트2" onclick="IsIE8Browser();">
</body>
</html>
Posted by 1010
반응형
http://www.gscottolson.com/blackbirdjs/



Demos

Output all message types

log.debug( 'this is a debug message' );
log.info( 'this is an info message' );
log.warn( 'this is a warning message' );
log.error( 'this is an error message' );

Click the block to execute the code

Generate test string

log.profile( 'generate test string' );

var testContent = '';
for ( var i = 0; i < 3000; i++ ) {
  testContent += '-';
}

log.profile( 'generate test string' );

Click the block to execute the code

Setup

Adding Blackbird to your page

  1. Download the files and place them on your server or in a local directory on your computer.
  2. Include blackbird.js in your page.
  3. Inlcude blackbird.css in your page.

Your HTML source should look similar to the following code:

<html>
  <head>
    <script type="text/javascript" src="/PATH/TO/blackbird.js"></script>
    <link type="text/css" rel="Stylesheet" href="/PATH/TO/blackbird.css" />
    ...
  </head>
  ...

Browser compatibility

Blackbird is has been smoke-tested on the following browsers:

  • Internet Explorer 6+
  • Firefox 2+
  • Safari 2+
  • Opera 9.5
Usage

Public API

log.toggle()
Hide/show Blackbird
log.move()
Move Blackbird to next fixed positions: top-left, top-right, bottom-left, bottom-right
log.resize()
Expand/contract Blackbird
log.clear()
Clear all contents of Blackbird
log.debug( message )
Add a debug message to Blackbird
message: the string content of the debug message
log.info( message )
Add an info message to Blackbird
message: the string content of the info message
log.warn( message )
Add a warning message to Blackbird
message: the string content of the warn message
log.error( message )
Add an error message to Blackbird
message: the string content of the warn message
log.profile( label )
Start/end a time profiler for Blackbird. If a profiler named string does not exist, create a new profiler. Otherwise, stop the profiler string and display the time elapsed (in ms).
label: the string identifying a specific profile timer

Keyboard controls

Hide/show
F2
Move
Shift + F2
Clear
Alt + Shift + F2

Interface controls

Pressing the Alt key while clicking any message filter control will only show messages of that type. For example, Alt + click debug control to show only debug messages.

Bookmarklets

Drag the following links to your bookmarks toolbar for quick access to Blackbird commands:

Customization

Changing the namespace

The default configuration attaches the public API for Blackbird to the global variable log. It is possible to have conflicts with existing variable declarations, and it is possible to redefine the global variable log in other blocks of JavaScript. If you want to define a different variable for Blackbird, such as blackbird, replace the assignment for NAMESPACE with any other string.

var NAMESPACE = 'log';

can be replaced with:

var NAMESPACE = 'blackbird';

or:

var NAMESPACE = 'myCustomLog';

The global API will be affected by this change. If you choose to replace log with myCustomLog, then log.debug will become myCustomLog.debug.

Capture & cancel logging statements

If you're shipping code with logging statements, you might want to capture and cancel commands intended for Blackbird. The following code will do this:

var log = {
  toggle: function() {},
  move: function() {},
  resize: function() {},
  clear: function() {},
  debug: function() {},
  info: function() {},
  warn: function() {},
  error: function() {},
  profile: function() {}
};
About

Credits

The code (blackbird.js, blackbird.css) and image assets (blackbird_panel.png, blackbird_icons.png) were created by G. Scott Olson.

The concept for Blackbird was sparked by JavaScript Logging, an article by David F. Miller. The first iteration of this project, named jsLogger, was developed for internal use at Orbitz. In the fall of 2007, jsLogger was rewritten from the ground up, given a facelift, and named project Blackbird.

Contributing to the Blackbird Project

Blackbird is an open source project. If you're intereted in contributing, you can start by checking out the project page on Google Code.

Posted by 1010
반응형

-- 문제


<script type="text/javascript">
 function tt(){
  var external_links = document.getElementById('external_links');
  var links = external_links.getElementsByTagName('a');
  for (var i=0;i < links.length;i++) {
      var link = links.item(i);
      link.onclick = function() {
          return confirm('You are going to visit: ' + this.href);
      };
  }
 } 
</script>

<div id="external_links">
 <a href="http://www.naver.com">link</a>
</div>  
<input type="button" name="dddd" onclick="tt();"/>

---
실행조건(1) : 링크를 클릭한다.
실행조건(2) : 버튼을 클릭한 후, 링크를 클릭한다.

결과가 다른 이유는...?

-----------------------------
ex)
window.onload = function() {
  tt();
 };

Posted by 1010
반응형
<script type="text/javascript">
 function array_max( )  
 {    
  var i, max = this[0];    
  for (i = 1; i < this.length; i++)    
  {     
   if (max < this[i])      
   max = this[i];    
  }        
  return max;   
 }   
 Array.prototype.max = array_max;   
 var x = new Array(1, 2, 3, 4, 5, 6);   
 var y = x.max( );
 function tt(){
  alert("y : "+y);
 } 
</script>
<input type="button" onclick="tt();">
Posted by 1010
반응형


출처 : http://jsguide.net/ver2/examples/index.php?mode=view&category=5&qstr=&uid=197&page=1


자바스크립트에서는 2바이트 문자를 한글자로 처리하기 때문에 바이트 단위로 잘라야 하거나 검사할때 문제가 많습니다.
그래서 바이트 단위로 길이를 검사하고 자르는 메소드를 추가해봤습니다.

서핑중에 sms 보내는 폼이 나오면... 혹시나하고 소스를 열어보곤 하는데.. ㅇ_ㅇ(힉..)
80바이트가 넘는지 검사하는걸 상당히 복잡하게 코딩해논게 보이더군요..
코드 나갑니다


<script>
 /**
 * string String::cut(int len)
 * 글자를 앞에서부터 원하는 바이트만큼 잘라 리턴합니다.
 * 한글의 경우 2바이트로 계산하며, 글자 중간에서 잘리지 않습니다.
 */
 String.prototype.cut = function(len) {
  var str = this;
  var l = 0;
  for (var i=0; i<str.length; i++) {
   l += (str.charCodeAt(i) > 128) ? 2 : 1;
   if (l > len) return str.substring(0,i) + "...";
  }
  return str;
 }

 /**
 * bool String::bytes(void)
 * 해당스트링의 바이트단위 길이를 리턴합니다. (기존의 length 속성은 2바이트 문자를 한글자로 간주합니다)
 */
 String.prototype.bytes = function() {
  var str = this;
  var l = 0;
  for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
  return l;
 }

 aaa = "동a해b물c과 백두산이";
 alert(aaa.cut(15));

 // 또는

 bbb = "너무긴내용너무긴내용너무긴내용";

 alert("length: " + bbb.length + "\nbytes(): " + bbb.bytes());

 //응용

 if (bbb.bytes() > 20) {
  alert("내용이 너무 깁니다");
 } else {
  // 처리
 }
/* 여기서부터는 실행되지는 않습니다 ---

 // 다시응용 (sms폼에서 80바이트 넘는지 처리할경우)

 var sms = document.forms['폼이름'].elements['입력창'];
 if (sms.value.bytes() > 80) {
  alert('80바이트까지만 전송할 수 있습니다');
  sms.value = sms.value.cut(80);
 }
여기까지 실행되지 않습니다 */
</script>

Posted by 1010