void test_permute_e()
{
    des_block_t half_block;
    half_block.c = 0xF0AA;
    half_block.d = 0xF0AA;
    des_block_t ep = permute_e(half_block);
    assert(ep.c == 0x7A1555);
    assert(ep.d == 0x7A1555);
}
void decode_ext(const std::vector<int> & msg_decode, const std::vector<int> & msg_old)
{
	int Kc = 5;	//Number of Parity bits(Kc >= 3)
	int M = 3;	//maximum bit error number M(Size of Sphere)

	int ExtHammCode = 1;	//for extended Hamming - Code
	cv::Mat mat_G = bem_hammgen(Kc);

	if (ExtHammCode)	
		mat_G = ext_hamming(mat_G);

	int kc = mat_G.rows;
	int	nc = mat_G.cols; Kc = nc - kc;

	cv::Mat mat_H = gen2par(mat_G);
	cv::Mat mat_HT; cv::transpose(mat_H, mat_HT);

	/*-----------------Permutation of 1, 2 and 3 bit errors----------------*/
	cv::Mat e = permute_e(nc, M);

	 /*----------------syndrome calculation-------------------*/
	cv::Mat syn = cv::Mat(e.rows, Kc, CV_32FC1);
	for (int i = 0; i < e.rows; i++){
		//syn.row(i) = (e.row(i)*mat_HT);
		cv::Mat mat_temp = e.row(i)*mat_HT;
		for (int j = 0; j < mat_temp.cols; j++){
			int _dec = (int)mat_temp.at<float>(0, j);
			syn.at<float>(i, j) = float(_dec % 2);
		}
	}

	/*cv::Mat e_mat;
	cv::FileStorage fs("permute_e.yml", cv::FileStorage::READ);
	fs["Data"] >> e_mat;
	fs.release();

	cv::Mat diff = e_mat != e;
	if (cv::countNonZero(diff) == 0) std::cout << "match\n";*/
}