Subversion Repositories DevTools

Rev

Rev 29 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
29 jtweddle 1
<%
2
'******************************
3
'   Crypt.asp
4
'******************************
5
 
6
Dim g_Key
7
 
8
Const g_CryptThis = "123"
9
Const g_KeyLocation = "key.txt"
10
 
11
g_Key = mid(ReadKeyFromFile(g_KeyLocation),1,Len(g_CryptThis))
12
 
13
Response.Write EnCrypt(g_CryptThis)
14
'Response.Write DeCrypt(EnCrypt(g_CryptThis))
15
 
16
Function EnCrypt(strCryptThis)
17
   Dim strChar, iKeyChar, iStringChar, i
18
   for i = 1 to Len(strCryptThis)
19
      iKeyChar = Asc(mid(g_Key,i,1))
20
      iStringChar = Asc(mid(strCryptThis,i,1))
21
      ' *** uncomment below to encrypt with addition,
22
      ' iCryptChar = iStringChar + iKeyChar
23
      iCryptChar = iKeyChar Xor iStringChar
24
      strEncrypted =  strEncrypted & Chr(iCryptChar)
25
   next
26
   EnCrypt = strEncrypted
27
End Function
28
 
29
Function DeCrypt(strEncrypted)
30
Dim strChar, iKeyChar, iStringChar, i
31
   for i = 1 to Len(strEncrypted)
32
      iKeyChar = (Asc(mid(g_Key,i,1)))
33
      iStringChar = Asc(mid(strEncrypted,i,1))
34
      ' *** uncomment below to decrypt with subtraction	
35
      ' iDeCryptChar = iStringChar - iKeyChar 
36
      iDeCryptChar = iKeyChar Xor iStringChar
37
      strDecrypted =  strDecrypted & Chr(iDeCryptChar)
38
   next
39
   DeCrypt = strDecrypted
40
End Function
41
 
42
Function ReadKeyFromFile(strFileName)
43
   Dim keyFile, fso, f
44
   set fso = Server.CreateObject("Scripting.FileSystemObject") 
45
   set f = fso.GetFile(strFileName) 
46
   set ts = f.OpenAsTextStream(1, -2)
47
 
48
   Do While not ts.AtEndOfStream
49
     keyFile = keyFile & ts.ReadLine
50
   Loop 
51
 
52
   ReadKeyFromFile =  keyFile
53
End Function
54
%>
55