<%@Language="VBSCRIPT" CODEPAGE="949"%>
<%
Response.CharSet = "EUC-KR"
Session.CodePage = 949
Dim Str,Flag : Str = Request("str")
%>
<form method="get" action="">
<input type="text" name="str" value="<%=Str%>">
<input type="submit">
</form>
<%
Response.Write "STRING : " & Str & "<BR>"
Response.Write "ENCODE : " & BASE64_ENCODE(Str) & "<BR>"
Response.Write "DECODE : " & BASE64_DECODE(BASE64_ENCODE(Str)) & "<BR>"
Function BASE64_KEY(ByVal Num,ByVal Flag)
Const Key = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
If UCase(FLAG) = "EN" Then
BASE64_KEY = Mid(Key,Num+1,1)
ElseIf UCase(FLAG) = "DE" Then
BASE64_KEY = InStr(Key,Num)-1
End If
End Function
Function BASE64_ENCODE(ByVal eSTR)
Dim BinStr, Tmp, Padding
ReDim ArrayStr(Len(eSTR))
For i = 1 To Len(eStr)
ArrayStr(i) = Int("&H" & Right("0000" & Hex(Asc(Mid(eStr,i,1))),4))
Tmp = Empty
Do While ArrayStr(i) > 0
Tmp = Tmp & ArrayStr(i) Mod 2
ArrayStr(i) = Int(ArrayStr(i) / 2)
Loop
If Len(Tmp) > 8 Then
ArrayStr(i) = StrReverse(Tmp)
Else
ArrayStr(i) = Right("00000000" & StrReverse(Tmp),8)
End If
BinStr = BinStr & ArrayStr(i)
Next
Padding = Len(BinStr) Mod 3
ReDim ArrayStr(Round(Len(BinStr)/6-1+0.49))
For i = 0 To UBound(ArrayStr)
ArrayStr(i) = Left(BinStr,6)
If Len(BinStr) > 6 Then
BinStr = Right(BinStr,Len(BinStr)-6)
End If
Next
If Len(ArrayStr(UBound(ArrayStr))) <> 6 Then
ArrayStr(UBound(ArrayStr)) = Left(ArrayStr(UBound(ArrayStr)) & "000000",6)
End If
For i = 0 To UBound(ArrayStr)
BASE64_ENCODE = BASE64_ENCODE & BASE64_KEY(BinToDec(ArrayStr(i)),"EN")
Next
For i = 1 To Padding
BASE64_ENCODE = BASE64_ENCODE & "="
Next
End Function
'2진수 -> 10진수
Function BinToDec(strBin)
Dim lTot, ctr, nLen : lTot = 0
nLen = Len(strBin)
For ctr = nLen - 1 To 1 Step -1
lTot = lTot + (2 * CInt(Mid(strBin, ctr, 1))) ^ (nLen - ctr)
Next
BinToDec = lTot + CInt(Mid(strBin, nLen, 1))
End Function
Function BASE64_DECODE(ByVal eStr)
Dim tmp, binStr : binStr = Empty
eStr = Replace(eStr,"=","")
ReDim ArrayStr(Len(eStr))
For i = 1 To Len(eStr)
ArrayStr(i) = Mid(eStr,i,1)
ArrayStr(i) = BASE64_KEY(ArrayStr(i),"DE")
tmp = Empty
Do While ArrayStr(i) > 0
Tmp = Tmp & ArrayStr(i) Mod 2
ArrayStr(i) = Int(ArrayStr(i) / 2)
Loop
binStr = binStr & Right("000000" & StrReverse(Tmp), 6)
Next
ReDim ArrayStr(Round(Len(BinStr)/8-1+0.49))
For i = 0 To UBound(ArrayStr)
ArrayStr(i) = Left(BinStr,8)
If Len(BinStr) > 8 Then
BinStr = Right(BinStr,Len(BinStr)-8)
End If
Next
For I = 0 To UBound(ArrayStr)
If ArrayStr(i) > 0 Then
If Asc(ArrayStr(i)) = 48 Then
BASE64_DECODE = BASE64_DECODE & Chr(BinToDec(ArrayStr(i)))
Else
BASE64_DECODE = BASE64_DECODE & Chr(BinToDec(ArrayStr(i)&ArrayStr(i+1)))
i = i + 1
End If
End If
Next
End Function
%>
'ASP' 카테고리의 다른 글
[ASP] 요일 구하는 함수 (0) | 2018.08.12 |
---|---|
ASP에서 SQL 인젝션(Injection) 방어하기 (0) | 2016.11.15 |
ASP NO-CACHE (0) | 2016.03.03 |
ASP 트랙잭션 (0) | 2016.03.03 |
[ASP] Dext.ImageProc 썸네일 이미지 생성하기 (0) | 2016.02.12 |