?
Solved

Encript a string

Posted on 2011-02-26
4
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 332 total points
ID: 34986886
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 332 total points
ID: 34986908
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 168 total points
ID: 34986932
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
ID: 34986946
Absolutely perfect!

I love experts exchange
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…
Suggested Courses
Course of the Month7 days, 22 hours left to enroll

765 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