Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

searching for possible word

 
Gary Goldsmith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a dictionary loaded into a hashmap, and I have a partial decrypted word. What I want to know is how do I enter a string (e.g. atteJFtiHU) lowercase letters are known letters and uppercase are still crypted letters. And search the dictionary on possible matches. Maybe the first question should be is a hashmap a good way to go about this or would a linkedlist be better? So I want to say here's my string 'atteJFtiHU' and have it return saying this is the list of possible matches e.g. 'attempting'. Any advice would be greatly received.
 
Gary Goldsmith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have so far, but returns a nullPointerException, and I'm not sure it's going to do what I expect it to.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dictionary.get is not doing what you think it does. Read the javadoc for Map/HashMap carefully.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your dictionary map contains entries that have equal keys and values, you chould switch to a Set<String> instead, using HashSet<String> as implementation:

 
Gary Goldsmith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, that was a big improvement on my old code, the only thing is it's not able to work out the partially decrypted word, if I say:
String strToCompare = "attempting";
Then it returns it from the set, but if I pass in:
String strToCompare = "atteJFtiHU";
Then nothing happens, how can I search the Set for a word that is a possible match to "atteJFtiHU" - lowerCase letters are letters that have been worked out uppercase are letters that haven't been worked out yet.
 
Gary Goldsmith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help, I have now worked out the problem

Thanks for your help.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Gary Goldsmith:]   Thank you for your help, I have now worked out the problem

Well can we see the code ? Some others are working on this same problem (me) and a fast, efficient decryption approach is always of interest in the matter - such as maintaining a precompiled TreeSet of Patterns for working through Collections of junk mail looking for the markers that Oscar De Grouch should have a chance at.
[ November 25, 2007: Message edited by: Nicholas Jordan ]
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:



I think you're having a regex issue. I think you want your string to compare to have a '.' (period) where you need to match any character. Thus:


[ November 26, 2007: Message edited by: Bill Shirley ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic