Re:The SHA256 for this sentence begins with: one, eight, two...
by Twirrim on Monday September 11, 2023 @12:49PM
(#37469989)
You can wrap tqdm around the "permutations(TOKENS, k)" if you want to measure progress. I haven't spent time trying to make this particularly optimised, for example that dict lookup is likely avoidable with a little bit of work via index lookup, and maybe cheaper. I've also not attempted to parallelise it, which would be fairly easy to do.
[ Parent
| on HN ]
Re:The SHA256 for this sentence begins with: one, eight, two...
by rainsford on Monday September 11, 2023 @08:21PM
(#37475447)
This is an interesting starting point for a python implementation, but it doesn't work correctly as far as I can tell. The list of tokens leaves out zero and includes a bunch of ascii characters that aren't valid hex. That second problem won't produce wrong results, but it'll spend a lot of time testing combinations that can't possibly appear in a SHA256 hex output. I also think the original tweet calculated without a newline.
More significantly, permutation in python is probably not the right tool for this. I believe it will not repeat token values at different positions, so for example you'll never end up testing "The SHA256 for this sentence begins with: f, f, and f", which is certainly a potentially valid result.
Re:The SHA256 for this sentence begins with: one, eight, two...
by Twirrim on Tuesday September 12, 2023 @06:11PM
(#37489275)
> The list of tokens leaves out zero and includes a bunch of ascii characters that aren't valid hex
I rewrote it in rust last night and realised that, yeah. Lots of wasted time on irrelevant characters.
>permutation in python is probably not the right tool for this.
Correct, missed that. I need `itertools.product(<iterable>, repeat=2)`