S

Function crypt (Action As String, key As String, Src As String) As String
'Action E für verschlüsseln oder D für entschlüsseln
'key ein Schlüssel String
'Scr der zu verschlüsselnde bzw. zu entschlüsselnde String

Dim Count As Integer
Dim KeyPos As Integer
Dim KeyLen As Integer
Dim SrcAsc As Integer
Dim Dest As String
Dim Offset As Integer
Dim srcpos As Integer, TmpSrcAsc
KeyLen = Len(key)

If Action = "E" Then

Randomize
Offset = (Rnd * 10000 Mod 255) + 1
Dest = Hex$(Offset)

For srcpos = 1 To Len(Src)

SrcAsc = (Asc(Mid$(Src, srcpos, 1)) + Offset) Mod 255
If KeyPos < KeyLen Then

KeyPos = KeyPos + 1

Else

KeyPos = 1

End If
SrcAsc = SrcAsc Xor Asc(Mid$(key, KeyPos, 1))
Dest = Dest + Format$(Hex$(SrcAsc), "@@")
Offset = SrcAsc

Next

ElseIf Action = "D" Then

Offset = Val("&H" + Left$(Src, 2))
For srcpos = 3 To Len(Src) Step 2

SrcAsc = Val("&H" + Trim(Mid$(Src, srcpos, 2)))

If KeyPos < KeyLen Then

KeyPos = KeyPos + 1

Else

KeyPos = 1

End If
TmpSrcAsc = SrcAsc Xor Asc(Mid$(key, KeyPos, 1))
If TmpSrcAsc <= Offset Then

TmpSrcAsc = 255 + TmpSrcAsc - Offset

Else

TmpSrcAsc = TmpSrcAsc - Offset

End If
Dest = Dest + Chr(TmpSrcAsc)
Offset = SrcAsc

Next

End If
crypt = Dest

End Function

Anzeige

Zum Seitenanfang