roger_wgnr
Newcomer
Since I am fairly new to this forum I could not post this to the Code Library.
I posted it on Extreme VB talk and thought someone here may find it of use also.
This is a simple class to encode and decode lines of text. I find it very usefull to keep prying eyes from data (as long as true security is not an issue) such as file locations and specific program data that I save to data files. While the Encoding is simple and can be broken there are steps that make it harder. Such as using a different key for each encoded line. This helps hide the method used and adds complexity to the process of trying to break it.
However, I want to make it plain that this does not provide secure encryption.
This is more of a method to obscure data for privacy.
Now to call the methods I use the following
Hope this will be of use
I posted it on Extreme VB talk and thought someone here may find it of use also.
This is a simple class to encode and decode lines of text. I find it very usefull to keep prying eyes from data (as long as true security is not an issue) such as file locations and specific program data that I save to data files. While the Encoding is simple and can be broken there are steps that make it harder. Such as using a different key for each encoded line. This helps hide the method used and adds complexity to the process of trying to break it.
However, I want to make it plain that this does not provide secure encryption.
This is more of a method to obscure data for privacy.
Visual Basic:
Public NotInheritable Class CypherText
' Prevent the compiler from creating a default public constructor.
Private Sub New()
End Sub
Public Shared Function EnCode(ByVal ToEnCode As String, ByVal KeyCode As String) As String
Dim MyReturn As String = ""
'Convert string to Character array
Dim MyArray() As Char = ToEnCode.ToCharArray
Dim Result As String
'Loop through Array and alter the character
For MyLoop As Integer = 0 To MyArray.Length - 1
Result = Chr(Asc(MyArray(MyLoop)) Xor Asc(KeyCode))
'Do not alter if it results in a Carrage Return or Line Feed
If Result = Chr(13) Or Result = Chr(10) Then
MyReturn = MyReturn & Chr(Asc(MyArray(MyLoop)))
Else
MyReturn = MyReturn & Result
End If
Next
Return KeyCode & MyReturn
End Function
Public Shared Function DeCode(ByVal ToDeCode As String) As String
Dim MyReturn As String = ""
Dim Result As String
'First Character is the Encoding Key
Dim KeyCode As String = ToDeCode.Substring(0, 1)
'Convert string to Character Array
Dim MyArray() As Char = ToDeCode.ToCharArray
'Loop through all but first character and convert back to original character
For MyLoop As Integer = 1 To MyArray.Length - 1
Result = Chr(Asc(MyArray(MyLoop)) Xor Asc(KeyCode))
'If result is a Carrage Return oR Line Feed it was not encrypted
If Result = Chr(13) Or Result = Chr(10) Then
MyReturn = MyReturn & Chr(Asc(MyArray(MyLoop)))
Else
MyReturn = MyReturn & Result
End If
Next
Return MyReturn
End Function
End Class
Code:
Const KeyVal As String = "abcdefghijklmnopqrstuvwxyz0123456789[]?/><!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Public RndKey As New Random
Dim EncodedTextVariable As String
EncodedTextVariable = CypherText.EnCode("Text to encode Here", KeyVal.Substring(RndKey.Next(0, 77), 1)
Dim OriginalText As String
OriginalText = CypherText.DeCode(EncodedTextVar)
Hope this will be of use