Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 13th, 2005, 2:02 PM   #1
seanhepburn2002
Newbie
 
Join Date: Oct 2005
Posts: 1
Rep Power: 0 seanhepburn2002 is on a distinguished road
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.
seanhepburn2002 is offline   Reply With Quote
Old Oct 15th, 2005, 2:12 PM   #2
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
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.
Rory is offline   Reply With Quote
Old Oct 15th, 2005, 4:20 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC