Ejemplo n.º 1
0
/*=============================================================================
Function main

Purpose:  this is the main entry point of the program.  It verifies the DSA
          computations that Dr. Peterson showed us and then I use DSA on some
          text of my own.
          
Parameters:
          not used
          
Returns:  nothing, DSA is demonstrated
=============================================================================*/
int main(int argc, char *argv[]) {

  UL y[32], r[32], qminus1[32], fminus1[32], pminus1[32], temp1[32], temp2[32],
    one[32], kprime[32], s[32], hcopy[32], res1[32], res2[32], w[32], u1[32],
    u2[32], v[32], mykprime[32];

  UL hash[32], hashcopy[32];
  struct hash *texthash;

  /* make a one to work with */
  zeroUL(one,32);
  one[31] = 1;

  /* first demonstrate that Dr. Peterson's example works as shown */

  printf("=========================================================\n");
  printf("Verifying Dr. Peterson's results:\n\n");

  mexp(g,x,y,p); /* here we compute public key y */

  printf("Public key y is:\n");
  fprintUL(stdout,y,32);

  /* and now determine r */
  mexp(g,k,r,p);
  mmult(one,r,r,q);

  printf("r is:\n");
  fprintUL(stdout,r,32);

  /* now calculate kprime */
  copyUL(q,qminus1,32);
  copyUL(f,fminus1,32);
  copyUL(p,pminus1,32);
  msub(qminus1,one,p);
  msub(fminus1,one,p);
  msub(pminus1,one,p);

  mmult(qminus1,fminus1,temp1,p);

  msub(temp1,one,p);

  mexp(k,temp1,kprime,q);

  printf("k' is:\n");
  fprintUL(stdout,kprime,32);

  /* now we get the s */
  mmult(x,r,temp1,q);
  madd(temp1,h,q);

  mmult(kprime,temp1,s,q);

  printf("s is:\n");
  fprintUL(stdout,s,32);

  /* calculate w=sprime */
  mmult(qminus1,fminus1,temp1,p);
  msub(temp1,one,p);
  
  mexp(s,temp1,w,q);

  printf("w is:\n");
  fprintUL(stdout,w,32);

  /* calculate u1 */
  mmult(h,w,u1,q);

  printf("u1 is:\n");
  fprintUL(stdout,u1,32);

  /* calculate u2 */
  mmult(r,w,u2,q);

  printf("u2 is:\n");
  fprintUL(stdout,u2,32);

  /* now calculate v */
  mexp(g,u1,temp1,p);
  mexp(y,u2,temp2,p);
  mmult(temp1,temp2,temp1,p);

  mmult(one,temp1,v,q);
                     
  printf("v is:\n");
  fprintUL(stdout,v,32);

  if (mcmp(r,v)==0)
    printf("v==r, Signature verifies!\n");
  else
    printf("v!=r, Signature does not verify!\n");
  printf("=========================================================\n\n");

  printf("Now working on some text of my own, I will sign the hash.\n\n");

  /* first get the hash we are going to sign */
  texthash = (struct hash *)malloc(sizeof(struct hash));

  sha1Mem(stuff,strlen(stuff),texthash);

  zeroUL(hash,32);
  hash[31] = texthash->H4;
  hash[30] = texthash->H3;
  hash[29] = texthash->H2;
  hash[28] = texthash->H1;
  hash[27] = texthash->H0;

  printf("Hash that we will sign:\n");
  fprintUL(stdout,hash,32);

  printf("Determining if chosen myk is relatively prime to q...\n");
  
  mexp(myk,qminus1,temp1,q);

  if (mcmp(temp1,one)==0)
    printf("myk is relatively prime to q!\n\n");
  else {
    printf("Chosen myk is not relatively prime to q, please \
            choose another myk.\n");
    exit(0);
  }

  mexp(g,x,y,p); /* here we compute public key y */

  printf("Public key y is:\n");
  fprintUL(stdout,y,32);

  /* and now determine r */
  mexp(g,myk,r,p);
  mmult(one,r,r,q);

  printf("r is:\n");
  fprintUL(stdout,r,32);

  /* calculate mykprime */
  copyUL(qminus1,temp1,32);
  msub(temp1,one,q);
  mexp(myk,temp1,mykprime,q);

  /* calculate s */
  mmult(x,r,temp1,q);
  madd(temp1,hash,q);

  mmult(mykprime,temp1,s,q);

  printf("s is:\n");
  fprintUL(stdout,s,32);

  /* calculate w=sprime */
  mmult(qminus1,fminus1,temp1,p);
  msub(temp1,one,p);
  
  mexp(s,temp1,w,q);

  printf("w is:\n");
  fprintUL(stdout,w,32);

  /* calculate u1 */
  mmult(hash,w,u1,q);

  printf("u1 is:\n");
  fprintUL(stdout,u1,32);

  /* calculate u2 */
  mmult(r,w,u2,q);

  printf("u2 is:\n");
  fprintUL(stdout,u2,32);

  /* now calculate v */
  mexp(g,u1,temp1,p);
  mexp(y,u2,temp2,p);
  mmult(temp1,temp2,temp1,p);

  mmult(one,temp1,v,q);
                     
  printf("v is:\n");
  fprintUL(stdout,v,32);

  if (mcmp(r,v)==0)
    printf("v==r, Signature verifies!\n");
  else
    printf("v!=r, Signature does not verify!\n");

}
	bool MeshXMLExporter::Export(OutputMap& output) 
	{

		try {

			// write XML to a strstream
			std::stringstream of;

			while (!m_submeshNames.empty())
				m_submeshNames.pop();

			if (m_pGame) {
				m_pGame->ReleaseIGame();
				m_pGame = 0;
			}

			m_ei->theScene->EnumTree(this);

			m_pGame = GetIGameInterface();
			IGameConversionManager* cm = GetConversionManager();
			cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);
			m_pGame->InitialiseIGame(m_nodeTab, false);
			m_pGame->SetStaticFrame(0);
			int nodeCount = m_pGame->GetTopLevelNodeCount();

			if (nodeCount == 0) {
				MessageBox(GetActiveWindow(), "No nodes available to export, aborting...", "Nothing To Export", MB_ICONINFORMATION);
				m_pGame->ReleaseIGame();
				return false;
			}

			// if we are writing everything to one file, use the name provided when the user first started the export;
			// otherwise, create filenames on the basis of the node (submesh) names
			std::string fileName;
			IGameNode* node = m_pGame->GetTopLevelNode(0);
			if (!m_config.getExportMultipleFiles())
				fileName = m_config.getExportFilename();
			else {
				fileName = m_config.getExportPath() + "\\";
				fileName += node->GetName();
				fileName += ".mesh.xml";
			}

			// write start of XML data
			streamFileHeader(of);

			int nodeIdx = 0;
			std::map<std::string, std::string> materialScripts;

			while (nodeIdx < nodeCount) {

				std::string mtlName;
				IGameNode* node = m_pGame->GetTopLevelNode(nodeIdx);
				IGameObject* obj = node->GetIGameObject();

				// InitializeData() is important -- it performs all of the WSM/time eval for us; no data without it
				obj->InitializeData();
				
				IGameMaterial* mtl = node->GetNodeMaterial();
				if (mtl == NULL)
					mtlName = m_config.getDefaultMaterialName();
				else
					mtlName = mtl->GetMaterialName();

				// clean out any spaces the user left in their material name
				std::string::size_type pos;
				while ((pos = mtlName.find_first_of(' ')) != std::string::npos)
					mtlName.replace(pos, 1, _T("_"));

				if (materialScripts.find(mtlName) == materialScripts.end()) {

					// export new material script
					MaterialExporter mexp(m_config, m_materialMap);
					std::string script;

					mexp.buildMaterial(mtl, mtlName, script);
					materialScripts[mtlName] = script;
				}

				//if (streamSubmesh(of, node, mtlName))
				if (streamSubmesh(of, obj, mtlName))
					m_submeshNames.push(std::string(node->GetName()));

				node->ReleaseIGameObject();
				nodeIdx++;

				if (m_config.getExportMultipleFiles() || nodeIdx == nodeCount) {

					// write end of this file's XML
					streamFileFooter(of);

					// insert new filename --> stream pair into output map
					output[fileName] = std::string(of.str());
					of.str("");

					if (nodeIdx != nodeCount) {
						fileName = m_config.getExportPath() + "\\";
						node = m_pGame->GetTopLevelNode(nodeIdx);
						fileName += node->GetName();
						fileName += ".mesh.xml";

						// start over again with new data
						streamFileHeader(of);
					}
				}
			}

			m_pGame->ReleaseIGame();

			// export materials if we are writing those
			if (m_config.getExportMaterial()) {

				std::ofstream materialFile;
				materialFile.open((m_config.getExportPath() + "\\" + m_config.getMaterialFilename()).c_str(), std::ios::out);

				if (materialFile.is_open()) {
					for (std::map<std::string, std::string>::iterator it = materialScripts.begin();
						it != materialScripts.end(); ++it)
					{
						materialFile << it->second;
					}

					materialFile.close();
				}
			}

			return true;
		}
		catch (...) {
			MessageBox(GetActiveWindow(), "An unexpected error has occurred while trying to export, aborting", "Error", MB_ICONEXCLAMATION);

			if (m_pGame)
				m_pGame->ReleaseIGame();

			return false;
		}
	}
