Blockchain IoT Example "Iris Contract"

In this post i will be creating a contract that works with a device (a device that can acquire your IRIS (EYE) Data and use it for Unlocking or Security.

How is it an IoT? Source
The Internet of things (IoT) is the network of physical devices, vehicles, home appliances, and other items embedded with electronicssoftwaresensorsactuators, and network connectivity which enable these objects to connect and exchange data.

There are many Cheap Hardware devices currently in the market that can provide and Iris Code.
One of these devices is the Samsung Note 7 that has a built in Iris Scanner for Unlocking Phone as a Secondary Authentication  Source

So assuming i have the hardware that can get My Iris Scanned.
What will be the output of this Hardware? How do iris Scan work?

 identifies around 240 unique features (about five times more "points of comparison" as fingerprint systems use). These features, unique to every eye, are turned into a simple, 512-digit number called an IrisCode® that is stored, alongside your name and other details, in a computer database.

so we have a 512 digit number. depending on the hardware it may be of longer length. Our Assumption for now is the 512 digit number.

Since each device saves their own Iris data and compares it. we are going to save this in the blockchain and do a comparison.

A well known comparison for iris data is the Hamming Distance.

the Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
So the lower the number on the hamming distance, the closer 2 data are to each other. A hamming distance of zero, shows an exact match. Here are some examples:


The Hamming distance between:
  • "karolin" and "kathrin" is 3.
  • "karolin" and "kerstin" is 3.
  • 1011101 and 1001001 is 2.
  • 2173896 and 2233796 is 3.

So lets start the Solidity Contract





pragma solidity ^0.4.18;

contract IoTAresh {
    
    address public owner; 
    struct device
    {
        string DeviceID;
        string iris;  //512 length IrisCode
    }
   
    device[] AllDevices;
    uint count;
    
    function IoTAresh() public {
        owner = msg.sender;
        count = 0;
    }
    
    function Register(string _deviceid, string _iris) public{
        AllDevices.push(device(_deviceid, _iris));
        count++;
    }
    
    function Find(uint _index, string _iris) public constant returns (uint){
        device storage temp = AllDevices[_index];
        return HammingDistance(temp.iris, _iris);
    }
    
    function HammingDistance(string storage _a, string memory _b)  internal view returns (uint) {
        bytes storage a = bytes(_a);
        bytes memory b = bytes(_b);
        uint counter =0;
        if (a.length != b.length)
            return 100; //large number
        for (uint i = 0; i < a.length; i ++)
        {
            if (a[i] != b[i])
            {
                counter++; //count the number of times its not a match
            }
        }
        return counter;
    }
}

Comments

Popular posts from this blog

Solidity Hash of Structs (Testing hash uniqueness)

Is Making the Crypto Space Legally Compliant Paving the Road to Mass (Blockchain) Adoption?

Parity installation on Ubuntu Virtual Machine