Example #1
0
File: avl.c Project: shijith/toy
void deletes(int n)
{
				struct node *par = 0;
				temp = root;
				par = find_pos(n, root);
				if(temp -> data == n) {
								if( par -> left == temp){
												if(temp -> right == 0)
																par ->left = temp -> left;
												else if(temp -> left == 0)
																par ->left = temp -> right;
												else {
																del_min();
												}
								} else if(par -> right == temp) {
												if(temp -> right == 0)
																par ->right = temp -> left;
												else if(temp -> left == 0)
																par ->right = temp -> right;
												else {
																del_min();
												}
								}	else {
												printf("root changed\n");
												if(root -> right == 0)
																root = root -> left;
												else
																del_min();

								}
								
				} 
				bf(par);
				
}
Example #2
0
File: avl.c Project: shijith/toy
void bf(struct node *p)
{
				struct node *l, *r;
				int bal;
				if(p) {
						bal = counts(p -> left) - counts(p -> right);
						if(bal == 2 || bal == -2) {
								printf("%d %d\n", p -> data, bal);
								if(bal == 2) {
										if(l = p -> left) {
												bal = counts(l -> left) - counts(l -> right);
														if(bal >= 0)
																rot_r(p -> left, p);
														else {	
																rot_l(p -> left -> right, p -> left);
																rot_r(p -> left, p); 	
														}
										}
								} else {
										if(r = p -> right) {
												bal = counts(r -> left) - counts(r -> right);
												if(bal > 0) {
														rot_r(p -> right -> left, p -> right);
														rot_l(p -> right, p);
												} else
														rot_l(p -> right, p);
										}
								}
						} else
								bf(p -> parent);
			}
}
Example #3
0
bool KviMircryptionEngine::doEncryptCBC(KviCString & plain, KviCString & encoded)
{
	// make sure it is a multiple of 8 bytes (eventually pad with zeroes)
	if(plain.len() % 8)
	{
		int oldL = plain.len();
		plain.setLen(plain.len() + (8 - (plain.len() % 8)));
		char * padB = plain.ptr() + oldL;
		char * padE = plain.ptr() + plain.len();
		while(padB < padE)
			*padB++ = 0;
	}

	int ll = plain.len() + 8;
	unsigned char * in = (unsigned char *)KviMemory::allocate(ll);

	InitVectorEngine::fillRandomIV(in, 8);

	KviMemory::copy(in + 8, plain.ptr(), plain.len());

	// encrypt
	unsigned char * out = (unsigned char *)KviMemory::allocate(ll);
	BlowFish bf((unsigned char *)m_szEncryptKey.ptr(), m_szEncryptKey.len());
	bf.ResetChain();
	bf.Encrypt(in, out, ll, BlowFish::CBC);
	KviMemory::free(in);

	encoded.bufferToBase64((const char *)out, ll);
	KviMemory::free(out);

	encoded.prepend('*'); // prepend the signature

	return true;
}
Example #4
0
void find_boundary_component_germs(GRID const& G, FACETSET & C,
				   int& num_comps, int& num_facets)

