import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.String;
import java.io.*;

public class Verifier{
    long[][] userInput;
    long[][] userData;
    
    public Verifier(File input, File data){
        userInput = this.fileToArray(input);
        userData  = this.fileToArray(data);
    }

    boolean verifyUser(int degError){
        long diff;
        long absdiff;
        boolean authenticate = true;
        for (int i = 0; i < 26; i++){
            for (int j = 0; j < 26; j++){
                diff = this.userInput[i][j] - this.userData[i][j];
                absdiff = Math.abs(diff);
                
                /**TO COLLECT EMPIRICAL DATA ONLY**/
                if (absdiff > 0){
                System.out.println("i = " + i + " j = " +j);
                System.out.println("Difference is : " + absdiff);
                }
                /**END**/
                
                if (absdiff > degError){
                    authenticate = authenticate && false;
                }
                else
                    authenticate = authenticate && true;
            }
        }
        return authenticate;
    }
    
    long[][] fileToArray(File fileData){
        String strLong = new String();
        Long objLong;
        long[][] retArray = new long[26][26];
        int i,j;
        BufferedReader b;
        FileReader f;
        try{
            b = new BufferedReader(new FileReader(fileData));
             
            for (i = 0; i < 26; i++){
                for (j = 0; j < 26; j++){
                    try{
                        strLong = b.readLine();
                    }
                    catch(IOException ie){
                        System.out.println("At end of file.");
                    }
                    objLong = new Long(strLong);
                    retArray[i][j] = objLong.longValue();
                }
            } 
        }
        catch(FileNotFoundException fe){
            System.out.println("File does not exist.");
            
        }
        return retArray;
    }

    public static void main(String[] args){
        File j1 = new File(args[0]);
        File j2 = new File(args[1]);
        Integer intDegError = new Integer(args[2]);
        int degError = intDegError.intValue();
        Verifier v = new Verifier(j1, j2);
        String tempString = new String();
        boolean sameUser;
        for (int i = 0; i < 26; i++){
            for (int j = 0; j < 26; j++){
                tempString = tempString + v.userInput[i][j] + '\t';
            }
            System.out.println(tempString);
            tempString = new String();
        }
        sameUser = v.verifyUser(degError);
        System.out.println("This is the same user : " + sameUser);
    }
            
}
