Function EncDec(InData As variant, Optional inPW As variant=”") as variant
On Error Resume Next
Dim arrSBox(0 to 255) As Integer
Dim arrPW(0 to 255) As Integer
Dim Bi As Integer,Bj as Integer
Dim mKey As Integer
Dim i As Integer, j As Integer
Dim x As Integer, y as Integer
Dim mCode As Byte, mCodeSeries As Variant
EncDec=”"
If Trim(inData)=”"Then
Exit Function
End If
If inPW <> “” Then
j=1
For i=0 to 255
arrPW(i)=Asc(Mid$(inPW),j,1))
j=j+1
if j > Len(inPW) Then
j=1
End if
Next i
Else
For i = 0 to 255
arrPW(i)=0
Next i
End if
For i = 0 to 255
arrSBox(i)=i
Next i
j=0
For i=0 to 255
j=(arrSBox(i) + arrPW(i)) Mod 256
x=arrSBox(i)
arrSBox(i)=arrSBox(j)
arrSBox(j)=x
Next i
mCodeSeries=”"
Bi=0;Bj=0
For i=1 to Len(InData)
Bi=(Bi+1)Mod 256
Bj=(Bj+arrSBox(Bi))Mod 256
‘change
x=arrSBox(Bi)
arrSBox(Bi=arrSBox(Bj)
arrSbox(Bj)=x
‘key for XOR
mKey=arrSBox(arrSBox(Bi)+arrSBox(Bj))Mod 256)
‘use operand XOR
mCode=Asc(Mid$(inData,i,1)) XOR mKey
mCodeSeries=mCodeSeries & Chr(mCode)
Next i
EncDec=mCodeSeries
End Function
If you want to buy something for christmast day don’t worry. Read More