[VB]암호화 함수 응용

01 14, 2007 01:52

Function EnCode(sText, sCode)
 Dim arrData() : Dim arrCode()

 cntData = Len(sText) - 1
 cntCode = Len(sCode) - 1

 Redim arrData(cntData) : Redim arrCode(cntCode)

 For i = 0  To cntData
  arrData(i) = Mid(sText, i + 1, 1)
 Next

 For i = 0  To cntCode
  arrCode(i) = Mid(sCode, i + 1, 1)
 Next

 flag = 0 : strResult = ""

 Dim Temp, Temp1, Temp2
 Temp="" : Temp1="" : Temp2=""

 For i = 0 To cntData
  Temp=((ASC(arrData(i)) XOR ASC(arrCode(flag))))
  Temp1=Temp1&Temp
  Temp2=Temp2&len(Temp)

  IF flag = cntCode Then flag = 0 Else flag = flag + 1
 Next

 EnCode = Temp1&"-"&Temp2
End Function


Function DeCode(sText, sCode)
 Dim arrCode(),arrData()

 if instr(sText,"-")<0 then Exit Function
 Dim Temp,Temp1,Temp2,Temp3
 Temp=InStrRev(sText,"-")
 Temp1=left(sText,Temp)
 Temp2=right(sText,len(sText)-Temp)

 ReDim arrData(len(Temp2))
 Temp=0
 for i=0 to len(Temp2)-1
  Temp3=mid(Temp2,i+1,1)
  arrData(i)=mid(Temp1,Temp+1,Temp3)
  Temp=Temp+Temp3
 next

 cntData = UBOUND(arrData) - 1
 cntCode = Len(sCode) - 1

 Redim arrCode(cntCode)

 For i = 0  To cntCode
  arrCode(i) = Mid(sCode, i + 1, 1)
 Next

 flag = 0 : strResult = ""
 For i = 0 To cntData
  strResult = strResult & CHR(Cint(arrData(i)) XOR ASC(arrCode(flag)))
  IF flag = cntCode Then
   flag = 0
  Else
   flag = flag + 1
  End IF
 Next

 DeCode = strResult
End Function

브니 Programs/VB

01 14, 2007 01:52 01 14, 2007 01:52
Trackback Address:http://limcom.co.kr/blog/trackback/15
[로그인][오픈아이디란?]
오픈아이디로만 댓글을 남길 수 있습니다