You may create the above code as a script in the libraries section of the scripts editor. Then you may call any of its functions from any script, even from a different language, by including its reference (i.e. checking its name in the list of includes) in that script.
In the "libraries" tab create a VBScript and call it HashUtils. Put there the above code, but replace the CalcHash function with this one:
Function GetFileHash(filename,hashtype)
Select Case hashtype
Case "md5" GetFileHash=md5(filename)
Case "sha1" GetFileHash=sha1(filename)
Case "sha256" GetFileHash=sha256(filename)
Case "sha384" GetFileHash=sha384(filename)
Case "sha512" GetFileHash=sha512(filename)
Case "ripemd160" GetFileHash=ripemd160(filename)
Case Else GetFileHash=""
End Select
End Function
Now, in the "scripts" tab, create a JScript named CalcHash with this code:
function CalcHash() {
return GetFileHash(BatchFile.filename, CurrentField.value);
}
To reference the HashUtils library, that contains the implementation of GetFileHash function, click the includes button, the button at the right of the script language selector (check the second screenshot of
this forum post for reference), and check the HashUtils entry. Now you have a jscript that is using functionalities from a VBScript.
Take notice that I've just found a bug while testing this. You will need to close the batch tool, and reopen it, when creating/making changes to a script in the libraries, or the called script function will not work immediately after closing the editor.