{
  typedef GRID                          grid_type;
  typedef grid_types<GRID>              gt;
  typedef typename gt::Facet            Facet;
  typedef typename gt::FacetIterator    FacetIterator;
  typedef iscellinside_pred<grid_type>  inside;
  typedef BoundaryComponentEdgeIterator2D<grid_type, inside> BCFacetIterator;

  partial_grid_function<Facet,bool> marked(G,false);

  num_comps = num_facets = 0;
  for(FacetIterator f = G.FirstFacet(); ! f.IsDone(); ++f)
    if( (! marked(*f))  && (G.IsOnBoundary(*f))) {
      C.push_back(*f);
      num_comps++;
      BCFacetIterator bf(*f,inside(G));
      while(! bf.IsDone()) {
	num_facets++;
	marked[*bf] = true;
	++bf;
      }
    }
}
Example #5
0
SEXP get_leftovers (SEXP bam, SEXP index, SEXP processed) try { 
    BamFile bf(bam, index);
    BamRead br;

    if (!isString(processed)) { throw std::runtime_error("names of processed chromosomes should be strings"); }
    const int nchr=LENGTH(processed);
    std::set<std::string> already_there;
    for (int i=0; i<nchr; ++i) {
        already_there.insert(std::string(CHAR(STRING_ELT(processed, i))));        
    }

    // Getting the reads mapped to chromosomes we didn't look at due to 'restrict'.
    int leftovers=0;
    std::set<std::string>::iterator iat;
    for (int cid=0; cid<bf.header->n_targets; ++cid) {
        iat=already_there.find(std::string(bf.header->target_name[cid]));
        if (iat!=already_there.end()) { continue; }
        BamIterator biter(bf, cid, 0, bf.header->target_len[cid]);
        while (bam_itr_next(bf.in, biter.iter, br.read) >= 0){ ++leftovers; }
    } 
    
    // Also getting the unmapped guys. 
    BamIterator biter(bf);
    while (bam_itr_next(bf.in, biter.iter, br.read) >= 0){ ++leftovers; }
    return(ScalarInteger(leftovers));
} catch (std::exception &e) {
    return mkString(e.what());
}
Example #6
0
void
TestBitField3D<T>::testCount() 
{
    DEFINE_TYPEDEFS;

    BitField bf(1);
    bf.fillBits();
    CPPUNIT_ASSERT(bf.toString() == "11111111");
    CPPUNIT_ASSERT(bf.count() == 8);

    bf.unsetBit(5);
    bf.unsetBit(2);
    CPPUNIT_ASSERT(bf.toString() == "11011011");
    CPPUNIT_ASSERT(bf.count() == 6);

    bf.clearBits();
    CPPUNIT_ASSERT(bf.toString() == "00000000");
    CPPUNIT_ASSERT(bf.count() == 0);

    bf.setBit(0);
    bf.setBit(2);
    bf.setBit(4);
    bf.setBit(6);
    CPPUNIT_ASSERT(bf.toString() == "10101010");
    CPPUNIT_ASSERT(bf.count() == 4);

    bf.invertBits();
    CPPUNIT_ASSERT(bf.toString() == "01010101");
    CPPUNIT_ASSERT(bf.count() == 4);
}
Example #7
0
void
TestBitField3D<T>::testUnsetBitCoordinate() 
{
    DEFINE_TYPEDEFS;

    BitField bf(1);
    CPPUNIT_ASSERT(bf.toString() == "00000000");
    
    bf.setBit(0, 0, 0);
    bf.setBit(1, 1, 1);
    bf.setBit(0, 1, 0);
    bf.setBit(0, 1, 1);
    bf.setBit(1, 0, 1);
    bf.invertBits();
    CPPUNIT_ASSERT(bf.toString() == "01011000");
        
    bf.unsetBit(1, 0, 0);
    CPPUNIT_ASSERT(bf.isSet(1) == false);
    CPPUNIT_ASSERT(bf.toString() == "00011000");
    bf.unsetBit(1, 1, 0);
    CPPUNIT_ASSERT(bf.isSet(3) == false);
    CPPUNIT_ASSERT(bf.toString() == "00001000");
    bf.unsetBit(0, 0, 1);
    CPPUNIT_ASSERT(bf.isSet(4) == false);
    CPPUNIT_ASSERT(bf.toString() == "00000000");
    CPPUNIT_ASSERT(bf.isEmpty() == true);
}
Example #8
0
void
TestBitField3D<T>::testSetBitCoordinate() 
{
    DEFINE_TYPEDEFS;

    BitField bf(1);
    CPPUNIT_ASSERT(bf.toString() == "00000000");

    bf.setBit(0, 0, 0);
    CPPUNIT_ASSERT(bf.isSet(0) == true);
    CPPUNIT_ASSERT(bf.isSet(1) == false);
    CPPUNIT_ASSERT(bf.toString() == "10000000");
    bf.setBit(1, 1, 1);
    CPPUNIT_ASSERT(bf.isSet(7) == true);
    CPPUNIT_ASSERT(bf.toString() == "10000001");
    bf.setBit(0, 1, 0);
    CPPUNIT_ASSERT(bf.isSet(2) == true);
    CPPUNIT_ASSERT(bf.toString() == "10100001");
    bf.setBit(0, 1, 1);
    CPPUNIT_ASSERT(bf.isSet(6) == true);
    CPPUNIT_ASSERT(bf.toString() == "10100011");
    bf.setBit(1, 0, 1);
    CPPUNIT_ASSERT(bf.isSet(5) == true);
    CPPUNIT_ASSERT(bf.toString() == "10100111");
}
Example #9
0
void
TestBitField3D<T>::testSetBitIndex() 
{
    DEFINE_TYPEDEFS;
 
    BitField bf(1);
    CPPUNIT_ASSERT(bf.toString() == "00000000");
  
    bf.setBit(0);
    CPPUNIT_ASSERT(bf.isSet(0) == true);
    CPPUNIT_ASSERT(bf.isSet(1) == false);
    CPPUNIT_ASSERT(bf.toString() == "10000000");
    bf.setBit(2);
    CPPUNIT_ASSERT(bf.isSet(2) == true);
    CPPUNIT_ASSERT(bf.toString() == "10100000");
    bf.setBit(4);
    CPPUNIT_ASSERT(bf.isSet(4) == true);
    CPPUNIT_ASSERT(bf.toString() == "10101000");
    bf.setBit(4);
    CPPUNIT_ASSERT(bf.isSet(4) == true);
    CPPUNIT_ASSERT(bf.toString() == "10101000");
    bf.setBit(6);
    CPPUNIT_ASSERT(bf.isSet(6) == true);
    CPPUNIT_ASSERT(bf.toString() == "10101010");
    CPPUNIT_ASSERT(bf.isFull()  == false);
    CPPUNIT_ASSERT(bf.isEmpty() == false);
}
Example #10
0
void
TestBitField3D<T>::testGetSetIndex() 
{
    DEFINE_TYPEDEFS;

    BitField bf(1);
    CPPUNIT_ASSERT(bf.toString() == "00000000");

    bf.setBit(5);
    CPPUNIT_ASSERT(bf.toString() == "00000100");
    CPPUNIT_ASSERT(bf.getSetIndex(0) == 5);

    bf.setBit(2);
    CPPUNIT_ASSERT(bf.toString() == "00100100");
    CPPUNIT_ASSERT(bf.getSetIndex(0) == 2);
    CPPUNIT_ASSERT(bf.getSetIndex(1) == 5);

    bf.setBit(7);
    CPPUNIT_ASSERT(bf.toString() == "00100101");
    CPPUNIT_ASSERT(bf.getSetIndex(0) == 2);
    CPPUNIT_ASSERT(bf.getSetIndex(1) == 5);
    CPPUNIT_ASSERT(bf.getSetIndex(2) == 7);

    bf.setBit(0);
    CPPUNIT_ASSERT(bf.toString() == "10100101");
    CPPUNIT_ASSERT(bf.getSetIndex(0) == 0);
    CPPUNIT_ASSERT(bf.getSetIndex(1) == 2);
    CPPUNIT_ASSERT(bf.getSetIndex(2) == 5);
    CPPUNIT_ASSERT(bf.getSetIndex(3) == 7);
}
Example #11
0
  void testQLDSolver()
  {
    BaseVariable xy("xy",2);
    BaseVariable z("z",1);
    CompositeVariable T("T", xy, z);

    MatrixXd A1(1,1); A1 << 1;
    VectorXd b1(1); b1 << -3;
    LinearFunction lf1(z, A1, b1);
    LinearConstraint c1(&lf1, true);

    MatrixXd A2(1,2); A2 << 3,1 ;
    VectorXd b2(1); b2 << 0;
    LinearFunction lf2(xy, A2, b2);
    LinearConstraint c2(&lf2, true);

    MatrixXd A3(2,2); A3 << 2,1,-0.5,1 ;
    VectorXd b3(2); b3 << 0, 1;
    LinearFunction lf3(xy, A3, b3);
    LinearConstraint c3(&lf3, false);

    QuadraticFunction objFunc(T, Matrix3d::Identity(), Vector3d::Zero(), 0);
    QuadraticObjective obj(&objFunc);
    
    QLDSolver solver;
    solver.addConstraint(c1);
    solver.addConstraint(c2);
    solver.addConstraint(c3);
    solver.addObjective(obj);

    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);


    solver.removeConstraint(c1);
    IdentityFunction id(z);
    VectorXd lz(1); lz << 1;
    VectorXd uz(1); uz << 2;
    IdentityConstraint bnd1(&id, lz, uz);
    solver.addBounds(bnd1);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    BaseVariable t("t", 2);
    VectorXd ut(2); ut << -4,-1;
    BoundFunction bf(t, ut, BOUND_TYPE_SUPERIOR);
    BoundConstraint bnd2(&bf, false);
    solver.addBounds(bnd2);

    QuadraticFunction objFunc2(t, Matrix2d::Identity(), Vector2d::Constant(2.71828),0);
    QuadraticObjective obj2(&objFunc2);
    solver.addObjective(obj2);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);

    Vector2d c3l(-1,-1);
    c3.setL(c3l);
    std::cout << "sol = " << std::endl << solver.solve().solution << std::endl << std::endl;
    ocra_assert(solver.getLastResult().info == 0);
  }
