Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:47:06+00:00 2026-05-27T21:47:06+00:00

I’m trying to implement an collision attack on hashes (I’m visiting the course ‘cryptography’).

  • 0

I’m trying to implement an collision attack on hashes (I’m visiting the course ‘cryptography’). Therefore I have two arrays of hashes (= byte-sequences byte[]) and want to find hashes which are present in both arrays. After some research and a lot of thinking I am sure that the best solution on a single-core machine would be a HashSet (add all elements of the first array and check via contains if elements of the second array are already present).

However, I want to implement a concurrent solution, since I have access to a machine with 8 cores and 12 GB RAM. The best solution I can think of is ConcurrentHashSet, which could be created via Collections.newSetFromMap(new ConcurrentHashMap<A,B>()). Using this data structure I could add all elements of the first array in parallel and – after all elements where added – I can concurrently check via contains for identical hashes.

So my question is: Do you know an algorithm designed for this exact problem? If not, do you have experience using such a ConcurrentHashSet concerning problems and effective runtime complexity? Or can you recommend another prebuilt data structure which could help me?

PS: If anyone is interested in the details: I plan to use Skandium to parallelize my program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:47:06+00:00Added an answer on May 27, 2026 at 9:47 pm

    I think it would be a complete waste of time to use any form of HashMap. I am guessing you are calculating multi-byte hashes of various data, these are already hashes, there is no need to perform any more hashing on them.

    Although you do not state it, I am guessing your hashes are byte sequences. Clearly either a trie or a dawg would be ideal to store these.

    I would suggest therefore you implement a trie/dawg and use it to store all of the hashes in the first array. You could then use all of your computing power in parallel to lookup each element in your second array in this trie. No locks would be required.

    Added

    Here’s a simple Dawg implementation I knocked together. It seems to work.

    public class Dawg {
      // All my children.
      Dawg[] children = new Dawg[256];
      // Am I a leaf.
      boolean isLeaf = false;
    
      // Add a new word.
      public void add ( byte[] word ) {
        // Finds its location, growing as necessary.
        Dawg loc = find ( word, 0, true );
        loc.isLeaf = true;
      }
    
      // String form.
      public void add ( String word ) {
        add(word.getBytes());
      }
    
      // Returns true if word is in the dawg.
      public boolean contains ( byte [] word ) {
        // Finds its location, no growing allowed.
        Dawg d = find ( word, 0, false );
        return d != null && d.isLeaf; 
      }
    
      // String form.
      public boolean contains ( String word ) {
        return contains(word.getBytes());
      }
    
      // Find the Dawg - growing the tree as necessary if requested.
      private Dawg find ( byte [] word, int i, boolean grow ) {
        Dawg child = children[word[i]];
        if ( child == null ) {
          // Not present!
          if ( grow ) {
            // Grow the tree.
            child = new Dawg();
            children[word[i]] = child;
          }
        }
        // Found it?
        if ( child != null ) {
          // More to find?
          if ( i < word.length - 1 ) {
            child = child.find(word, i+1, grow);
          }
        }
        return child;
      }
    
      public static void main ( String[] args ) {
        Dawg d = new Dawg();
        d.add("H");
        d.add("Hello");
        d.add("World");
        d.add("Hell");
        System.out.println("Hello is "+(d.contains("Hello")?"in":"out"));
        System.out.println("World is "+(d.contains("World")?"in":"out"));
        System.out.println("Hell is "+(d.contains("Hell")?"in":"out"));
        System.out.println("Hal is "+(d.contains("Hal")?"in":"out"));
        System.out.println("Hel is "+(d.contains("Hel")?"in":"out"));
        System.out.println("H is "+(d.contains("H")?"in":"out"));
      }
    }
    

    Added

    This could be a good start at a concurrent lock-free version. These things are notoriously difficult to test so I cannot guarantee this will work but to my mind it certainly should.

    import java.util.concurrent.atomic.AtomicReferenceArray;
    
    
    public class LFDawg {
      // All my children.
      AtomicReferenceArray<LFDawg> children = new AtomicReferenceArray<LFDawg> ( 256 );
      // Am I a leaf.
      boolean isLeaf = false;
    
      // Add a new word.
      public void add ( byte[] word ) {
        // Finds its location, growing as necessary.
        LFDawg loc = find( word, 0, true );
        loc.isLeaf = true;
      }
    
      // String form.
      public void add ( String word ) {
        add( word.getBytes() );
      }
    
      // Returns true if word is in the dawg.
      public boolean contains ( byte[] word ) {
        // Finds its location, no growing allowed.
        LFDawg d = find( word, 0, false );
        return d != null && d.isLeaf;
      }
    
      // String form.
      public boolean contains ( String word ) {
        return contains( word.getBytes() );
      }
    
      // Find the Dawg - growing the tree as necessary if requested.
      private LFDawg find ( byte[] word, int i, boolean grow ) {
        LFDawg child = children.get( word[i] );
        if ( child == null ) {
          // Not present!
          if ( grow ) {
            // Grow the tree.
            child = new LFDawg();
            if ( !children.compareAndSet( word[i], null, child ) ) {
              // Someone else got there before me. Get the one they set.
              child = children.get( word[i] );
            }
          }
        }
        // Found it?
        if ( child != null ) {
          // More to find?
          if ( i < word.length - 1 ) {
            child = child.find( word, i + 1, grow );
          }
        }
        return child;
      }
    
      public static void main ( String[] args ) {
        LFDawg d = new LFDawg();
        d.add( "H" );
        d.add( "Hello" );
        d.add( "World" );
        d.add( "Hell" );
        System.out.println( "Hello is " + ( d.contains( "Hello" ) ? "in" : "out" ) );
        System.out.println( "World is " + ( d.contains( "World" ) ? "in" : "out" ) );
        System.out.println( "Hell is " + ( d.contains( "Hell" ) ? "in" : "out" ) );
        System.out.println( "Hal is " + ( d.contains( "Hal" ) ? "in" : "out" ) );
        System.out.println( "Hel is " + ( d.contains( "Hel" ) ? "in" : "out" ) );
        System.out.println( "H is " + ( d.contains( "H" ) ? "in" : "out" ) );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.