Skip to content

Instantly share code, notes, and snippets.

@ryonsherman
Last active January 3, 2016 19:49
Show Gist options
  • Select an option

  • Save ryonsherman/c0c1000c55140eef43f3 to your computer and use it in GitHub Desktop.

Select an option

Save ryonsherman/c0c1000c55140eef43f3 to your computer and use it in GitHub Desktop.
Generates a hashtable containing the sha256 hash of a 10 character string containing every permutation of a combintaion of two letters, one upper-case and one lower-case.
#/usr/bin/env php
<?php
/*
Generates a hashtable containing the sha256 hash of
a 10 character string containing every permutation of
a combintaion of two letters, one upper-case and
one lower-case.
Example:
...
0b1eb7703a4e5438a489ea9a17c3b4bd3722d0a638743095176ff8f39b86dbb0 iiiAAiAiAA
7231b77b41388c1c475345e58770d88f88970a8812a6865e108af9ed785de085 iiiAAiiAAA
0845fc00cc34acdd16725504d6432bd4d2bc85a48965217db3a37adfdcf58318 iiiAiAAAAi
dbcecb83a888217e9c3f9708052061c44d5b96e9d23b7c73f748ea960755cd47 iiiAiAAAiA
5a1f1a1cb5c4e2eaa4c32bbcf775d3487703a5f8f7ecf0983292a555d57679ca iiiAiAAiAA
4a5776798a1bfba6d61c8b1a0e00c38c92b3fd8dca7e44ca5ec5bfad0a9ca329 iiiAiAiAAA
234df3355fbffdff8996d235bebe225ad5d924b6b321e32da930bd00a5936bcb iiiAiiAAAA
c8039ee9cb88e2f5d4f5e9e24eb8ee5b4870d762e62f04b43e3f0b3683c961b3 iiiiAAAAAi
b96ec4863def4bc469a9f70d7a7c39e522e0c604bbc4a2540c110da0424f11a2 iiiiAAAAiA
...
*/
ini_set('memory_limit', '2G');
function permute($str) {
$perms = array();
if (strlen($str) < 2) return array($str);
foreach (permute(substr($str, 1)) as $perm)
for ($i = 0; $i <= strlen($perm); $i++)
$perms[] = substr($perm, 0, $i).$str[0].substr($perm, $i);
return $perms;
}
function genhash($high, $low) {
print "Generating {$high}:{$low}\n";
for ($i = 1; $i < 10; $i++)
foreach (array_unique(permute(str_repeat($high, $i).str_repeat($low, 10 - $i))) as $value)
file_put_contents('hashtable', hash('sha256', $value)." ".$value."\n", FILE_APPEND) ;
}
file_put_contents('hashtable', '');
for ($high = ord('A'); $high <= ord('Z'); $high++)
for ($low = ord('a'); $low <= ord('z'); $low++)
genhash(chr($high), chr($low));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment