![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 1
Rep Power: 0
![]() |
Convert VBA to VBScript
Hi, I'm trying to use and an XOR encryption process in both VBA Access and in VBScript on a webpage. I guessed (but it seems wrong!) that the codes were more or less interchangeable. I've spent a couple of days messing around with it now and it always gives me Type Mismatch Error for the following in VBScript (It came from VBA where it worked great, although I have removed the 'as string' etc. on the dims).
I have tried debug but can't seem to work out how although I find it easy in VBA. Sorry if I'm being thick here but its driving me mental...any help would be very much appreciated. <html>
<head>
<script language = "vbscript">
Public Function dhXORText(strText, strPWD)
' Encrypt or decrypt a string using the XOR operator.
' From "Visual Basic Language Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 2000; Sybex, Inc. All rights reserved.
' In:
' strText:
' Input text
' strPWD:
' Password to be used for encryption.
' Out:
' Return Value:
' The encrypted/decrypted string.
Dim abytText()
Dim abytPWD()
Dim intPWDPos
Dim intPWDLen
Dim intChar
abytText = strText
abytPWD = strPWD
intPWDLen = LenB(strPWD)
For intChar = 0 To LenB(strText) - 1
' Get the next number between 0 and intPWDLen - 1
intPWDPos = (intChar Mod intPWDLen)
abytText(intChar) = abytText(intChar) Xor _
abytPWD(intPWDPos)
Next intChar
dhXORText = abytText
End Function
</script>
</head>
<body>
<form name = "encrypt">
<!--webbot bot="Validation" S-Data-Type="String" B-Allow-Letters="TRUE" B-Allow-Digits="TRUE" B-Allow-WhiteSpace="TRUE" --><input type = "text" name = "T1" size = "50">
<!--webbot bot="Validation" S-Data-Type="String" B-Allow-Letters="TRUE" B-Allow-Digits="TRUE" B-Allow-WhiteSpace="TRUE" --><input type = "text" name = "T2" size = "50">
<input type = "button" name = "B1" value = "Submit">
<script language = "vbscript">
Sub B1_onclick
'encrypt.T2.value = encrypt.T1.value
Dim strEncrypted
Dim strPassword
Dim strDecrypted
strPassword = "password"
strEncrypted = encrypt.T1.value
strDecrypted = dhXORText(strEncrypted, strPassword)
encrypt.T2.value = strDecrypted
End Sub
</script>
</body>
</html>Last edited by seanhepburn2002; Oct 13th, 2005 at 2:31 PM. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
As VBScript has no typecasting, Dim abytText() actually declares an array of variants, and presumably your code originally operated on a byte array for speed's sake. The closest thing would be to iterate through using the Mid function on the string, but bear in mind this will be VERY slow in comparison to the byte array method (each iteration will create and destroy several objects, as mid works on and returns a string, but xor acts on a byte).
EDIT: You'll also need the Chr() and Asc() functions. |
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
XOR isn't much of an encryption. If given either the password or the text, you can XOR it with the "encrypted" data to get the other. At the very least, base your key on the current time so that replay attacks aren't as possible. Note that I am taking this out of context of what you are doing. Just consider that if you need real security, use SSL.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|