Created
September 5, 2015 00:11
-
-
Save snoble/c30c53312cfe3f722df4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH input AS (SELECT MD5('some input string') AS input, 20 AS modulo), | |
mods AS ( | |
SELECT | |
STRTOL(SUBSTRING(input,1,8),16) % modulo AS a, | |
STRTOL(SUBSTRING(input,9,8), 16) % modulo AS b, | |
STRTOL(SUBSTRING(input,17,8), 16) % modulo AS c, | |
STRTOL(SUBSTRING(input,25,8), 16) % modulo AS d, | |
POW(POW(16 % modulo, 4)::INT % modulo, 2)::INT % modulo AS offset_multiplier, | |
modulo | |
FROM input) | |
SELECT ((((a * offset_multiplier) + b) * offset_multiplier + c) * offset_multiplier + d) % modulo AS result | |
FROM mods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment