# 是否有可能将这种算法从VBA转换为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;}
``````

``````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
``````