Abstract: Method of generating a copy detection pattern (CDP), or a portion of a CDP, for printing on a substrate, comprising: generating a plurality of digital files, each of an image comprising an at least partially random two dimensional (2D) distribution of dark and light pixels, and applying an optimization process configured to increase a copy detection performance of a resultant digital file output by the method, said optimization process comprising a) comparing a copy detection performance of a first of said plurality of digital files, which constitutes a test digital file, with a copy detection performance of another of said plurality of digital files modified with respect to said test digital file, which constitutes a modified digital file, b) replacing the test digital file with said modified digital file, if the copy detection performance of said modified digital file is greater than the copy detection performance of the test digital file, in which case the modified digital file becomes the test digital fil