Пример #1
0
// Works for 26bits.
int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {

	uint8_t pre[128];
	memset(pre, 0x00, sizeof(pre));

	// format start bit
	pre[79] = 1;
	
	// Get 26 wiegand from FacilityCode, CardNumber	
	uint8_t wiegand[24];
	memset(wiegand, 0x00, sizeof(wiegand));
	num_to_bytebits(fc, 8, wiegand);
	num_to_bytebits(cn, 16, wiegand+8);

	// add wiegand parity bits (dest, source, len)
	wiegand_add_parity(pre+80, wiegand, 24);
	
	// add paritybits	(bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
	addParity(pre+8, pyramidBits+8, 102, 8, 1);

	// add checksum		
	uint8_t csBuff[13];
	for (uint8_t i = 0; i < 13; i++)
		csBuff[i] = bytebits_to_byte(pyramidBits + 16 + (i*8), 8);

	uint32_t crc = CRC8Maxim(csBuff, 13);
	num_to_bytebits(crc, 8, pyramidBits+120);
	return 1;
}
Пример #2
0
int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {

	uint8_t pre[128];
	memset(pre, 0x00, sizeof(pre));

	// preamble  1111 1111 10 = 0xFF8
	num_to_bytebits(0xFF8, 12, pre);

	// fixed tagtype code?  0010 1101 = 0x2D
	num_to_bytebits(0x2D, 8, pre+10);
	
	// 46 encrypted bits - UNKNOWN ALGO
	//    -- 16 bits checksum. Should be 4x4 checksum,  based on UID and 2 constant values.
	//    -- 30 bits undocumented?  
	//num_to_bytebits(cn, 46, pre+18);

	//----from this part, the UID in clear text, with a 1bit ZERO as separator between bytes.
	pre[64] = 0;
	pre[73] = 0;
	pre[82] = 0;
	pre[91] = 0;
	pre[100] = 0;
	pre[109] = 0;
	pre[118] = 0;
	
	// cardnumber (uid)
	num_to_bytebits( (cn >>  0) & 0xFF, 8, pre+65);
	num_to_bytebits( (cn >>  8) & 0xFF, 8, pre+74);
	num_to_bytebits( (cn >> 16) & 0xFF, 8, pre+83);

	// two ?
	num_to_bytebits( 0, 8, pre+92);
	num_to_bytebits( 0, 8, pre+101);
	
	// chksum 
	num_to_bytebits( (0 >> 0) & 0xFF, 8, pre+110);
	num_to_bytebits( (0 >> 8) & 0xFF, 8, pre+119);	

	
	// add paritybits	(bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
	addParity(pre, pre+64, 64, 8, 1);
	addParity(pre+64, pre+64, 64, 8, 1);

	pre[63] = GetParity( DemodBuffer, EVEN, 63);
	pre[127] = GetParity( DemodBuffer+64, EVEN, 63);
	
	memcpy(nedapBits, pre, 128);

	// 1111111110001011010000010110100011001001000010110101001101011001000110011010010000000000100001110001001000000001000101011100111
	return 1;
}