views:

145

answers:

3

I want to encrypt some info for a licensing system and I want the result to be able to be typed in by the user.

Update: This operation must be reversible (decrypt-able) E.g., Encrypt ( ComputerID+ProductID) -> (any standard ASCII character that can be typed. Ideally maybe even just A-Z).

So far what I did was to convert the encrypted text to HEX (so it's any character from 0-F) but that doubles the number of characters.

I'm using VB6.

I'm thinking I'd do some operation on each pair of (Input$(x) and Key$(x)) and then do a MOD to keep it within a range of ascii values (maybe 0-9-A-Z)

Any suggestions of a good algorithm?

+5  A: 

Look into Base64 "encryption."

Base 64 will convert a number into 64 different ASCII characters, verses hex which is only 16 different ASCII characters... Making Base64 more compact and what you are looking for.

EDIT: Code to do this in VB6 is available here: http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp

Per Fuzzy Lollipop, below, Base32 looks like an even better option. Bonus points if you can find an example of that.

EDIT: I found an example of Base32 for VB6 although I've not tried it yet. -Clay

Computer Guru
base64 is not encryption it is encoding, there is nothing cypheric about base64
fuzzy lollipop
hence my usage of "" around the word :)
Computer Guru
I cannot find a VB6 implementation of Base32, but it's really simple to implement.For the encoding function, just map inputs 0-26 to a-z, and inputs 27-32 to 2-7.base32 means 2^5, so char = 'A' + 5bits. If result is > 'Z', add the difference between 'Z' and the result to '2'.:)
Computer Guru
+2  A: 

encode the encrypted bytes in HEX, or Base32 or Base64

fuzzy lollipop
+1 for mentioning Base32, it uses A-Z (case insensitive) and 2-7, so it's not difficult to different 0-O, or 1-I-l
MBO
I'd forgotten about the 0-O an I-1 similarity. VERY good thinking. If you can provide an example, you'll have the winning answer.
Clay Nichols
A: 

Do you want this to be reversible -- to recover the IDs from the encrypted text? If so then it matters how you combine the key and input strings.

Usually you'd XOR each byte pair (work with byte arrays to avoid Unicode issues), circulating on the key string if it's shorter than the input. You can then use Base N encoding (32, 64 etc) to generate the license string.

Both operations are reversible: you can recover the XORed strings from the Base N string, then XOR with the key again to get the original IDs.

If you don't care about reversing the operations, then any convolution of key and ID will do. XOR is just the simplest.

Jim Mack
Yes, should be reversible.
Clay Nichols