VB icon

A Simple Encryption/Decryption bas using ASCII

Email
Submitted on: 1/30/2015 4:07:00 AM
By: Jaime Muscatelli (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: VB 6.0
Views: 4306
 
     This is great for beginners! This takes each character of a string and converts it to an ASCII value, then adds or substracts a designated number in order to decrypt/encrypt the string. Great for in-app passwords! Check it out sVariable = ENCRYPT(sYourString,lLenOfString)
 

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 :A Simple Encryption/Decryption bas using ASCII
'**************************************
Option Explicit
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: A Simple Encryption/Decryption bas using ASCII
' Description:This is great for beginners! This takes each character of a string and converts it to an ASCII value, then adds or substracts a designated number in order to decrypt/encrypt the string. Great for in-app passwords! Check it out
sVariable = ENCRYPT(sYourString,lLenOfString)
' By: Jaime Muscatelli (from psc cd)
'**************************************

Option Explicit
'*** By Jaime Muscatelli
' Just a simple example usage sub ( Main() is Not needed for prog!)
Public Sub Main()
Dim sString As String
Dim sEncrypted As String
Dim sDecrypted As String
sString = InputBox("String?", "String?")
sEncrypted = ENCRYPT(sString, Len(sString))
MsgBox sEncrypted
sDecrypted = DECRYPT(sEncrypted, Len(sEncrypted))
MsgBox sDecrypted
End Sub
' The encryption sub
' USAGE:sVariable = ENCRYPT(sYourString, lLengthOfString)
Private Function ENCRYPT(sString As String, lLEn As Long) As String
'Just declaring variables
Dim I As Long
Dim NewChar As Long
I = 1 'can't start a string at 0 :-)
' Go through each character in the string and convert
' it to an ASCII value, add the number desired (here, 13), and
' then place it into a new string 
Do Until I = lLEn + 1
NewChar = Asc(Mid(sString, I, 1)) + 13
ENCRYPT = ENCRYPT + Chr(NewChar)
I = I + 1
Loop
End Function
'Decryption sub
'USAGE: sVariable = DECRYPT(sYourstring, lLengthOfString) 
Private Function DECRYPT(sString As String, lLEn As Long) As String
Dim I As Long
Dim NewChar As Long
I = 1
'Doing the reverse of the encryption sub!
Do Until I = lLEn + 1
NewChar = Asc(Mid(sString, I, 1)) - 13
DECRYPT = DECRYPT + Chr(NewChar)
I = I + 1
Loop
End Function


Other 13 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.