VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Simple Encryption/Decryption bas using ASCII

by Jaime Muscatelli (14 Submissions)
Category: Encryption
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

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)

API Declarations
Option Explicit

Rate A Simple Encryption/Decryption bas using ASCII

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

Download this snippet    Add to My Saved Code

A Simple Encryption/Decryption bas using ASCII Comments

No comments have been posted about A Simple Encryption/Decryption bas using ASCII. Why not be the first to post a comment about A Simple Encryption/Decryption bas using ASCII.

Post your comment

Subject:
Message:
0/1000 characters