Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert Hex into Alphabets and Obfuscate?

 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any reason why you don't just call the toUpperCase() method of String?
 
James Dekker
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,

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

-James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic