Hashids and Perceptual hashes

Hashids and Perceptual hashes

PHP Ghent presentation

B4e6cd606ce4f2122d78f259e46ea64a?s=128

Jens Segers

April 29, 2015
Tweet

Transcript

  1. None
  2. @jenssegers Jens Segers

  3. Hashids hashids/hashids

  4. youtube.com/watch?v=dQw4w9WgXcQ

  5. Why id obfuscation? Hiding application internals Reduces chance for URL

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

    = new Hashids\Hashids('salt'); $decodedId = $hashids->decode('Mj3')[0]; Decoding ids
  7. Perceptual hashes jenssegers/imagehash

  8. Removing thumbnails and duplicate images

  9. #b40b2980dcbd08a #c1e9ee950f0e56cc Different from cryptographic hashing

  10. Perceptual fingerprint No avalanche effect Comparing hashes Similar images =

    similar hashes
  11. Hamming Distance Number of different individual bits gmp_hamdist(0b10100110001, 0b10100110101) =

    1
  12. None
  13. None
  14. None
  15. None
  16. 0000000000000010000000110000011100001111000111110110111111111111

  17. 0000000000000010000000110000011100001111000111110110111111111111 1011000110001000111110000000010100100111110100000100010100001010

  18. 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');
  19. 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
  20. @jenssegers Jens Segers