Example #12
0
//-------------------------------------------------------------------------------------------------
void ConsoleMenu::EditMsg(tty_save_state& tty, const FieldTable::Pair *fld, Message *msg) const
{
	string txt;
	int rval(-1);
	if (fld->_value._rlm)
		rval = SelectRealm(fld->_key, fld->_value._rlm);
	else
	{
		_os << endl << fld->_value._name << ": " << flush;
		GetString(tty, txt);
		if (msg->get_fp().is_group(fld->_key))
		{
			int cnt(GetValue<int>(txt));
			GroupBase *gb(msg->find_group(fld->_key));
			if (gb && cnt)
			{
				for (int ii(0); ii < cnt; ++ii)
				{
					Message *gmsg(static_cast<Message *>(gb->create_group()));
					const FieldTable::Pair *fld;
					while((fld = SelectField(gmsg, ii + 1)))
						EditMsg(tty, fld, gmsg);
					_os << endl << endl << *static_cast<MessageBase *>(gmsg) << endl;
					if (get_yn("Add group to msg? (y/n):", true))
						*gb += gmsg;
				}
			}
		}
	}

	BaseField *bf(fld->_value._create(txt, fld->_value._rlm, rval));
	msg->add_field(bf->get_tag(), msg->get_fp().get_presence().end(), 0, bf, true);
}
Example #13
0
bool Config::Save(std::string filename) const
{
	if (filename.empty())
		return true;

	FileWriter bf(filename);
	bf.write<std::string>("raggioMappa: " + raggioMappa + "\n");
	bf.write<std::string>("raggioCatasto: " + raggioCatasto + "\n");

	bf.write<std::string>("default_project_filetype: " + ProjectFileTypeGetName(default_project_filetype) + "\n");
	bf.write<std::string>("dataMisure: " + dataMisuraToString(dataMisureType, dataMisure) + "\n");
	bf.write<std::string>("store_crypted_passwords: " + (store_crypted_passwords ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("warnOverwriteSimulations: " + (warnOverwriteSimulations ? TRUE_STRING : FALSE_STRING) + "\n");

	bf.write<std::string>("displayAboutPanel: " + (displayAboutPanel ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("checkAntennasPreesistenti: " + (checkAntennasPreesistenti ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("preesistenti_xls: " + (preesistenti_xls ? TRUE_STRING : FALSE_STRING) + "\n");

	bf.write<std::string>("createPreesistentiFromQGIS: " + (createPreesistentiFromQGIS ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("checkAntennasTilts: " + (checkAntennasTilts ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("onTabSelectAll: " + (onTabSelectAll ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("useGainFromAntenna: " + (useGainFromAntenna ? TRUE_STRING : FALSE_STRING) + "\n");
	bf.write<std::string>("gainSmallErrorThreshold: " + Utils::formatDouble(gainSmallErrorThreshold, 2) + "\n");
	bf.write<std::string>("gainCriticalErrorThreshold: " + Utils::formatDouble(gainCriticalErrorThreshold, 2) + "\n");

	bf.write<std::string>("personalName: " + personalName + "\n");
	bf.write<std::string>("personalPhone: " + personalPhone + "\n");

	bf.write<std::string>("workingFolder: " + workingFolder + "\n");
	bf.write<std::string>("minCellPositionGrouping: " + std::to_string(minCellPositionGrouping) + "\n");

	bf.write<std::string>("db_sql_hostname: " + db_sql_hostname + "\n");
	bf.write<std::string>("db_sql_dbname: " + db_sql_dbname + "\n");
	bf.write<std::string>("db_sql_username: "******"\n");
	bf.write<std::string>("db_sql_password: "******"\n");
	bf.write<std::string>("db_catasto_hostname: " + db_catasto_hostname + "\n");
	bf.write<std::string>("db_catasto_username: "******"\n");
	bf.write<std::string>("db_catasto_password: "******"\n");

	bf.write<std::string>("pathGDAL: " + pathGDAL + "\n");

	bf.write<std::string>("calcoloInterpolazioneAngoli: " + InterpolationTypeToString(interpolation) + "\n");

	bf.write<std::string>("ndecimalHorr: " + std::to_string(ndecimalHorr) + "\n");
	bf.write<std::string>("ndecimalVert: " + std::to_string(ndecimalVert) + "\n");

	bf.write<std::string>("respectVolumeLimit: " + Utils::formatDouble(respectVolumeLimit, 2) + "\n");
	bf.write<std::string>("respectVolumeType: " + respectVolumeType + "\n");

	bf.write<std::string>("proxy_host: " + proxy_host + "\n");
	bf.write<std::string>("proxy_port: " + std::to_string(proxy_port) + "\n");
	bf.write<std::string>("proxy_username: "******"\n");
	bf.write<std::string>("proxy_password: "******"\n");

	for (CalcPreset cp : calcPresets)
		bf.write("calcpreset: " + cp.toString() + "\n");

	bf.close();
	return true;
}
Example #14
0
TEST(TBitField, can_invert_many_random_bits_bitfield)
{
  const int size = 38;
  TBitField bf(size), negBf(size), expNegBf(size);

  std::vector<int> bits;
  bits.push_back(0);
  bits.push_back(1);
  bits.push_back(14);
  bits.push_back(16);
  bits.push_back(33);
  bits.push_back(37);

  for (unsigned int i = 0; i < bits.size(); i++)
    bf.SetBit(bits[i]);

  negBf = ~bf;

  for(int i = 0; i < size; i++)
    expNegBf.SetBit(i);
  for (unsigned int i = 0; i < bits.size(); i++)
    expNegBf.ClrBit(bits[i]);

  EXPECT_EQ(expNegBf, negBf);
}
Example #15
0
void bapply(bfunc *bf) {

  Register *p;
  for (p=head.next;p!=NULL;p=p->next)
    bf(p->who,p->where,p->ptr);

} /* bapply */
Example #16
0
int			main()
{
	int		t[SZ][SZ]={
		{ 8, 2,22,97,38,15, 0, 4, 0,75, 4, 5, 7,78,52,12,50,77,91, 8},
		{49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48, 4,56,62, 0},
		{81,49,31,73,55,79,14,29,93,71,40,67,53,88,30, 3,49,13,36,65},
		{52,70,95,23, 4,60,11,42,69,24,68,56, 1,32,56,71,37, 2,36,91},
		{22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80},
		{24,47,32,60,99, 3,45, 2,44,75,33,53,78,36,84,20,35,17,12,50},
		{32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70},
		{67,26,20,68, 2,62,12,20,95,63,94,39,63, 8,40,91,66,49,94,21},
		{24,55,58, 5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72},
		{21,36,23, 9,75, 0,76,44,20,45,35,14, 0,61,33,97,34,31,33,95},
		{78,17,53,28,22,75,31,67,15,94, 3,80, 4,62,16,14, 9,53,56,92},
		{16,39, 5,42,96,35,31,47,55,58,88,24, 0,17,54,24,36,29,85,57},
		{86,56, 0,48,35,71,89, 7, 5,44,44,37,44,60,21,58,51,54,17,58},
		{19,80,81,68, 5,94,47,69,28,73,92,13,86,52,17,77, 4,89,55,40},
		{ 4,52, 8,83,97,35,99,16, 7,97,57,32,16,26,26,79,33,27,98,66},
		{88,36,68,87,57,62,20,72, 3,46,33,67,46,55,12,32,63,93,53,69},
		{ 4,42,16,73,38,25,39,11,24,94,72,18, 8,46,29,32,40,62,76,36},
		{20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74, 4,36,16},
		{20,73,35,29,78,31,90, 1,74,31,49,71,48,86,81,16,23,57, 5,54},
		{ 1,70,54,71,83,51,54,69,16,92,33,48,61,43,52, 1,89,19,67,48}
	};

	return (printf("%d\n", bf(t)));
}
Example #17
0
SEXP Bbi_get_wig_region(SEXP file_name, SEXP chr_name, SEXP start, SEXP end)
{
  std::string fname = Rcpp::as<std::string>(file_name); // explicit
  std::string chrome = Rcpp::as<std::string>(chr_name); // implicit ? which ok
  unsigned int c_start = Rcpp::as<unsigned int>(start);
  unsigned int c_end = Rcpp::as<unsigned int>(end);
  
  // we are goig to wrap up a std::map<std::string, std::vector<float> >
  // to pass back to R.
  // Unfortunately I'm unable to find the actual specifications for the
  // GenericVector class (it's a template of Vector

  std::vector<unsigned int> starts;
  std::vector<unsigned int> ends;
  std::vector<float> values;
  
  BigFile bf(fname.c_str());
  if(!bf.good())
    return( make_return_data(chrome, starts, ends, values) );
  
  WigSegment* segment = bf.segment(chrome, c_start, c_end);
  if(!segment)
    return( make_return_data(chrome, starts, ends, values) );

  starts = segment->starts();
  ends = segment->ends();
  values = segment->values();
  delete segment;
  return( make_return_data(chrome, starts, ends, values) );
}
Example #18
0
void testBilateralFilter( const Array2D< float >& input,
	float ss, float sr,
	Array2D< float >& output )
{
	BilateralFilter bf( input.width(), input.height(), ss, sr );
	
	int nIterations = 100;

    
	bf.setInput( input );
	StopWatch sw;

	for( int i = 0; i < nIterations; ++i )
	{
		bf.apply( );
		cudaDeviceSynchronize();
	}

	float ms = sw.millisecondsElapsed();
	bf.getOutput( output );
	printf( "image size: %d x %d\n", input.width(), input.height() );
	printf( "ss = %f, sr = %f\n", ss, sr );
	printf( "Total time = %f ms, ms on average: %f\n",
		ms, ms / nIterations );
}
Example #19
0
int main(int argc, char* argv[])
{
	GraphBuilder gb(argv[1], true);
	std::string malware_program(argv[2]);

	int num_files = 0;
	std::ifstream bf(argv[3]);
	std::string tmp_string;
	std::vector<std::string> benign_programs;
	std::vector<Graph*> malspecs;

	bf>>num_files;
	std::getline(bf, tmp_string);
	for(int i = 0; i < num_files; i++) {
		std::getline(bf, tmp_string);
		benign_programs.push_back(tmp_string);
	}

	malspecs = malspec_mining(gb, malware_program, benign_programs);
	std::cout<<std::endl<<"Malspecs found:"<<std::endl;
	for(unsigned int i = 0; i < malspecs.size(); i++) {
		std::cout<<"Malspec "<<i<<std::endl;
		std::cout<<*malspecs[i]<<std::endl;
	}

	for(unsigned int i = 0; i < malspecs.size(); i++)
		delete malspecs[i];
	return 0;
}
int main(int argc, char** argv)
{
    unsigned int hash = 0xC4B1801C;
    std::string charset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
    std::cout << bf(sub_41EC50, (const unsigned char*)&hash, 4, charset, 1, 5) << std::endl;
    return 0;
}
Example #21
0
void RestoreFs::onFile( )
{
   InBz2File bf( _attr.hash );

   OutputFile of( _path.string() );

   of.write( bf );
}
Example #22
0
//
// 加解密文件测试
//
void YCTest::test_encrypt_file()
{
	const char* pwd = "<ulstyle='padding:0;margin:10px;'><listyle='line-height:16px;padding-left:0;margin-left:10px;font-s";
	YCBFEncryption bf(pwd);

	bf.encode("c:\\encrypt\\license.lic", "c:\\encrypt\\license.cipher");
	bf.decode("c:\\encrypt\\license.cipher", "c:\\encrypt\\license.plain");
}
Example #23
0
template <class ZT, class FT> void MatHouseholder<ZT, FT>::refresh_R_bf(int i)
{
  // Verify that b[i] has change before last time (more or less bf != b)
  FPLLL_DEBUG_CHECK(col_kept[i] == false);

  int j;

  n_known_cols = max(n_known_cols, init_row_size[i]);

  if (enable_row_expo)
  {
    long max_expo = LONG_MIN;

    // Copy b(i, j) in bf(i, j) and get the maximal exponent of the row
    // TODO: these are row operations. However, since the types are converted, maybe difficult
    // to make a row operation here.
    for (j = 0; j < n_known_cols; j++)
    {
      b(i, j).get_f_exp(bf(i, j), tmp_col_expo[j]);
      max_expo = max(max_expo, tmp_col_expo[j]);
    }

    // Renormalize all the bf(i, j) with max_expo
    // TODO: these are row operations. However, since the exponent of mul_2si is not constant,
    // maybe difficult to make a row operation here.
    for (j = 0; j < n_known_cols; j++)
      bf(i, j).mul_2si(bf(i, j), tmp_col_expo[j] - max_expo);
    for (j = n_known_cols; j < n; j++)
      bf(i, j) = 0.0;

    row_expo[i] = max_expo;
    FPLLL_DEBUG_CHECK(row_expo[i] >= 0);
  }
  else
  {
    // Simply copy b[i] in bf[i]
    // TODO: these are row operations. However, since the types are converted, maybe difficult
    // to make a row operation here.
    for (j = 0; j < n_known_cols; j++)
      bf(i, j).set_z(b(i, j));
    for (j = n_known_cols; j < n; j++)
      bf(i, j) = 0.0;
  }

  // Copy R[i] in bf[i] (while we have copied b[i] in R[i])
  // TODO: these are row operations.
  for (j = 0; j < n_known_cols; j++)
    R(i, j) = bf(i, j);
  for (j = n_known_cols; j < n; j++)
    R(i, j) = 0.0;

  // TODO: maybe not realy efficient (since we will redo some already done comparisions if flags are
  // enabled) but factorize code.
  norm_square_b_row(norm_square_b[i], i, expo_norm_square_b[i]);

#ifdef DEBUG
  // bf[i] = b[i] at the end of the function
  col_kept[i] = true;
#endif  // DEBUG
}
Example #24
0
TEST(TBitField, can_set_bit)
{
  TBitField bf(10);

  EXPECT_EQ(0, bf.GetBit(3));

  bf.SetBit(3);
  EXPECT_NE(0, bf.GetBit(3));
}
Example #25
0
void
main(int argc, char **argv)
{
	int from, to;
	int size = 24;
	int src = Jis;
	char *file = 0;
	long nc, nb;
	int x;
	uchar *bits;
	long *chars;
	int raw = 0;
	Bitmap *b, *b1;
	Subfont *f;
	int *found;

	ARGBEGIN{
	case 'f':	file = ARGF(); break;
	case 'r':	raw = 1; break;
	case '5':	src = Big5; break;
	case 's':	size = 16; break;
	case 'g':	src = Gb_bdf; break;
	case 'q':	src = Gb_qw; break;
	default:	usage();
	}ARGEND
	if(file == 0)
		file = source[src].names[(size==24)? Size24:Size16];
	if(argc != 2)
		usage();
	from = strtol(argv[0], (char **)0, 0);
	to = strtol(argv[1], (char **)0, 0);
	binit(0, 0, "fontgen");
	nc = to-from+1;
	nb = size*size/8;		/* bytes per char */
	nb *= nc;
	bits = (uchar *)malloc(nb);
	chars = (long *)malloc(sizeof(long)*nc);
	found = (int *)malloc(sizeof(found[0])*nc);
	if(bits == 0 || chars == 0){
		fprint(2, "%s: couldn't malloc %d bytes for %d chars\n", argv0, nb, nc);
		exits("out of memory");
	}
	if(raw){
		for(x = from; x <= to; x++)
			chars[x-from] = x;
	} else
		source[src].mfn(from, to, chars);
	memset(bits, 0, nb);
	b = source[src].bfn(file, nc, chars, size, bits, &found);
	b1 = balloc(b->r, b->ldepth);
	bitblt(b1, b1->r.min, b, b->r, S);
	f = bf(nc, size, b1, found);
	wrbitmapfile(1, b);
	wrsubfontfile(1, f);/**/
	exits(0);
}
Example #26
0
void RestoreFs::onSymlink( )
{
   char buf[PATH_MAX];
   InBz2File bf( _attr.hash );

   auto n = bf.read( buf, sizeof(buf)-1 );
   buf[n] = 0;

   symlink( buf, _path.c_str( ) );
}
Example #27
0
buffered_file file::fdopen(const char *mode) {
  // Don't retry as fdopen doesn't return EINTR.
  FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode));
  if (!f)
    FMT_THROW(system_error(errno,
                           "cannot associate stream with file descriptor"));
  buffered_file bf(f);
  fd_ = -1;
  return bf;
}
Example #28
0
void RestoreFs::onDirBegin( )
{
   InBz2File bf( _attr.hash );
   NodeAttr attr;

   while ( bf.parseNodeAttr(&attr) )
      subPush( new RestoreFs( attr, _path ) );

   boost::filesystem::create_directories( _path );
}
Example #29
0
File: bf.c Project: otz/brainf--k
int main(int argc, char **argv)
{
	int c;
	char *p = tape;
	FILE *ftape = fopen(argv[1], "r");
	while (EOF != (c = fgetc(ftape)))
		*p++ = c;
	*p = 0;
	fclose(ftape);
	return bf();
}
Example #30
0
TEST(TBitField, can_clear_bit)
{
  TBitField bf(10);

  int bitIdx = 3;

  bf.SetBit(bitIdx);
  EXPECT_NE(0, bf.GetBit(bitIdx));

  bf.ClrBit(bitIdx);
  EXPECT_EQ(0, bf.GetBit(bitIdx));
}