#include <stdio.h>

int main()
{
	int sbox[16][8] = 
	{
		{0,0,0,0,1,0,1,1},
		{0,0,0,1,0,0,1,0},
		{0,0,1,0,0,1,1,1},
		{0,0,1,1,1,1,0,0},
		{0,1,0,0,0,0,0,1},
		{0,1,0,1,1,1,1,1},
		{0,1,1,0,0,0,0,0},
		{0,1,1,1,1,0,0,0},
		{1,0,0,0,1,1,1,0},
		{1,0,0,1,0,1,0,0},
		{1,0,1,0,0,1,0,1},
		{1,0,1,1,1,0,0,1},
		{1,1,0,0,0,1,1,0},
		{1,1,0,1,1,0,1,0},
		{1,1,1,0,0,0,1,1},
	    {1,1,1,1,1,1,0,1}
	};

	int test[8] = {0,0,0,0,0,0,0,0};
	
	int count1;
	int count2;
	int check;
	int number;
	float bias;
	
	printf("X1 X2 X3 X4 Y1 Y2 Y3 Y4 : bias\n");

	/* Do test until all possible 256 tests are completed */

	while(test[0] != 1 || test[1] != 1 || test[2] != 1 || test[3] != 1 || test[4] != 1 || test[5] != 1 || test[6] != 1 || test[7] != 1) {

		/* Increment test block */
		if(test[7] == 1) {
			test[7] = 0;
			if(test[6] == 1) {
				test[6] = 0;
				if(test[5] == 1) {
					test[5] = 0;
					if(test[4] == 1) {
						test[4] = 0;
						if(test[3] == 1) {
							test[3] = 0;
							if(test[2] == 1) {
								test[2] = 0;
								if(test[1] == 1) {
									test[1] = 0;
									if(test[0] == 1) {
										test[0] = 0;
									} else {
										test[0] = 1;
									}
								} else {
									test[1] = 1;
								}
							} else {
								test[2] = 1;
							}
						} else {
							test[3] = 1;
						}
					} else {
						test[4] = 1;
					}
				} else {
					test[5] = 1;
				}
			} else {
				test[6] = 1;
			}
		} else {
			test[7] = 1;
		}

		number = 0;
		for(count1 = 0; count1 <= 15; count1++) {
			check = 0;
			for(count2 = 0; count2 <= 7; count2++) {
				if(test[count2] == 1) {
					check = (check + sbox[count1][count2]) % 2;
				}
			}

			if(check == 0) {
				number++;
			}
		}

			bias = (((float)number)/16) - 0.5;
			printf("%d  %d  %d  %d  %d  %d  %d  %d  : %f\n", test[0], test[1], test[2], test[3], test[4], test[5], test[6], test[7], bias);
	}

	return 0;
}

