Solved

Encript a string

Posted on 2011-02-26
4
275 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 83 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 83 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 42 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

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

705 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