#include "spn.h"

void calc_inv_perm(unsigned char perm[8],unsigned char inv_perm[8])
{
	// TODO
}

void calc_inv_subst(unsigned char subst[16],unsigned char inv_subst[16])
{
	// TODO
}

unsigned char do_perm(unsigned char w,unsigned char perm[8])
{
	unsigned char pw = 0; // permuted byte
	int i;
	unsigned char mask = 0x1;
	unsigned char bit;
	unsigned char place;

	for(i=0;i<8;i++){
		bit=w&mask;
		place=perm[i];
		pw |= bit<<place;
		w>>=1;
	}

	return pw;
}

unsigned char do_subst(unsigned char w,unsigned char subst[16])
{
	unsigned char sw=0;

	// TODO
	return sw;
}

unsigned char encrypt(
		unsigned char w, 
		unsigned  key,
		unsigned char perm[8],
		unsigned char subst[16])
{
	unsigned char k0=key&0xff;
	unsigned char k1=(key>>8)&0xff;
	unsigned char k2=(key>>16)&0xff;

	// TODO

	return w;
}
unsigned char decrypt(
		unsigned char w, 
		unsigned short key,
		unsigned char perm[8],
		unsigned char subst[16])
{
	unsigned char k0=key&0xff;
	unsigned char k1=(key>>8)&0xff;
	unsigned char k2=(key>>16)&0xff;

	// TODO

}

