File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to convert Hex into Alphabets and Obfuscate? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to convert Hex into Alphabets and Obfuscate?" Watch "How to convert Hex into Alphabets and Obfuscate?" New topic
Author

How to convert Hex into Alphabets and Obfuscate?

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
All,

I created a sample key generator which generates UUIDs (with lots of hex for the output like this):



The main app:



The output:



I need to figure out a way to take out the hex from this String and make it look a lot better.

Figured that I could probably do it inside a separate wrapper class (perhaps a Filter) which contains an arbitrary map for the hex letters (A=G,B=M,C=X,D=U, etc.).

That way, the key (or a substring of the key) would turn into: 4HD5-K8X3-42TL.

Would appreciate it if someone could help me with the separate wrapper class which contains the obfuscator...

-James
[ May 02, 2008: Message edited by: James Dekker ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Any reason why you don't just call the toUpperCase() method of String?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Hi Paul,

Thanks for responding!

Excellent point...

I just created this filter right here:



Now, what it prints out are keys like this:

05FEE651-1F7B-3C79-A3B9-DBD3716E847F
4F86CA82-06BD-3880-9741-B5FC970B10AE
A511C3DB-1E48-32F3-B6CF-4B919934FF4D

The first subset is 8 characters long, the 2nd - 4th are four characters long, and the fifth subset is 12 characters long...

Question(s):

(1) How to take out the majority of the hex numbers (only 1 number per subset) and map the alphabets to something like this:

A=I, B=N, C=J, D=P, 1 = 3, 2 = M ?

(2) How do I ensure that all five subsets of the obfuscated string are always the same length (but with mapping specified in Line Item (1)) - see above?

e.g.

Original: A511C3DB-1E48-32F3-B6CF-4B919934FF4D
Obfuscated: XXJS1-ZKSFK-TUZAM-KHABV-QWMGP

-James
[ May 02, 2008: Message edited by: James Dekker ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You can step through each character in your string easily enough (String.toCharArray()) and build up your replacement String (using a StringBuilder, StringBuffer, new array of chars - whatever you like). If you ignore the hyphens you just need to chuck in a hyphen every five characters in your new string. If the strings are variable length you may have to do a little arithmetic up front to find out where this hyphen should be. A Map will hold your mapped key/value pair - just swap the old value with the value in the Map and append it to the new String.
James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Paul,

Thanks again for your input... Could you elaborate a bit more of what you mean with some sample code?

-James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert Hex into Alphabets and Obfuscate?