Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Encrypt a string (uses password)


Function EncryptString(Plain As String , Key As String ) As String
Dim i As Long , P As String , K As String
For i = 1 To Len(Plain)
 P = Mid (Plain, i, 1)                       'next character from Plain
 K = Mid (Key, (i - 1) Mod Len(Key) + 1, 1) 'next character from Key
  'next encrypted character - convert to ASCII, XOR them, and convert to a character again
 EncryptString = EncryptString & Chr ( Asc (P) Xor Asc (K))
Next i
End Function