by Brad (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 4.0 (32-bit)
Difficulty: Unknown Difficulty
Originally Published: Fri 22nd June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Encryption/Decryption process works well
API Declarations
'put 3 text boxes on a form
'and 2 command buttons
'put them in whatever layout you choose
'text1 is where the user puts in the text to be encrypted
'text2 is where the user puts in the encryption key
'text3 is where the encrypted text is put
'command1 is the encrypt button
'command2 is the decrypt button
'not the best code, but will work
'--------------------------
' brad23
'--------------------------
' www.brad23hacks.f2s.com
'--------------------------
'[email protected]
'--------------------------
Message = Text1.Text
Key = Text2.Text
For i = 1 To Len(Message)
If Text2.Text = "" Then GoTo brad
textChar = Mid(Message, i, 1)
keyChar = Mid(Key, (i Mod Len(Key)) + 1)
encryptedChar = Asc(textChar) Xor Asc(keyChar)
EncryptedMessage = EncryptedMessage & Chr(encryptedChar)
Next
Text3.Text = EncryptedMessage
GoTo past
brad:
MsgBox ("Please enter an Encryption Key")
past:
End Sub
Private Sub Command2_Click()
MsgBox ("Your decrypted message will appear in the first box")
after:
Message = Text3.Text
Key = Text2.Text
For i = 1 To Len(Message)
textChar = Mid(Message, i, 1)
keyChar = Mid(Key, (i Mod Len(Key)) + 1)
encryptedChar = Asc(textChar) Xor Asc(keyChar)
EncryptedMessage = EncryptedMessage & Chr(encryptedChar)
Next
Text1.Text = EncryptedMessage
End Sub