Hashids and Perceptual hashes

Hashids and Perceptual hashes

PHP Ghent presentation

Jens Segers

April 29, 2015

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

20 slides
  1. Why id obfuscation? Hiding application internals Reduces chance for URL

    guessing Hide number of users, articles, … More difficult for scrapers
  2. Encoding ids $hashids = new Hashids\Hashids('salt'); $encodedId = $hashids->encode(123); $hashids

    = new Hashids\Hashids('salt'); $decodedId = $hashids->decode('Mj3')[0]; Decoding ids
  3. Calculating the hash Using a different implementation: use Jenssegers\ImageHash\ImageHash; $hasher

    = new ImageHash; $hash = $hasher->hash('path/to/image.jpg'); use Jenssegers\ImageHash\Implementation\AverageHash; $hasher = new ImageHash(new AverageHash); $hash = $hasher->hash('path/to/image.jpg');
  4. Comparing hashes Or use your database: $d = $hasher->compare('image1.jpg', 'image2.jpg');

    $d = $hasher->distance($hash1, $hash2); SELECT BIT_COUNT(hash ^ :hash) as hamming_distance FROM images HAVING hamming_distance < 5

More Decks by Jens Segers

Other Decks in Technology