Input: watermark relational database , parameters , Mid and two pairs,
      (PP1, CZP1) and (PP2, CZP2).
Output: Watermarked status true, false}, recover the original database
(1) = Tuple_Selection ;
(2) foreach tuple do
(3) attribute_index mod // selected attribute
(4) mark_bit mod // determine mark bit
(5) = Get2digits( );
(6) insert into Seq;
(7) insert imb into Mark_Seq; //save index of the corresponding mark bit
(8)    end foreach;
(9)    Dif_Seq = Diff(Seq, Mid); // compute the difference sequence Dif_Seq
(10) for to do
(11) ; //reset watermark data
(12) count 0 = 0; count 1 = 0; //reset votes for to be 0, 1 respectively
(13) end for;
(14) for to do
(15) if = PP1, then count Mark_Seq , 0 += 1;
(16) else
(17) if = PP1 − 1, then count Mark_Seq , 1 += 1;
(18)           end if;
(19) if <= PP1 − 1, then = + 1;
(20)          end if;
(21) end if;
(22) if = PP2, then count Mark_Seq , 0 += 1;
(23) else
(24)           if = PP2 + 1, then count Mark_Seq , 1 += 1;
(25)           end if;
(26)           if >= PP2 + 1, then ;
(27)           end if;
(28) end if;
(29) end for;
(30) for to do
(31) if count 0 + count 1 = 0 then ;
(32)   end if;
(33) if count 1 /(count 1 + count 1 ) > then ;
(34)   else ;
(35)   end if;
(36) end for;
(37) Regenerate the original watermark data ; // using (4)
(38) for to do //find the match between original watermark and
        detected watermark if then matchcount += 1;
(39)          end if;
(40) end for;
(41) if matchcount = , then
(42)   return true; // suspected relational database is recovered successfully
(43) else
(44)   return false; // suspected relational database cannot be recovered
(45) end if;
Algorithm 3: Watermark detection.