Created
August 16, 2021 16:43
-
-
Save jasonrhaas/078a7db95c561bb8446eab5b5b1edc9a to your computer and use it in GitHub Desktop.
feistel bigint
This file contains hidden or 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
CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$ | |
DECLARE | |
l1 bigint; | |
l2 bigint; | |
r1 bigint; | |
r2 bigint; | |
i int:=0; | |
BEGIN | |
l1:= (VALUE >> 32) & 4294967295::bigint; | |
r1:= VALUE & 4294967295; | |
WHILE i < 3 LOOP | |
l2 := r1; | |
r2 := l1 # ((((1366.0 * r1 + 150889) % 714025) / 714025.0) * 32767*32767)::int; | |
l1 := l2; | |
r1 := r2; | |
i := i + 1; | |
END LOOP; | |
RETURN ((r1::bigint << 32) + l1); | |
END; | |
$$ LANGUAGE plpgsql strict immutable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment