Exemple #1
0
void testFactory(vector<char> data, seconds duration, seconds maxTimeToTest, int id)
{
	Puzzle p;
	HardwareSpeedTester hst(1000, maxTimeToTest);
	TimeCapsuleFactory<char> tcf(hst);
	//char rawdata[] = "Hey, I hope it will finish in time.. tho probably not :D ...";
	auto capsule = tcf.createTimeCapsule(p, data, duration);
	capsule.save("capsule_" + to_string(id) + ".dat");

	Capsule<char> capsule2;
	capsule2.load("capsule_" + to_string(id) + ".dat");

	auto crdata = capsule.getCryptedData();
	auto crdata2 = capsule2.getCryptedData();

	assert(capsule.getBase() == capsule2.getBase());
	assert(capsule.getN() == capsule2.getN());
	assert(capsule.getIV() == capsule2.getIV());
	assert(capsule.getCryptedKey() == capsule2.getCryptedKey());
	assert(capsule.getNumberOfOperations() == capsule2.getNumberOfOperations());
	Logger::log("Original crypted data size: " + to_string(crdata.size()));
	Logger::log("Copypasted crypted data size: " + to_string(crdata2.size()));

	string datastr(crdata.begin(), crdata.end());
	string datastr2(crdata2.begin(), crdata2.end());
	Logger::log("Original   crypted data: " + datastr);
	Logger::log("Copypasted crypted data: " + datastr2);

	//cout << capsule.getCryptedData().size() << ", " << capsule2.getCryptedData().size() << endl;
	//assert(capsule.getCryptedData().size() == capsule2.getCryptedData().size());
	//for (size_t i = 0; i < capsule.getCryptedData().size(); ++i)
	//	assert(capsule.getCryptedData()[i] == capsule2.getCryptedData()[i]);

	Puzzle p2(capsule2.getBase());

	auto start = chrono::high_resolution_clock::now();
	auto key = p2.solve(capsule2.getCryptedKey(), capsule2.getNumberOfOperations(), capsule2.getN());
	auto end = chrono::high_resolution_clock::now();

	Logger::log("Time specified to decode: " + to_string(duration.count()) + " seconds");
	Logger::log("Time taken to decode: " + to_string(chrono::duration_cast<seconds>(end - start).count()) + " seconds");
	
	Encryptor<char> cr;
	auto databack = cr.decrypt(capsule2.getCryptedData(), key, capsule2.getIV());
	string tmpdata(data.begin(), data.end());
	string tmpdataback(databack.begin(), databack.end());
	Logger::log("Original  data: " + tmpdata);
	Logger::log("Data decrypted: " + tmpdataback);

	/*char dummychar;
	if (crdata.size() != crdata2.size())
	{
		Logger::log("PARA VAN!");
		cin >> dummychar;
	}*/
}
Exemple #2
0
bool Nfc::serialWrite(const uint16_t addr, const uint8_t num, const std::vector<uint8_t>& data){
	std::vector<uint8_t> senddata(5+num);
	auto ite = senddata.begin();
	*ite++ = SYNC_CODE;
	*ite++ = SERIAL_READ;
	*ite++ = static_cast<uint8_t>((addr>>8)&0x00FF);
	*ite++ = static_cast<uint8_t>(addr&0x00FF);
	for (auto v : data){
		*ite++ = v;
	}
	*ite = getChecksum(data, 4+num);
	sendnbyte(senddata, 5+num);

	std::vector<uint8_t> tmpdata(3);
	uint8_t tmp1data;
	if(!recvnbyte(tmpdata, 2)) return false;
	if(!recv1byte(tmp1data)) return false;
	if(tmpdata[1] != RESPONCE_ACK) return false;
	return true;
}
Exemple #3
0
    //* Creation / loading methods ********************************************
    void GLTexture::createInternalResourcesImpl(void)
    {
        if (!GLEW_VERSION_1_2 && mTextureType == TEX_TYPE_3D)
            OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, 
                "3D Textures not supported before OpenGL 1.2", 
                "GLTexture::createInternalResourcesImpl");

        if (!GLEW_VERSION_2_0 && mTextureType == TEX_TYPE_2D_ARRAY)
            OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, 
                "2D texture arrays not supported before OpenGL 2.0", 
                "GLTexture::createInternalResourcesImpl");

        if (mTextureType == TEX_TYPE_EXTERNAL_OES) {
            OGRE_EXCEPT(
                Exception::ERR_RENDERINGAPI_ERROR,
                "TEX_TYPE_EXTERNAL_OES is not available for openGL",
                "GLTexture::createInternalResourcesImpl"
            );
        }

        // Convert to nearest power-of-two size if required
        mWidth = GLPixelUtil::optionalPO2(mWidth);      
        mHeight = GLPixelUtil::optionalPO2(mHeight);
        mDepth = GLPixelUtil::optionalPO2(mDepth);
        

        // Adjust format if required
        mFormat = TextureManager::getSingleton().getNativeFormat(mTextureType, mFormat, mUsage);
        
        // Check requested number of mipmaps
        uint32 maxMips = getMaxMipmaps();
        mNumMipmaps = mNumRequestedMipmaps;
        if(mNumMipmaps>maxMips)
            mNumMipmaps = maxMips;

        // Check if we can do HW mipmap generation
        mMipmapsHardwareGenerated = true;
        
        // Generate texture name
        glGenTextures( 1, &mTextureID );
        
        // Set texture type
        mRenderSystem->_getStateCacheManager()->bindGLTexture( getGLTextureTarget(), mTextureID );
        
        // This needs to be set otherwise the texture doesn't get rendered
        if (GLEW_VERSION_1_2)
            mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(),
                GL_TEXTURE_MAX_LEVEL, mNumMipmaps);
        
        // Set some misc default parameters so NVidia won't complain, these can of course be changed later
        mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        if (GLEW_VERSION_1_2)
        {
            mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            mRenderSystem->_getStateCacheManager()->setTexParameteri(getGLTextureTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        }

        if ((mUsage & TU_AUTOMIPMAP) && mNumRequestedMipmaps)
        {
            mRenderSystem->_getStateCacheManager()->setTexParameteri( getGLTextureTarget(), GL_GENERATE_MIPMAP, GL_TRUE );
        }
        
        // Allocate internal buffer so that glTexSubImageXD can be used
        // Internal format
        GLenum internalformat = GLPixelUtil::getGLInternalFormat(mFormat, mHwGamma);
        uint32 width = mWidth;
        uint32 height = mHeight;
        uint32 depth = mDepth;

        GLenum format = GLPixelUtil::getGLOriginFormat(mFormat);
        GLenum datatype = GLPixelUtil::getGLOriginDataType(mFormat);

        if(PixelUtil::isCompressed(mFormat))
        {
            // Compressed formats
            GLsizei size = static_cast<GLsizei>(PixelUtil::getMemorySize(mWidth, mHeight, mDepth, mFormat));
            // Provide temporary buffer filled with zeroes as glCompressedTexImageXD does not
            // accept a 0 pointer like normal glTexImageXD
            // Run through this process for every mipmap to pregenerate mipmap piramid
            std::vector<uint8> tmpdata(size);
            
            for(uint32 mip=0; mip<=mNumMipmaps; mip++)
            {
                size = static_cast<GLsizei>(PixelUtil::getMemorySize(width, height, depth, mFormat));
                switch(mTextureType)
                {
                    case TEX_TYPE_1D:
                        glCompressedTexImage1DARB(GL_TEXTURE_1D, mip, internalformat, 
                            width, 0, 
                            size, &tmpdata[0]);
                        break;
                    case TEX_TYPE_2D:
                        glCompressedTexImage2DARB(GL_TEXTURE_2D, mip, internalformat,
                            width, height, 0, 
                            size, &tmpdata[0]);
                        break;
                    case TEX_TYPE_2D_ARRAY:
                    case TEX_TYPE_3D:
                        glCompressedTexImage3DARB(getGLTextureTarget(), mip, internalformat,
                            width, height, depth, 0, 
                            size, &tmpdata[0]);
                        break;
                    case TEX_TYPE_CUBE_MAP:
                        for(int face=0; face<6; face++) {
                            glCompressedTexImage2DARB(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat,
                                width, height, 0, 
                                size, &tmpdata[0]);
                        }
                        break;
                    case TEX_TYPE_2D_RECT:
                        break;
                    case TEX_TYPE_EXTERNAL_OES:
                        OGRE_EXCEPT(
                            Exception::ERR_RENDERINGAPI_ERROR,
                            "Attempt to create mipmaps for unsupported TEX_TYPE_EXTERNAL_OES, should never happen",
                            "GLTexture::createInternalResourcesImpl"
                        );
                        break;
                };
                if(width>1)
                    width = width/2;
                if(height>1)
                    height = height/2;
                if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY)
                    depth = depth/2;
            }
        }
        else
        {
            // Run through this process to pregenerate mipmap pyramid
            for(uint32 mip=0; mip<=mNumMipmaps; mip++)
            {
                // Normal formats
                switch(mTextureType)
                {
                    case TEX_TYPE_1D:
                        glTexImage1D(GL_TEXTURE_1D, mip, internalformat,
                            width, 0, 
                            format, datatype, 0);
    
                        break;
                    case TEX_TYPE_2D:
                        glTexImage2D(GL_TEXTURE_2D, mip, internalformat,
                            width, height, 0, 
                            format, datatype, 0);
                        break;
                    case TEX_TYPE_2D_ARRAY:
                    case TEX_TYPE_3D:
                        glTexImage3D(getGLTextureTarget(), mip, internalformat,
                            width, height, depth, 0, 
                            format, datatype, 0);
                        break;
                    case TEX_TYPE_CUBE_MAP:
                        for(int face=0; face<6; face++) {
                            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, internalformat,
                                width, height, 0, 
                                format, datatype, 0);
                        }
                        break;
                    case TEX_TYPE_2D_RECT:
                        break;
                    case TEX_TYPE_EXTERNAL_OES:
                        OGRE_EXCEPT(
                            Exception::ERR_RENDERINGAPI_ERROR,
                            "Attempt to create mipmaps for unsupported TEX_TYPE_EXTERNAL_OES, should never happen",
                            "GLTexture::createInternalResourcesImpl"
                        );
                        break;
                };
                if(width>1)
                    width = width/2;
                if(height>1)
                    height = height/2;
                if(depth>1 && mTextureType != TEX_TYPE_2D_ARRAY)
                    depth = depth/2;
            }
        }
        _createSurfaceList();
        // Get final internal format
        mFormat = getBuffer(0,0)->getFormat();
    }