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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help converting online vbscript function to hta

Status
Not open for further replies.

cr84net2

Programmer
Feb 8, 2005
93
US
I have a web (online) asp/vbscript that uses a function to decrypt RC4 encrypted data. A client now needs to email encrypted data and decrypt it on their local desktop. I recently found out about hta's and they appear to be the answer in this case. I have read several posts and downloaded and searched the Scripting guys articles but cannot get the function to work.

I have tried at least thirty variations of the code below without success. I think I need help converting the function to a sub I can call like this: Sub B1_onClick

B1 being the name of the submit button

Here is what I have, and of course I am getting two errors, Wrong number of arguements or invalid property assignment: RC4 and Cannot use parentheses when calling a sub. Any help would be greatly appreciated.

Code:
<html>

<head><title>Data Decryption</title>

<HTA:APPLICATION ID="oHTA";

  APPLICATIONNAME="Data Decryption";

  BORDER="thin";

  BORDERSTYLE="normal";

  SINGLEINSTANCE="no";

 />
 <style>

body {
   background-color:#E8E8E8;
   font:13px "Century Gothic";
   color:#000;
hr {
   color:#0000C0;
.title {
   font-weight:700;
</style>


<script type="text/vbscript">

Sub Window_OnLoad

   self.resizeTo 600, 400

End Sub



 Function RC4(ByRef Key, ByRef Data)
    dim KeyBytes(255)
    dim CypherBytes(255)
    KeyLen=Len(Key)
    if KeyLen=0 Then Exit function
    KeyText=Key
    For i=0 To 255
      KeyBytes(i)=Asc(Mid(Key, ((i) Mod (KeyLen))+1, 1))
    Next
    if Len(Data)=0 Then Exit function
    For i=0 To 255
      CypherBytes(i)=i
    Next
    Jump=0 'Swap values of Cypher around based on index and KeyText value
    For i=0 To 255 'Find index To switch
      Jump=(Jump+CypherBytes(i)+KeyBytes(i)) Mod 256
      Tmp=CypherBytes(i) 'Swap
      CypherBytes(i)=CypherBytes(Jump)
      CypherBytes(Jump)=Tmp
    Next
    i=0
    Jump=0
    For X=1 To Len(Data)
      i=(i+1) Mod 256
      Jump=(Jump+CypherBytes(i)) Mod 256
      T=(CypherBytes(i)+CypherBytes(Jump)) Mod 256
      Tmp=CypherBytes(i) 'Swap
      CypherBytes(i)=CypherBytes(Jump)
      CypherBytes(Jump)=Tmp
      RC4=RC4 & Chr(Asc(Mid(Data, X, 1)) Xor CypherBytes(T)) 'Character Encryption
    Next
  End function
  
   Output.innerHTML= RC4
 
 </script> 
 
 </head>

<body>
<p><span class="title">Data Decryption Utility</span><hr><br>

<form name="form1"  >  

    <p>Encrypted Data Here: <input type="text" size="40" name="t2">
    
    <input type="hidden" size="40" name="t1" value="36yj49x6t5hd7x245k8tm7829a4d6cvhsh4x1m5r">

    <input type="submit" name="B1" value="Submit" onclick="RC4(t2.value,t1.value)"></p><br>
    </form>

<div id=Output></div>



</body>

</html>

If you can get me going in the right direction I would appreciate it, I feel like I am running in circles here.
 
Replace this:
Output.innerHTML= RC4
with something like this:
Output.innerHTML=RC4(strKey,strData)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV,

I tried the change mentioned. But I am still getting the Cannot use parentheses when calling a sub which occurs on the line:

Code:
<input type="submit" name="B1" value="Submit" onclick="RC4(t2.value,t1.value)"></p><br>

And I am now getting an error that says: Object Required: Output from this line:

Code:
Output.innerHTML=RC4(strKey,strData)

Do I need to define Output as a WSH object or something??


The hta is also opening another copy of the hta Which encounters the same errors. (When I click submit button).

Any ideas? thanks again for your help, i appreciate it.
 
I have made several modifications to the hta and now i don't get an error until I click the button. The error i get is:

Object Required: t2

This is on the line:

Code:
strOut=wshShell.Run(RC4(t2.value, t1.value))

t2 is a txt input box-how would I make it an object??

Here is the entire code after modification.

Code:
<html>

<head><title>Data Decryption</title>

<HTA:APPLICATION ID="oHTA";

  APPLICATIONNAME="Data Decryption";

  BORDER="thin";

  BORDERSTYLE="normal";

  SINGLEINSTANCE="no";

 />
 <style>

body {
   background-color:#E8E8E8;
   font:13px "Century Gothic";
   color:#000;
hr {
   color:#0000C0;
.title {
   font-weight:700;
</style>


<script type="text/vbscript">

Sub Window_OnLoad

   self.resizeTo 600, 400

End Sub

Set WshShell = CreateObject("WScript.Shell")

strOut=""

Sub RunScript


strOut=wshShell.Run(RC4(t2.value, t1.value))

       
   Output.innerHTML= strOut

End Sub


 Function RC4(ByRef Key, ByRef Data)
    dim KeyBytes(255)
    dim CypherBytes(255)
    KeyLen=Len(Key)
    if KeyLen=0 Then Exit function
    KeyText=Key
    For i=0 To 255
      KeyBytes(i)=Asc(Mid(Key, ((i) Mod (KeyLen))+1, 1))
    Next
    if Len(Data)=0 Then Exit function
    For i=0 To 255
      CypherBytes(i)=i
    Next
    Jump=0 'Swap values of Cypher around based on index and KeyText value
    For i=0 To 255 'Find index To switch
      Jump=(Jump+CypherBytes(i)+KeyBytes(i)) Mod 256
      Tmp=CypherBytes(i) 'Swap
      CypherBytes(i)=CypherBytes(Jump)
      CypherBytes(Jump)=Tmp
    Next
    i=0
    Jump=0
    For X=1 To Len(Data)
      i=(i+1) Mod 256
      Jump=(Jump+CypherBytes(i)) Mod 256
      T=(CypherBytes(i)+CypherBytes(Jump)) Mod 256
      Tmp=CypherBytes(i) 'Swap
      CypherBytes(i)=CypherBytes(Jump)
      CypherBytes(Jump)=Tmp
      RC4=RC4 & Chr(Asc(Mid(Data, X, 1)) Xor CypherBytes(T)) 'Character Encryption
    Next
  End function
  
  
 
 </script> 
 
 </head>

<body>
<p><span class="title">Data Decryption Utility</span><hr><br>

<form name="form1"  >  

    <p>Encrypted Data Here: <input type="text" size="40" name="t2">
    
    <input type="hidden" size="40" name="t1" value="36yj49x6t5hd7x245k8tm7829a4d6cvhsh4x1m5r">

    <input type="submit" name="B1" value="Submit" onClick="RunScript"></p><br>
    </form>

<div id=Output></div>



</body>

</html>

Any help would be appreciated.
 
Typed, untested:
Replace this:
t2.value, t1.value
with this:
Document.Forms("form1").Item("t2").Value, Document.Forms("form1").Item("t1").Value

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Thanks for bearing with me here.

I am now getting an error on the following line:

Code:
strOut=wshShell.Run(RC4(Document.Forms("form1").Item("t2").Value, Document.Forms("form1").Item("t1").Value))

The error is:

line 44 char 1 The system cannot find the file specified

Then the hta asks me to open another hta.

I am at a loss, thanks for your help.
 
I guess you wanted this:
strOut=RC4(Document.Forms("form1").Item("t2").Value, Document.Forms("form1").Item("t1").Value)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for your help, that generated a result without an error. It still opens another hta file though..any thoughts..
 
In the line you use Submit as the type. This may be appropriate for a web page but not in HTA.
For HTA change to Button as type
( )

See if that stops it attempting to open another copy.

change
Code:
    <input type="[b]submit[/b]" name="B1" value="Submit" onClick="RunScript"></p><br>
to
Code:
    <input type="[b]button[/b]" name="B1" value="Submit" onClick="RunScript"></p><br>
 
RobertC22,

Thanks for the help, I found similar information and made the corrections but help is always appreciated.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top