by Patrick Briand (1 Submission)
Category: Encryption
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 18th August 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
I wanted something real simple to encrypt a password, however I didn't have much time to do so. I wrote this to serve the purpose. It could be
' I wanted something real simple to encrypt a password,
' however I didn't have much time to do so. I wrote
' this to serve the purpose. It could be optimized
' greatly if I used an encryption key. That will be
' my next submission.
' Depending on whether or not the character is in an even
' or an odd position in the string, the ascii value is
' added to or subtracted from.
Public Function MixChars(ByVal Chars As String) As String
Dim Indice, OldChar, NewChar As Integer
Dim Newtext, tmptext As String
Newtext = ""
tmptext = Chars
For Indice = 1 To Len(Chars)
' The ASC() function returns the value of the first
' character in the string. Therefore I simply loop
' until all the characters have been parsed.
' Using the MID() function could reduce the amount
' of coding used in these functions.
OldChar = Asc(tmptext)
Select Case Indice Mod 2
Case 0 ' If the character is in an even position
NewChar = OldChar + 1
Case Else ' If the character is in an odd position
NewChar = OldChar - 1
End Select
Newtext = Newtext + Chr(NewChar)
tmptext = Right(Chars, Len(Chars) - Indice)
Next Indice
MixChars = Newtext
End Function
' This function decrypts the value.
Public Function UnmixChars(ByVal Chars As String) As String
Dim Indice, OldChar, NewChar As Integer
Dim Newtext, tmptext As String
Newtext = ""
tmptext = Chars
For Indice = 1 To Len(Chars)
OldChar = Asc(tmptext)
Select Case Indice Mod 2
Case 0
NewChar = OldChar - 1
Case Else
NewChar = OldChar + 1
End Select
Newtext = Newtext + Chr(NewChar)
tmptext = Right(Chars, Len(Chars) - Indice)
Next Indice
UnmixChars = Newtext
End Function
No comments have been posted about I wanted something real simple to encrypt a password, however I didn't have much time to do so. I w. Why not be the first to post a comment about I wanted something real simple to encrypt a password, however I didn't have much time to do so. I w.