void GenerateCodeList(huffman_code_t **codelist, huffman_node_t *huffmanTree){ huffman_node_t *codeStack[CHARCOUNT],*current=huffmanTree; huffman_code_t *code=CreateCode(); int stacktop=-1, done=0,depth=0,depthdiff=0; while(done != 1){ if(current!=NULL){ ++stacktop; codeStack[stacktop]=current; if(current->parent != NULL) current->depth=current->parent->depth+1; current=current->left; ++depth; AddBit(code,1); } else{ if(stacktop>-1){ current=codeStack[stacktop]; --stacktop; depthdiff=depth-current->depth; if(depthdiff < 0) depthdiff=-depthdiff; ShiftRight(code, depthdiff); if(current->value != COMBINE_NODE){ codelist[current->value]=CloneCode(code); } depth=current->depth+1; AddBit(code,0); current=current->right; } else done=1; } } free(code); }
void ConstantLengthHighPulseProtocolBase::Decode(short state, unsigned int duration) { if (state==LOW) { unsigned int pulsecycleduration = duration + _highpulseduration ; if (WithinExpectedDeviation( pulsecycleduration , _shortperiods * _timeperiodduration , _timeperiodduration / 8) ) { // Are there more bits in the buffer than is expected for this protocol? if (decoder_bitpos == GetBitstreamLength()) { ShiftFirstBitOut(decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos); } AddBit( decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos , false); } else if (WithinExpectedDeviation( pulsecycleduration , _longperiods * _timeperiodduration , _timeperiodduration / 8) ) { // Are there more bits in the buffer than is expected for this protocol? if (decoder_bitpos == GetBitstreamLength()) { ShiftFirstBitOut(decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos); } AddBit( decoder_bitbuffer , decoder_bitbufferlength, decoder_bitpos , true); } else { DecodeBitstream(_highpulseduration, duration); ResetDecoder(); } } else if (state==HIGH) { _highpulseduration = duration; } }
int CCryptoBoolFunctionAnalyzer::GetErrorDistributionCoefficient(int inputCoordinate, int coordinateFunction) const { auto size = m_function.GetFunctionInputSize(); auto errorCoef = 0; for (int input = 0; input < size; ++input) { auto shiftedValue = (CFieldElement)GetBinaryRepresentation(input); shiftedValue.AddBit(inputCoordinate, 1); errorCoef += (m_table.GetCoordinateFunctionValue((CFieldElement)GetBinaryRepresentation(input), coordinateFunction) + m_table.GetCoordinateFunctionValue(shiftedValue, coordinateFunction)) % 2; } return errorCoef; }
int CCryptoBoolFunctionAnalyzer::GetErrorDistributionCoefficientInAverage(int inputCoordinate) const { auto size = m_function.GetFunctionInputSize(); auto errorCoef = 0; for (int input = 0; input < size; ++input) { auto shiftedValue = (CFieldElement)GetBinaryRepresentation(input); shiftedValue.AddBit(inputCoordinate, 1); auto firstValue = m_table.GetFunctionValue((CFieldElement)GetBinaryRepresentation(input)); auto secondValue = m_table.GetFunctionValue(shiftedValue); auto result = m_engine.Addition(firstValue, secondValue); errorCoef += result.GetWeight(); } return errorCoef; }