Skip to content

Instantly share code, notes, and snippets.

@123jimin
Created August 24, 2016 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 123jimin/0ebabe54fc06b445dffdcc61c376ef13 to your computer and use it in GitHub Desktop.
Save 123jimin/0ebabe54fc06b445dffdcc61c376ef13 to your computer and use it in GitHub Desktop.
KONAMI eAMUSEMENT Visual Verification Image Classifier
#!/usr/bin/env node
/*
Instruction
1. Download raw (100x100 png) image files.
2. Execute ./classify.js foo.png bar.png baz.png
3. The output is the concatenation of characters reperesenting classes of each images.
4. ...?
5. Profit!!!
*/
var fs = require('fs');
var data = (function(str){
var obj = {};
str.split(',').forEach(function(x){obj[x.slice(0, 8)] = x[8];});
return obj;
})("0b194f96b,0c982f58t,0eb6b657t,159a50bdl,28219a6cs,2e5e5f2ds,2efead89g,379ef53dl,"
+ "40103a67l,41401bebb,42e289bcg,4934db3dg,5839f804s,58cd383bl,7aef48fcl,8882c122s,89b8fdf5b,"
+ "8d812abbb,8f84a3ddt,92165cbcg,94eef3c2s,9cec59dbb,9e0e9e67t,b0cd8626t,c103674dg,c907addeb,"
+ "cca180c5s,ccb8dd81l,de9e6e0ct,e109bd81g,e5c4d054g");
var hash = function(buffer){
var value = 0x9ABC123F;
var i;
for(i=buffer.length-1; i>=0 && i%4 != 3; i--)
value ^= buffer[i]<<((i%4)*8);
for(i=0; i+3<buffer.length; i+=4)
value ^= buffer.readUInt32LE(i, true);
if(value < 0) value += 0x100000000;
value = value.toString(16);
while(value.length < 8) value = '0'+value;
return value;
};
var classify = function(buffer){
return data[hash(buffer)] || '_';
};
if(process.argv.length <= 2){
console.error("Usage: ./classify.js file1.png file2.png ...");
}
console.log(process.argv.slice(2).map(function(f){
return classify(fs.readFileSync(f));
}).join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment