This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to convert Hex into Alphabets and Obfuscate?

 
Ranch Hand
Posts: 222
  • 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 ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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: 222
  • 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
Hibernate Eclipse IDE 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: 222
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!