Ejemplo n.º 3
0
double cosnn1nnint(double a11,double a12, double b1, int n11, int n12, int m1,
		   double aM, double bM1, double bM2,
		   double a21,double a22, double b2, int n21, int n22, int m2){
  double ret = cosnn1nnintwork(a11,a12,b1,n11,n12,(m1<0 ? -m1 : m1),
			       aM ,bM1 ,bM2,
			       a21,a22,b2,n21,n22,(m2<0 ? -m2 : m2));
  if(0) {
    cout << setprecision(10) << setiosflags(ios::fixed);
    // cout << setprecision(10); //  << setiosflags(ios::fixed);
    cout << "{1/(2*Pi)^2*NIntegrate[";
    if(m1) cout << "Cos["<<m1<<"*phi1]*";
    if(m2) cout << "Cos["<<m2<<"*phi2]*";
    cout << "(\n";
    for  (int i1=0;i1<(m1?2*m1:1);i1++) {
      for(int i2=0;i2<(m2?2*m2:1);i2++) {
	cout << "(";
	if((i1+i2)%2==1) cout << "-";
	cout << "1)/(\n";
	if(n11) {
	  cout        << "("<<mexp(a11)
		      << "+"<<mexp(b1 )<< "*Cos[phi1";
	  if(m1) cout << "+"<<i1<<"*Pi/"<<m1;
	  cout        <<"])^"<<n11<<"\n";
	}
	if(n12) { 
	  cout        << "("<<mexp(a12)
		      << "+"<<mexp(b1 )<< "*Cos[phi1";
	  if(m1) cout << "+"<<i1<<"*Pi/"<<m1;
	  cout        <<"])^"<<n12<<"\n";
	}
	cout          << "("<<mexp(aM )
		      << "+"<<mexp(bM1)<< "*Cos[phi1";
	if(m1) cout   << "+"<<i1<<"*Pi/"<<m1;
	cout          <<"]";
	cout          << "+"<<mexp(bM2)<< "*Cos[phi2";
	if(m2) cout   << "+"<<i2<<"*Pi/"<<m2;
	cout          <<"])\n";
	if(n21) {
	  cout        << "("<<mexp(a21)
		      << "+"<<mexp(b2 )<< "*Cos[phi2";
	  if(m2) cout << "+"<<i2<<"*Pi/"<<m2;
	  cout        <<"])^"<<n21<<"\n";
	}
	if(n22) {
	  cout        << "("<<mexp(a22)
		      << "+"<<mexp(b2 )<< "*Cos[phi2";
	  if(m2) cout << "+"<<i2<<"*Pi/"<<m2;
	  cout        <<"])^"<<n22<<"\n";
	}
	
	cout   << ")\n";
	if(i2!=2*m2-1) if(m2) cout << "+\n";
      }
      if(i1!=2*m1-1) if(m1) cout << "+\n";
    }
    cout        << "),{phi1,0";
    if(m1) cout << "+Pi/"<<2*m1;
    cout        <<",2*Pi";
    if(m1) cout <<    "/"<<2*m1;
    if(m1) cout << "+Pi/"<<2*m1;
    cout        <<"},{phi2,0";
    if(m2) cout << "+Pi/"<<2*m2;
    cout        <<",2*Pi";
    if(m2) cout <<    "/"<<2*m2;
    if(m2) cout << "+Pi/"<<2*m2;
    cout        <<"}],\n";
    cout << mexp(ret) << "}\n";
  }
  return ret;
} // cosnn1nnint