是否有可能将这种算法从VBA转换为Java?

我正在尝试将要使用的加密功能从VBA转换为JAVA。我已经解决了大部分编程问题,但目前仍坚持将算法集成到我的Java代码中。算法中使用的函数是否在Java中存在?

这是我已转换为Java的部分代码,

function XorC(input){
var input=input.toString();
var key="testing";
var inputlength=input.length;
var keylength=key.length;
var i;

  if ((inputlength==0) || (keylength==0)){
    var XorC="Invalid arguments(s) used";
    return 0;
  }
  var checkx= input.substring(0,3);
  if (checkx=="JKX"){
        var bEncOrDec = "False"
        input = input.substring(3,inputlength) }
  else { 
  var bEncOrDec = "True"}

var byIn = input;
var byOut = input;
var byKey = key;

让我卡住的部分

var l = LBound(byKey);

  for (i = LBound(byIn); i<=(UBound(byIn) - 1);i=i+2){
    byOut[i] = ((byIn[i] + Not bEncOrDec) Xor byKey(l)) - bEncOrDec;
    l = l + 2;
    if l > UBound(byKey)  {
    l = LBound(byKey);}
    }   

其余的代码

  var XorC = byOut;
  if (bEncOrDec=="True"){
    XorC = "JKX" + XorC;}
  else{}
  return XorC;}

如果有人想在VBA中查看原始代码,

Function XorC(ByVal sData As String, ByVal sKey As String) As String
Application.EnableCancelKey = xlDisabled
Dim l As Long, i As Long, byIn() As Byte, byOut() As Byte, byKey() As Byte
Dim bEncOrDec As Boolean

If Len(sData) = 0 Or Len(sKey) = 0 Then XorC = "Invalid argument(s) used": Exit Function

If Left$(sData, 3) = "JKX" Then
    bEncOrDec = False
    sData = Mid$(sData, 4)
Else
    bEncOrDec = True
End If

byIn = sData
byOut = sData
byKey = sKey
l = LBound(byKey)
For i = LBound(byIn) To UBound(byIn) - 1 Step 2
    byOut(i) = ((byIn(i) + Not bEncOrDec) Xor byKey(l)) - bEncOrDec
    l = l + 2
    If l > UBound(byKey) Then l = LBound(byKey)
Next i
XorC = byOut
If bEncOrDec Then XorC = "JKX" & XorC

End Function
评论