Exemple #1
0
void Imu::setFilterDataRate(uint16_t decimation, const std::bitset<5>& sources) {
  Imu::Packet p(COMMAND_CLASS_3DM);  //  was 0x04
  PacketEncoder encoder(p);
 
  static const uint8_t fieldDescs[] = { FIELD_QUATERNION,
                                        FIELD_GYRO_BIAS,
                                        FIELD_ANGLE_UNCERTAINTY,
                                        FIELD_BIAS_UNCERTAINTY,
                                        FIELD_GPS_TIMESTAMP};
  assert(sizeof(fieldDescs) == sources.size());
  std::vector<uint8_t> fields;
  
  for (size_t i=0; i < sources.size(); i++) {
    if (sources[i]) {
      fields.push_back(fieldDescs[i]);
    }
  }
  
  encoder.beginField(COMAMND_FILTER_MESSAGE_FORMAT);
  encoder.append(FUNCTION_APPLY, u8(fields.size()));
  
  for (const uint8_t& field : fields) {
    encoder.append(field, decimation);
  }

  encoder.endField();
  p.calcChecksum();
  sendCommand(p);
}
Exemple #2
0
std::vector<std::bitset<ROUND_KEY_SIZE> > generate_round_keys(const std::bitset<KEY_SIZE>& key) {
	std::vector<std::bitset<ROUND_KEY_SIZE> > round_keys;
	// split key into lower and upper half, of 28b
	std::bitset<KEY_SIZE/2> lower;
	std::bitset<KEY_SIZE/2> upper;
	int mid = key.size() / 2;
	for (int i = 0; i < key.size(); i++)
		if (i < mid) lower.set(i, key.test(i));
		else upper.set(i % mid, key.test(i));

	for (int i = 0; i < ROUND_NUM; ++i) {
		// left shift using key_schedule
		lower = (lower << key_schedule[i]);
		upper = (upper << key_schedule[i]);
		// permute using pc_2 table
		
		//combine 28b lower and 28b upper for 56b key
		std::bitset<KEY_SIZE> input_key;
		for (i = 0; i < input_key.size(); ++i) {
			if (i < mid) input_key.set(i, lower.test(i));
			else input_key.set(i, upper.test(i % mid));
		}
		
		// permute using pc_2 table
		std::bitset<ROUND_KEY_SIZE> round_key;
		for (int i = 0; i < pc_2.size(); ++i)
			round_key.set(i, input_key[pc_2[i]]);

		round_keys.push_back(round_key);
	}
	
	return round_keys;
}
Exemple #3
0
void Imu::setIMUDataRate(uint16_t decimation, 
                        const std::bitset<5>& sources) {
  Imu::Packet p(COMMAND_CLASS_3DM);  //  was 0x04
  PacketEncoder encoder(p);
  
  //  valid field descriptors: accel, gyro, mag, pressure
  static const uint8_t fieldDescs[] = { FIELD_ACCELEROMETER, 
                                        FIELD_GYROSCOPE, 
                                        FIELD_MAGNETOMETER, 
                                        FIELD_BAROMETER,
                                        FIELD_GPS_CORRELATION_TIMESTAMP};
  assert(sizeof(fieldDescs) == sources.size());
  std::vector<uint8_t> fields;
  
  for (size_t i=0; i < sources.size(); i++) {
    if (sources[i]) {
      fields.push_back(fieldDescs[i]);
    }
  }
  encoder.beginField(COMMAND_IMU_MESSAGE_FORMAT);
  encoder.append(FUNCTION_APPLY, u8(fields.size()));
  
  for (const uint8_t& field : fields) {
    encoder.append(field, decimation);
  }

  encoder.endField();
  p.calcChecksum();
  sendCommand(p);
}
double BSO::evaluate(std::bitset<chromoLength> paramsBS)
{
	double result = 0.0;
	int chromo[] = {0,0,0,0,0, 0,0,0,0, 0,0,0,0,0, 0,0,0,0,  0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
	int length = paramsBS.size();

    for(int i = 0; i < paramsBS.size(); i++){
	  chromo[i] = paramsBS.at(i);
    }
	
	result = this->sharedMemoryEvaluator->eval(chromo, length);
	return result;
}
Exemple #5
0
// given plain text and key, return cipher text
std::bitset<BLOCK_SIZE> encrypt(const std::bitset<BLOCK_SIZE>& input_text, const std::bitset<INPUT_KEY_SIZE>& input_key, bool encrypt) {
	std::bitset<BLOCK_SIZE> cipher_block;	
	// generate initial key	
	std::bitset<KEY_SIZE> initial_key = generate_initial_key(input_key);
	
	// generate round keys
	std::vector<std::bitset<ROUND_KEY_SIZE> > round_keys = generate_round_keys(initial_key);
	
	// split input text into two blocks of 32b
	std::bitset<BLOCK_SIZE/2> lower; // use lower to represent bits [0,BLOCK_SIZE/2), and
	std::bitset<BLOCK_SIZE/2> upper; // user upper to represent bits [BLOCK_SIZE/2,BLOCK_SIZE)
	int mid = input_text.size() / 2;
	for (int i = 0; i < input_text.size(); i++)
		if (i < mid) lower.set(i, input_text.test(i));
		else upper.set(i % mid, input_text.test(i));
	
	std::bitset<BLOCK_SIZE/2> temp; // temporarily hold lower, so that upper can be used in XOR
	
	// if encryption
	if (encrypt) {
		for (int i = 0; i < ROUND_NUM; ++i) {
			//std::cout << "ROUND " << i << "----------------------------------------" << std::endl;
			//std::cout << "Using key " <<  i << ":\t\t" << round_keys[i] << std::endl;
			temp = copy_bit_pattern(lower); // hold r_i-1 in temp
			lower = perform_round(lower, round_keys[i]);
			lower ^= upper; // r_i = f(r_i-1,key) xor l_i-1
			upper = copy_bit_pattern(temp); // l_i = r_i-1
			std::cout << "ROUND " << i << " ENDED" << "----------------------------------" << std::endl;
		}
	} else {
		// if decryption
		for (int i = ROUND_NUM -1; i >= 0; --i) {
			//std::cout << "ROUND " << i << "----------------------------------------" << std::endl;
			//std::cout << "Using key " <<  i << ":\t\t" << round_keys[i] << std::endl;
			temp = copy_bit_pattern(lower); // hold r_i-1 in temp
			lower = perform_round(lower, round_keys[i]);
			lower ^= upper; // r_i = f(r_i-1,key) xor l_i-1
			upper = copy_bit_pattern(temp); // l_i = r_i-1
			//std::cout << "ROUND " << i << " ENDED" << "----------------------------------" << std::endl;
		}
	}
	
	// perform final swap
	for (int i = 0; i < cipher_block.size(); ++i) {
		if (i < mid) cipher_block.set(i, upper.test(i));
		else cipher_block.set(i, lower.test(i % mid));
	}
	
	return cipher_block;
}
Exemple #6
0
 void setValues(double mix,
                std::bitset<4> aChannels)
 {
     _mix = mix;
     assert(aChannels.size() == 4);
     _aChannels = aChannels;
 }
Exemple #7
0
inline int parity(std::bitset<nBits> bitrep)
{
    int parity = 0;
    for (size_t i = 0; i < bitrep.size(); ++i) {
        parity ^= bitrep[i];
    }
    return parity;
}
Exemple #8
0
void printBitSet(std::bitset<1000> intBitSet)
{
	for(long int i = 0; i < intBitSet.size(); i++)
	{
		if(intBitSet[i] == 1)
			std::cout << i << std::endl;
	}
}
Exemple #9
0
 void load(Archive& ar, std::bitset<Nb>& bs, const unsigned int version)
 {
   std::string s;
   ar >> BOOST_SERIALIZATION_NVP(s);
   assert(s.size() == bs.size());
   bs = 0;
   for (size_t i = 0; i < Nb; ++i)
     bs[Nb - i - 1] = (s[i] == '1');
 }
Exemple #10
0
void insert_assertions_step(const php::Func& func,
                            const Bytecode& bcode,
                            const State& state,
                            std::bitset<kMaxTrackedLocals> mayReadLocalSet,
                            bool lastStackOutputObvious,
                            Gen gen) {
  for (size_t i = 0; i < state.locals.size(); ++i) {
    if (options.FilterAssertions) {
      if (i < mayReadLocalSet.size() && !mayReadLocalSet.test(i)) {
        continue;
      }
    }
    auto const realT = state.locals[i];
    auto const op = makeAssert<bc::AssertObjL,bc::AssertTL>(
      borrow(func.locals[i]), realT
    );
    if (op) gen(*op);
  }

  if (!options.InsertStackAssertions) return;

  // Skip asserting the top of the stack if it just came immediately
  // out of an 'obvious' instruction.  (See hasObviousStackOutput.)
  assert(state.stack.size() >= bcode.numPop());
  auto i = size_t{0};
  auto stackIdx = state.stack.size() - 1;
  if (lastStackOutputObvious) {
    ++i, --stackIdx;
  }

  /*
   * This doesn't need to account for ActRecs on the fpiStack, because
   * no instruction in an FPI region can ever consume a stack value
   * from above the pre-live ActRec.
   */
  for (; i < bcode.numPop(); ++i, --stackIdx) {
    auto const realT = state.stack[stackIdx];

    if (options.FilterAssertions &&
        !realT.strictSubtypeOf(stack_flav(realT))) {
      continue;
    }

    auto const op = makeAssert<bc::AssertObjStk,bc::AssertTStk>(
      static_cast<int32_t>(i), realT
    );
    if (op) gen(*op);
  }
}
void test_val_ctor()
{
    {
        TEST_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
        assert(v.size() == N);
        std::size_t M = std::min<std::size_t>(N, 64);
        for (std::size_t i = 0; i < M; ++i)
            assert(v[i] == ((i & 1) != 0));
        for (std::size_t i = M; i < N; ++i)
            assert(v[i] == false);
    }
#if TEST_STD_VER >= 11
    {
        constexpr std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
        static_assert(v.size() == N, "");
    }
#endif
}
Exemple #12
0
void test_size()
{
    const std::bitset<N> v;
    assert(v.size() == N);
}