'base64를 이용한 복호화 함수

	Dim enc64List()
	Dim dec64List()
	Dim  c, d, e , ascValue, i, n, ascArrayValue
	Dim  input(), output, ptr

Function initBase64()  '초기화 함수

	For i=0 To 25
		ReDim Preserve enc64List(i)
'Response.write Ubound(enc64List)&"
" 'CHR ==String.fromCharCode enc64List(Ubound(enc64List)) = Chr(65 + i) 'Response.write "i : "& i & ", enc64List : "& enc64List(i)&"]
" Next For i=0 To 25 ReDim Preserve enc64List(i+26) enc64List(Ubound(enc64List)) = Chr(97 + i) 'Response.write "i+26 : "& i+26 & ", enc64List : "& enc64List(i+26)&"]
" Next For i=0 To 9 ReDim Preserve enc64List(i+26+26) enc64List(Ubound(enc64List)) = Chr(48 + i) 'Response.write "i+26+26 : "& i+26+26 & ", enc64List : "& enc64List(i+26+26)&"]
" Next ReDim Preserve enc64List(Ubound(enc64List)+1) enc64List(Ubound(enc64List)) = "+" ReDim Preserve enc64List(Ubound(enc64List)+1) enc64List(Ubound(enc64List)) = "/" 'Response.write "["&enc64List(ubound(enc64List)-1)&"]
" 'For i=0 To ubound(enc64List) ' Response.write "i : "& i & ", enc64List : "& enc64List(i)&"]
" 'next For i=0 To 127 ReDim Preserve dec64List(i) dec64List(Ubound(dec64List)) = -1 Next 'Response.write "["&ubound(dec64List)&"]
" For i=0 To 63 ReDim Preserve dec64List(i+127) 'dec64List[enc64List[i].charCodeAt(0)] = i; dec64List(Asc(Left(enc64List(i),1))) = i 'Response.write i & " : " &Asc(Left(enc64List(i),1)) & "
" Next End Function Function base64Decode(value) c=0 d=0 ascValue=0 ptr =0 n=0 output = "" initBase64() '초기화함수를 이용하여 디코더 함수 배열 초기화 'Response.write "

" 'Response.write "value : ["& value&"]
" 'input = Split(value, "") ' ""로 잘라서 input 배열 생성 ReDim input(Len(value)-1) 'asp split 은 "" 으로 자를 수 없어서 for 문 활용 For i=0 To Len(value)-1 input(i) = Mid(value, i+1,1) ' Response.write "input : ["& input(i)&"]
" Next 'Asc(value) ==charCodeAt() ascValue = Asc(Left(input(ptr),1)) '배열의 인덱스 값을 증가시키며 첫번째 문자의 아스키 값을 ascValue로 받는다 'Response.write "ascValue : ["& ascValue&"]
" ptr =ptr +1 ascArrayValue = dec64List(ascValue) 'Response.write "ascArrayValue : ["& ascArrayValue&"]
" If ascValue >= 0 And ascValue < 128 And ascArrayValue <> -1 Then if n Mod 4 = 0 Then 'c = ascArrayValue << 2 c = ascArrayValue * 2^2 'Response.write "n : " & n &", c : ["& c &"]
" ElseIf n Mod 4 = 1 Then 'c = c Or ( ascArrayValue >> 4 ) c = c Or ( ascArrayValue / 2^4 ) 'Response.write "n : " & n &", c : ["& c &"]
" 'd = ( ascArrayValue And 0x0000000F ) << 4 d = ( ascArrayValue And &HF ) * 2^4 'Response.write "n : " & n &", d : ["& d &"]
" ElseIf n Mod 4 = 2 Then 'd = d Or ( ascArrayValue >> 2 ) d = d Or ( ascArrayValue /2^2 ) 'Response.write "n : " & n &", d : ["& d &"]
" 'e = ( ascArrayValue And 0x00000003 ) << 6 e = ( ascArrayValue And &H3 ) * 2^6 'Response.write "n : " & n &", e : ["& e &"]
" Else e = e Or ascArrayValue End If n= n+1 if n Mod 4 = 0 Then output = output & CHR(c) &CHR(d) & CHR(e) 'Response.write "n : " & n &"output : ["& output&"]
" End If End If 'x >> n' 은 x / 2^n의 결과와 같다. 우측으로 비트를 n만큼 움직임 'x << n' 은 x * 2^n의 결과와 같다. Do While ubound(input) >= ptr '기존 value를 잘라서 가지고 있는 input 배열의 크기와 ptr이 같아 질때까지 'Response.write ptr &"
" ascValue = Asc(Left(input(ptr),1)) '배열의 ptr 값을 증가시키며 첫번째 문자의 아스키 값을 ascValue로 받는다 : asp ++ 지원을 하지 않아 다음줄에서 ptr 증가 ptr =ptr +1 ascArrayValue = dec64List(ascValue) If ascValue >= 0 And ascValue < 128 And ascArrayValue <> -1 Then if n Mod 4 = 0 Then 'c = ascArrayValue << 2 c = ascArrayValue * 2^2 ElseIf n Mod 4 = 1 Then 'c = c Or ( ascArrayValue >> 4 ) c = c Or ( ascArrayValue / 2^4 ) 'd = ( ascArrayValue And 0x0000000F ) << 4 d = ( ascArrayValue And &HF ) * 2^4 ElseIf n Mod 4 = 2 Then 'd = d Or ( ascArrayValue >> 2 ) d = d Or ( ascArrayValue /2^2 ) 'e = ( ascArrayValue And 0x00000003 ) << 6 e = ( ascArrayValue And &H3 ) * 2^6 Else e = e Or ascArrayValue End If n= n+1 if n Mod 4 = 0 Then output = output & CHR(c) &CHR(d) & CHR(e) 'Response.write "n : " & n &", output : ["& output&"]
" End If End If Loop 'output += (n % 4 == 3) ? String.fromCharCode(c) + String.fromCharCode(d) : ((n % 4 == 2) ? String.fromCharCode(c) : ""); If n Mod 4 =3 Then output = output &CHR(c) & CHR(d) Else If n Mod 4 = 2 Then output = output & CHR(c) Else output = output & "" End If End If base64Decode = output End Function 내가 만듬, 현재 블로그 스크립트 메뉴에 있는 base64 암호화 함수를 복호화 하는 function 이며 자바스크립트 base64Decode(value) 함수를 asp 용으로 바꾼 것임. 비트 연산자가 먹히지 않아서 조금 애먹음 사용 법은 파라미터를 넘기는 페이지에서 스크립트용 base64 암호화를 이용하여 암호화 한후 submit 하면 받는 페이지에서 asp function base64Decode(parameter) 를 이용 하여 복호화 반대로 하는 즉 asp 에서 암호화 -> 자바스크립트 복호화는 나중에 만들어야 할듯 참고할 사항은 스크립트로 암호화시 그 페이지에서 넘어가기 직전 암호화된 아이디가 input 태그에 노출 되므로 (비밀번호는 type이 password라 노출되지 않음) 넘길때 스크립트로 각 값을 hidden 태그에 저장하고 보여지는 input 태그에는 값을 없애는 방법으로 적용함 아.. 자바하고싶다 ㅠㅠㅠㅠ

'프로그래밍 > ASP / .NET' 카테고리의 다른 글

간단한 다운로드 소스  (0) 2014.08.07
asp 에러 노출 코드  (0) 2014.03.05
asp 에서 엑셀로 파일 다운로드 구현하기  (0) 2013.10.08

+ Recent posts