Simple Encryption?

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-05-01
Does anyone have an encryption routine that can take any string and encrypt it into a string that contains only numbers and capital letters (e.g., DHSK3J641GA)

I do not want to use a Hex representation because these strings may be somewhat long and a Hex representation will only make it longer.  The encrypted string will be given to customers over the phone so I need to avoid complex strings with lower-uppercase issues and any special characters.  This is for licensing an application.  The encrypted string will contain information used by the program.
Question by:vblogic
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

Expert Comment

ID: 8159502
This will prevent lowercase letters from being typed in the textbox.

Dim fBoolChange As Boolean
Dim inI As Integer

Private Sub Text1_Change()
If fBoolChange = True Then
    fBoolChange = False
    Text1.Text = Replace(Text1.Text, Chr(inI), Chr(inI - 32))
    Text1.SelStart = Len(Text1.Text)
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii > 96 And KeyAscii < 123 Then
    fBoolChange = True
    inI = KeyAscii
End If
End Sub

Expert Comment

ID: 8159560
Here is a command that will do it.  Just get your string in to ststring, and it will do the rest

Private Sub Command1_Click()
Dim ststring As String
Dim inI As Integer
Dim inKeyasc As Integer

ststring = CStr(Text1.Text)

inI = Len(ststring)

For i = 1 To inI
    inKeyasc = Asc(Mid(ststring, i, 1))
    If inKeyasc > 96 And inKeyasc < 123 Then
            inKeyasc = inKeyasc - 32
            Mid(ststring, i, 1) = Replace(Mid(ststring, i, 1), Chr(inKeyasc + 32), Chr(inKeyasc))
    End If
   Next i

Text1.Text = ststring
End Sub
LVL 28

Expert Comment

ID: 8159610
How is this at all related to the question which is about encryption?  Encryption being altering data into an unrecognizable format.  For explanation purposes only:

Prior to Encryption :  "Hello World"
After Encryption :  "DHA249FHSU9"

Then, you should be able to run the 'After Encryption' string through a decryption routine to receive the data string value 'Prior to Encryption'.
LVL 11

Accepted Solution

Steiner earned 1000 total points
ID: 8159705
Well, the problem with the length: you'll have to remember that the encrypted string has to be longer than the original one since you can only use fewer charaters.

While in the original string you can have brackets, lower case and special characters, in the encrypted one you can't. So you'll have to replace at least some characters by 2 characters in the encrypted string (I'd guess 2 third, and since you would have to differ between 2 encrypted chars = 1 decrypted char and 1 encrypted char= 1 decrypted char, that amount will surely increase further).

So I think your hex-approach wouldn't be the worst thing since it's easy to convert (maybe some addition to confuse the user...) and should be fairly easy to revert to the original text, too.
LVL 44

Expert Comment

ID: 8160985
as Steiner has said, your original request:

"Does anyone have an encryption routine that can take any string and encrypt it into a string that contains only numbers and capital letters (e.g., DHSK3J641GA)"

CANNOT be accomplished easily.  To be specific (to elaborate on steiner's explanation)-->  "He" and "hE",for examp must be Encrypted to DIFFERENT result strings, but since you are only allowing UPPER CASE letters and NUMBERS, the RESULT set im LIMITED to a maximum of 36 different characters, which the SOURCE string can be from a set of AT LEAST 62 characters (26 Upper case letters, 26 Lower case letters, 10 digits, blanks, as well as other possible non-alphanumeric characters (;,./[]()*&^%$#@! etc))

I suggest you re-think the original request.


Featured Post

Industry Leaders: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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