Link to home
Start Free TrialLog in
Avatar of vblogic
vblogic

asked on

Simple Encryption?

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.
Avatar of Jacamar
Jacamar

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
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
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'.
ASKER CERTIFIED SOLUTION
Avatar of Steiner
Steiner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

AW