VB icon

Beginner String Encryption

Email
Submitted on: 1/10/2015 2:36:00 PM
By: The Joker (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: VB 5.0, VB 6.0
Views: 1159
 
     It takes a string from a textbox and encrypts it. Nothing major, i wouldnt use this for anything important, but i use it to encrypt data and put the encrypted string in the registry. This is sections of different codes i have found, i changed some of it around, joined some of it and found a nice little encryption method.

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Beginner String Encryption
'**************************************
N/A
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Beginner String Encryption
' Description:It takes a string from a textbox and encrypts it. Nothing major, i wouldnt use this for anything important, but i use it to encrypt data and put the encrypted string in the registry. This is sections of different codes i have found, i changed some of it around, joined some of it and found a nice little encryption method.
' By: The Joker (from psc cd)
'
' Inputs:An UnEncrypted String.
'
' Returns:An Encrypted String.
'
' Assumes:Not for governmental use. & You need at least 3 characters to encrypt the string.
'
' Side Effects:Coding may cause damage to personal life if not accompanied with Jolt Cola.
'**************************************

' [: Paste This Code Into a module. :]
Option Explicit
Dim DataLength as Boolean
Dim i As Integer
Dim Letter As String, Side0 As String, Side1 As String, Side2 As String
Public Function Encrypt(ByVal EncryptData As String)
 If Len(EncryptData) Mod 2 = 0 Then
Side1 = StrReverse(Left(EncryptData, (Len(EncryptData) / 2)))
Side2 = StrReverse(Right(EncryptData, (Len(EncryptData) / 2)))
EncryptData = Side1 & Side2
 Else
Side0 = StrReverse(EncryptData)
 For i = 1 To Len(Side0)
Letter = Mid$(Side0, i, 1)
Mid$(Side0, i, 1) = Chr(Asc(Letter) + 9)
 Next i
EncryptData = Side0
 End If
 
 For i = 1 To Len(EncryptData)
Letter = Mid$(EncryptData, i, 1)
Mid$(EncryptData, i, 1) = Chr(Asc(Letter) + 2)
 Next i
 
 Encrypt = EncryptData 'LCase(EncryptData)
End Function
Public Function Decrypt(ByVal DecryptData As String)
 For i = 1 To Len(DecryptData)
Letter = Mid$(DecryptData, i, 1)
Mid$(DecryptData, i, 1) = Chr(Asc(Letter) - 2)
 Next i
 
 If Len(DecryptData) Mod 2 = 0 Then
Side1 = StrReverse(Left(DecryptData, (Len(DecryptData) / 2)))
Side2 = StrReverse(Right(DecryptData, (Len(DecryptData) / 2)))
DecryptData = Side1 & Side2
 Else
Side0 = StrReverse(DecryptData)
 For i = 1 To Len(Side0)
Letter = Mid$(Side0, i, 1)
Mid$(Side0, i, 1) = Chr(Asc(Letter) - 9)
 Next i
DecryptData = Side0
 End If
 
 Decrypt = DecryptData 'LCase(DecryptData)
End Function
' [: ENCRYPTDATA & DECRYPTDATA 2 B PASSED :]
Private Sub Command1_Click()
Dim EncryptData As String
CheckLength
If DataLength = True Then
 EncryptData = EncryptData & Encrypt(Text1.Text)
 Text2.Text = EncryptData
Else
 MsgBox "Sorry, Not Enuogh Characters"
End If
End Sub
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Private Sub Command2_Click()
Dim DecryptData As String, DecryptRegData As String
 DecryptData = DecryptData & Decrypt(Text2.Text) '(DecryptRegData)
 Text3.Text = DecryptData
End Sub
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Sub CheckLength()
 If Len(Text1.Text) <= 3 Then
DataLength = False
 Else
DataLength = True
 End If
End Sub
'-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Private Sub Form_Load()
 DataLength = False
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.