Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
A fast implementation of the Aho-Corasick algorithm using the compact double-array data structure
daachorse is a fast implementation of the Aho-Corasick algorithm using the compact double-array data structure. This is a Python wrapper.
Run the following command:
$ pip install daachorse
You need to install the Rust compiler following the documentation beforehand.
daachorse uses pyproject.toml
, so you also need to upgrade pip to version 19 or later.
$ pip install --upgrade pip
After setting up the environment, you can install daachorse as follows:
$ pip install git+https://github.com/daac-tools/python-daachorse
Daachorse contains some search options, ranging from basic matching with the Aho-Corasick algorithm to trickier matching. All of them will run very fast based on the double-array data structure and can be easily plugged into your application as shown below.
To search for all occurrences of registered patterns
that allow for positional overlap in the input text,
use find_overlapping()
. When you instantiate a new automaton,
unique identifiers are assigned to each pattern in the input order.
The match result has the character positions of the occurrence and its identifier.
>> import daachorse
>> patterns = ['bcd', 'ab', 'a']
>> pma = daachorse.Automaton(patterns)
>> pma.find_overlapping('abcd')
[(0, 1, 2), (0, 2, 1), (1, 4, 0)]
If you do not want to allow positional overlap, use find()
instead.
It performs the search on the Aho-Corasick automaton
and reports patterns first found in each iteration.
>> import daachorse
>> patterns = ['bcd', 'ab', 'a']
>> pma = daachorse.Automaton(patterns)
>> pma.find('abcd')
[(0, 1, 2), (1, 4, 0)]
If you want to search for the longest pattern without positional overlap in each iteration,
use MATCH_KIND_LEFTMOST_LONGEST
in the construction.
>> import daachorse
>> patterns = ['ab', 'a', 'abcd']
>> pma = daachorse.Automaton(patterns, daachorse.MATCH_KIND_LEFTMOST_LONGEST)
>> pma.find('abcd')
[(0, 4, 2)]
If you want to find the the earliest registered pattern
among ones starting from the search position,
use MATCH_KIND_LEFTMOST_FIRST
.
This is so-called the leftmost first match, a bit tricky search option.
For example, in the following code,
ab
is reported because it is the earliest registered one.
>> import daachorse
>> patterns = ['ab', 'a', 'abcd']
>> pma = daachorse.Automaton(patterns, daachorse.MATCH_KIND_LEFTMOST_FIRST)
>> pma.find('abcd')
[(0, 2, 0)]
Licensed under either of
at your option.
FAQs
A fast implementation of the Aho-Corasick algorithm using the compact double-array data structure
We found that daachorse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.