Solved

Encript a string

Posted on 2011-02-26
4
270 Views
Last Modified: 2012-06-21
Experts,

I need a function or procedure that will encrypt an alpha numeric string.  Nothing complex, just a mapping (or something) that changes the string to something you couldn't make sense of and then back again.  I am not fussed about security of access, just security of interpretation.  Something like a mapping where A =Code1 and B=code2 C= code3.

I figure, someone would have done this before.

Code snippets or links are all I need.
0
Comment
Question by:Carl Sudholz
  • 2
4 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 83 total points
Comment Utility
You could simply shift the ASCII code by one
Sub Encode()
Dim strNewText As String
Dim i As Integer

Const strSample = "Hello World"

For i = 1 To Len(strSample)
    strNewText = strNewText & Chr$(Asc(Mid(strSample, i, 1)) + 1)
Next i
MsgBox strNewText
MsgBox Decode(strNewText)
End Sub

Function Decode(strEncoded As String)
    Dim strDecoded As String
    Dim i As Integer
    
    For i = 1 To Len(strEncoded)
        strDecoded = strDecoded & Chr$(Asc(Mid(strEncoded, i, 1)) - 1)
    Next i
    Decode = strDecoded
End Function

Open in new window

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 83 total points
Comment Utility
Or you could use XOR.

Sub Encode_1()
Dim strNewText As String
Dim i As Integer

Const strSample = "Hello World"

For i = 1 To Len(strSample)
    strNewText = strNewText & Chr$(Asc(Mid(strSample, i, 1)) Xor 170)
Next i
MsgBox strNewText
MsgBox Decode_1(strNewText)
End Sub

Function Decode_1(strEncoded As String)
    Dim strDecoded As String
    Dim i As Integer
    
    For i = 1 To Len(strEncoded)
        strDecoded = strDecoded & Chr$(Asc(Mid(strEncoded, i, 1)) Xor 170)
    Next i
    Decode_1 = strDecoded
End Function

Open in new window

0
 
LVL 13

Assisted Solution

by:devlab2012
devlab2012 earned 42 total points
Comment Utility
Create a new module with the following code:

Option Compare Database
Option Explicit

Public Function Encrypt(str As String) As String
    Encrypt = ""
    Dim s1 As String
    s1 = ""
    Dim i As Integer
    i = 0
    For i = 1 To Len(str)
        s1 = Mid(str, i, 1)
        s1 = Right("000" & CStr(Asc(s1)), 3)
        Encrypt = Encrypt & s1
    Next
End Function

Public Function Decrypt(str As String) As String
    Decrypt = ""
    Dim s1 As String
    Dim code As Integer
    s1 = ""
    Dim i As Integer
    i = 0
    For i = 1 To Len(str) Step 3
        code = CInt(Mid(str, i, 3))
        s1 = Chr(code)
        Decrypt = Decrypt & s1
    Next
End Function


Run the following queries to test it:

select Encrypt('devlab2012')
select Decrypt('100101118108097098050048049050')
select Decrypt(Encrypt('devlab2012'))
0
 

Author Closing Comment

by:Carl Sudholz
Comment Utility
Absolutely perfect!

I love experts exchange
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now