Skip to content

Instantly share code, notes, and snippets.

@kodekracker
Forked from dariushoule/pseudo_enc_bigint.sql
Created September 19, 2020 16:49
Show Gist options
  • Select an option

  • Save kodekracker/17cfd04c4f42e6dca5005845ea839bf5 to your computer and use it in GitHub Desktop.

Select an option

Save kodekracker/17cfd04c4f42e6dca5005845ea839bf5 to your computer and use it in GitHub Desktop.

Revisions

  1. Darius Houle created this gist Apr 11, 2016.
    20 changes: 20 additions & 0 deletions pseudo_enc_bigint.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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;