Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to convert javscript runat server to VB.Net

Status
Not open for further replies.

AndyH1

Programmer
Joined
Jan 11, 2004
Messages
350
Location
GB
I have some code I inherited for an encryption which we where running in asp. We now need to convert it to VB.Net but unfortunately its a mix of asp and javascript
The code was originally

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Function IzDecrypt(ByVal s)
Dim k, x, iKeyChar, iStringChar, iDeCryptChar
k = ReadKeyFromFile()
x = ""

For i = 1 To len(s)
iKeyChar = mid(k, i, 1)
iStringChar = mid(s, i, 1)
iDeCryptChar = expon(iKeyChar, iStringChar)
x = x & iDeCryptChar
Next

IzDecrypt = x
End Function
</SCRIPT>
<script language=JavaScript RUNAT=SERVER>
function expon(a,b) {
return (String.fromCharCode(a.charCodeAt(0) ^ b.charCodeAt(0)));
}
</script>


run inside the global.asa.

I now need to integrate this into the global.asax, but am unsure how (and if I can) integrate the javascript part as the asp and javascript need to communicate

For asp.net now have:
----------------------------------------------------------
Imports System.Web
Imports System.Web.SessionState

Public Class Global
Inherits System.Web.HttpApplication
Function IzDecrypt(ByVal s)
Dim k, x, iKeyChar, iStringChar, iDeCryptChar
k = ReadKeyFromFile()
x = ""

For i = 1 To len(s)
iKeyChar = mid(k, i, 1)
iStringChar = mid(s, i, 1)
iDeCryptChar = expon(iKeyChar, iStringChar)
x = x & iDeCryptChar
Next

IzDecrypt = x
End Function
End Class
-----------------------------------------------------------
but cannot see how I can add the javascript runat server bit so that the asp.net knows about the expon function. (Assume if I change languages this could affect the expon functionality so cannot simply change to asp.net). Can anyone give me suggestions as to whether this is feasible and if so any pointers

Thanks
Andy
 
I would suggest creating a class with a public method that could be called and that returned "x". You will be able to call the class from anywhere in your project (no real need for global.asax).

I must admit that I don't know what the expon function does in javascript but your are right in that it will not work in .NET (although there is most probably an alternative).

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thanks, I'm afraid I'm a bit of a newbie to asp.net. How would I create a class to run the javascript? I use visual studio and all it gives is the ability to create classes for vb or vc? Can anyone advise
Thanks
Andy
 
You wouldn't create a class to run the javascript - you would create a vb (or vc) class with .net code that you would run server-side.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Not sure how this would help me incorporate the javscript code? Sorry if I'm being a bit stupid.
Andy
 
What I mean is that why does it need to be javascript? You are doing all of the encryption server-side anyway so why can't you just create a class and call the method whenever it is needed?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Ah I see, thanks - manged to convert it to vb.net
Function expon(ByVal a, ByVal b)
expon = Chr(Asc(Left(a, 1)) Xor Asc(Left(b, 1)))
End Function

and it works fine. many thanks for your help
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top