Encoding Of Strings

Posted on 2011-04-19
Medium Priority
Last Modified: 2013-11-27
Say I've got a simple two field table in access (Sample data and possible results listed)
STRING -------------------------------------------------- CODED-RESULT
John Smith, 1 Main Street --------------------------- 44654844werrw4we4fw+4fwe4wfwef
Mary Quinn, 22 Green Street ----------------------- 4g489ewr4g4w4gwre4huioyt4t4hr4r4t4rh
Barry Quinn, Lissenhall, Swords -------------------- g48r4gwg49w4gfw4wyuh4a68e84dsg4s68g4a

What I need is a function that will convert the name/address string into some kind of unrecognisable string (and of course the ability to convert back)

I'm not looking for encryption, or any kind of high security. Once the coded result is unrecognisable as a name and address, I'm happy.

It is important that coded result is unique. (every unique name/address should produce a unique result).

If the function used some kind of "seed word" that would be great (but not necessary).

I know that the above methodology is used by providers of some software products where the name and address and other info is stored in a long key for activating software. However I would prefer something built into Access where I will have 1000's of listings.

I have access 2003 & 2007 but I would like any solution provided to work in 2003.
Question by:Eirman
LVL 41

Assisted Solution

graye earned 600 total points
ID: 35427251
I'd recommend something as simple as Base64 encoding.

This is pretty standard on higher-level languages, but can be added to VBA with the following:  http://www.source-code.biz/snippets/vbasic/12.htm
LVL 26

Assisted Solution

Nick67 earned 600 total points
ID: 35429023
Nothing super-fancy
Turn the letters into comma delimited strings of numbers and vice versa

Private Function Obfuscate(mystring As String) As String

Dim Result As String
Dim myLength As Integer
Dim x As Integer
myLength = Len(mystring)
For x = 1 To myLength
    Result = Result & Asc(Right(Left(mystring, x), 1)) & ","
Next x
Obfuscate = Result

End Function

Private Function DeObfuscate(mystring As String) As String
On Error Resume Next
Dim Result As String
Dim myLength As Integer
Dim x As Integer
Dim TheLetters() As String
TheLetters() = Split(mystring, ",")

For x = 0 To UBound(TheLetters)
    Result = Result & Chr(CInt(TheLetters(x)))
Next x
DeObfuscate = Result
End Function

Open in new window

LVL 24

Author Comment

ID: 35429410
Thanks for the excellent suggestions ..... Any more anyone ?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Accepted Solution

LambertHeenan earned 800 total points
ID: 35478386
Here is a simple example of using XOR to reverably obsucre text.

Option Compare Database
Option Explicit

Dim strKey As String

Function ObscureString(strIn As String) As String
Dim nCode As Long
Dim n As Long
Dim l As Long
Dim ch As String
Dim cMask As String
Dim cAsc As Long
Dim cMaskAsc As Long
Dim strOut As String
    l = Len(strIn)
    For l = 1 To Len(strIn)
        For n = 0 To 3
            If l + n <= l Then
                ch = Mid(strIn, l + n, 1)
                cAsc = Asc(ch)
                cMask = Mid(strKey, n + 1, 1)
                cMaskAsc = Asc(cMask)
                cAsc = cAsc Xor cMaskAsc
                strOut = strOut & Chr(cAsc)
            End If
        Next n
    Next l
    ObscureString = strOut
End Function

Sub testObs(strInput As String)
Dim str As String
    strKey = ""
    While Len(strKey) < 4
    strKey = InputBox("Give me four characters", , "WXYZ")
    strKey = Left(strKey, 4)
    Debug.Print "Input:" & strInput
    str = ObscureString(strInput)
    Debug.Print "Obscured: " & str
    Debug.Print "Clear: " & ObscureString(str)
End Sub

Open in new window

LVL 11

Expert Comment

ID: 35478390
That should be "reversably"
LVL 44

Expert Comment

ID: 35495119
uhuh - reversibly
LVL 24

Author Closing Comment

ID: 35495153
Thanks everyone
LVL 11

Expert Comment

ID: 35506614
@GrayL - yup. "Reversibly". Spelling always trips me up! :-)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question