µðÄÚµù ÇÔ¼ö ÀÔ´Ï´Ù.


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :ÀüÁ¤ÀÏ 1999³â 2¿ù 22ÀÏ 09:19:08

In Reply to: base64 ÀÎÄÚµù ¹× µðÄÚµù ¹æ¹ýÀ» ¾Æ½Ã´Â ºÐ ¾Ë·ÁÁÖ¼¼¿ä.. posted by ¼­Ä¡¿µ on 1999³â 2¿ù 18ÀÏ 03:53:44:

µðÄÚµù ¹Û¿¡ ¸¸µç °ÍÀÌ ¾ø³×¿ä. »ç¿ëÇϽô µ§ ¹«¸®°¡ ¾øÀ» °ÍÀÔ´Ï´Ù.


public String Base64Decode(String str)
{
StringBuffer sb = new StringBuffer();
String returnStr = "";
try{
if (str.length() < 1){
return returnStr;
}
byte tmp1,tmp2,tmp3,tmp4;
int bytelen = str.length()/4*3;
byte arraybyte[] = new byte[bytelen];
byte hanchar[] = new byte[2];
byte chr;
char chrtmp;
int j=0;

for (int i=0; i<str.length();i=i+4){

tmp1 = BchngValue(str.charAt(i));
tmp2 = BchngValue(str.charAt(i+1));
if(str.charAt(i+2) == '='){
tmp3=(byte)0x00;}
else{
tmp3 = BchngValue(str.charAt(i+2));
}
if (str.charAt(i+3) == '='){
tmp4 = (byte)0x00;}
else{
tmp4 = BchngValue(str.charAt(i+3));
}

chr = tmp1;
chr=(byte)(tmp1<<2);
tmp1=(byte)tmp2;
tmp1=(byte)(tmp1 & 0x30);
tmp1=(byte)(tmp1>>4);
chr=(byte)((byte)chr | (byte)tmp1);
arraybyte[j]=(byte)chr;

tmp2=(byte)(tmp2<<4);
tmp1=tmp3;
chr=(byte)((byte)(tmp3 & 0x3c) >> 2);
chr=(byte)((byte)tmp2 | (byte)chr);
arraybyte[j+1]=(byte)chr;

tmp1=(byte)((byte)(tmp1 & 0x03) << 6);
chr=(byte)((byte)tmp1 | (byte)tmp4);
arraybyte[j+2]=(byte)chr;
j=j+3;
}


for(int k=0;k<bytelen;k++){

if (arraybyte[k] >=0x00 && arraybyte[k] <=0x7f)
{
sb.append((char)arraybyte[k]);
}
else if (arraybyte[k] >=(-128) && arraybyte[k] <=(-1))
{
//chrtmp = (char)((char)arraybyte[k] << 8);
//chrtmp = (char)((char)chrtmp | (char)arraybyte[k+1]);
hanchar[0] = arraybyte[k];
hanchar[1] = arraybyte[k+1];
try {
sb.append(new String(hanchar,"KSC5601"));
} catch (UnsupportedEncodingException e) {}
k++;
}
}

returnStr = new String(sb.toString());
//System.out.println(returnStr.length());
//System.out.println(returnStr);

return returnStr;
}catch(Exception e){System.out.println("Error In BaseDecode:");return str;}


}




private byte BchngValue( char chr)
{
byte temp;
temp=(byte)chr;
if (temp >= 'A' && temp <='Z')

temp=(byte)(temp-0x41);
else if (temp >='a' && temp <= 'z')
{
temp=(byte)(temp-0x47);
}
else if (temp >='0' && temp <= '9')
{
temp= (byte)(temp+0x04);
}
else if(temp == '+')
{
temp=(byte)(temp+0x13);
}
else if(temp == '-')
{
temp=(byte)(temp+0x12);
}
return temp;
}


´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]