"Sputnik" help  
Sputnik Help
CrcHash(<size>, <tweak>, <rounds>, <factor>, <data>, [<polynomial>], [<reverseIn>], [<reverseOut>])


Generates a tweakable hash using the CRC64 algorithm with additional tweaks for enhanced variability. The resulting hash is of the specified size and influenced by the provided parameters.


<hash> The size of the output hash.
<tweak> A tweakable value (64-bit integer) influencing the hash.
<rounds> The number of rounds for additional processing after initial hashing.
<factor> The number of rounds for additional processing while hashing.
<data> The input data (string/binary/numbers/arrays etc) to be hashed.
<polynomial> Optional. The tweakable value polynomial (64-bit integer) used for CRC64 calculation. (Default: @Crc64Poly)
<reverseIn> Optional. A tweakable value boolean indicating whether to reverse the input data when calculating the CRC64 table from the polynomial. (Default: false)
<reverseOut> Optional. A tweakable value boolean indicating whether to reverse the output when calculating the CRC64 table from the polynomial. (Default: false)

Return Value

Success: Returns a string representing the generated hash.
Failure: Returns an empty string.


The CrcHash function is a robust hashing algorithm that employs the CRC64 algorithm with tweakable parameters, offering a high level of customization and security. Tweakability is achieved through several parameters, including the tweak, rounds, factor, polynomial, and hash size values. Importantly, adjusting any of these parameters results in a significantly different hash output, contributing to the algorithm's uniqueness and security.

The hash size parameter is a crucial component of the tweakability process in CrcHash. Unlike some other hash algorithms, changing the size of the generated hash leads to an entirely different output. This behavior distinguishes CrcHash from algorithms like Whirlpool, which consistently produces the same bytes in sequence irrespective of the requested size. Therefore, in this function, the hash size is considered an integral part of the tweaking process, enhancing the overall unpredictability and security of the generated hash.

Rounds can increased really high without slowing things down too much however the Factor will significantly slow things down when increased too much.




Example of usage:

say CrcHash(16, 0, 1, 1, "Hello World");
// 525F8CD04A1035921D27469242F9775F

say CrcHash(16, 0, 4096, 64, "Hello World");
// 97396A1FC0D2CDA188B147A2D6E1889A

say CrcHash(16, Tb64("MSWord97"), 4096, 64, "Hello World");
// A3C5E734DE72EC6B48F7E984E5E12434

Hashing passwords and verifying the hash:

// a function to handle creating hashes of passwords
Function HashPassword($password)
    return CrcHash(16, Tb64("QTY918@?"), 32767, 128, $password, 0x19AFED42, true, false);

// create the hash of a password
my $pass = "secret password";
my $hash = HashPassword($pass);
say "Hash = $hash";

// confirm the hash of a password
if (HashCmp(HashPassword($pass), $hash))
    say "Password is valid!";
    say "Password is invalid!";

// Hash = 8AB108BBF18171FC65C664984BAB87F5
// Password is valid!

Trying to brute force the CrcHash:

global $base = CrcHash(16, 1337, 1, 1, "Hello");
global $generation = 0;

my $result = ParallelFor(0, 100000000, 1,
    my $str = RandStr(5);
    my $attack = CrcHash(16, 1337, 1, 1, $str);
    if ($attack == $base)
        say "Attack found $str ($attack == $base) \@ generation $generation";
    if (IsDivisible($generation, 10000))
        say "Generations $generation";

// Generations 10053
// Generations 20005
// Generations 30002
// Generations 50007
// Generations 60007
// Generations 70006
// Generations 80006
// Generations 90006
// Generations 90013
// Generations 100005
// Generations 100017

Even attempting to crack a size 4 one would take a very long time but a size 16 will probably take until the death of the universe.

Cheryl (uberfox@hotmail.com)