Esempio n. 1
1
/*******************************************************************************  
* Function Name  : AES_expand_deckey  
* Description    : According to key computes the expanded key (expkey) for AES128   
*                  decryption.  
* Input          : key: user key (128 bits / 16 bytes)
* Output         : expkey: expanded key (320 bits / 40 bytes)
* Return         : None  
*******************************************************************************/   
void AES_expand_deckey(ot_u32* key, ot_u32* expkey) {
#if (AES_USEHW)
    platform_expand_deckey(key, expkey);

#elif (AES_USEFAST)
    register ot_u32* local_pointer;// = expkey;   
    register int i; // = 0;   
    register ot_u32 copy0;   
    register ot_u32 copy1;   
    register ot_u32 copy2;   
    register ot_u32 copy3;   
   
    AES_expand_enckey(key,expkey);   
    
    local_pointer       = expkey;
    local_pointer[0]    = key[0];   
    local_pointer[1]    = key[1];   
    local_pointer[2]    = key[2];   
    local_pointer[3]    = key[3];   
   
    for (i = 1; i <10; i++) {   
        local_pointer  += 4;   
        copy0           = local_pointer[0];    
        copy1           = local_pointer[1];   
        copy2           = local_pointer[2];   
        copy3           = local_pointer[3];   
        
        local_pointer[0] =      dec_table[Sbox[byte0(copy0)]]  ^   
                           rot1(dec_table[Sbox[byte1(copy0)]]) ^   
                           rot2(dec_table[Sbox[byte2(copy0)]]) ^   
                           rot3(dec_table[Sbox[byte3(copy0)]]);   
        
        local_pointer[1] =      dec_table[Sbox[byte0(copy1)]]  ^   
                           rot1(dec_table[Sbox[byte1(copy1)]]) ^   
                           rot2(dec_table[Sbox[byte2(copy1)]]) ^   
                           rot3(dec_table[Sbox[byte3(copy1)]]);   
        
        local_pointer[2] =      dec_table[Sbox[byte0(copy2)]]  ^   
                           rot1(dec_table[Sbox[byte1(copy2)]]) ^   
                           rot2(dec_table[Sbox[byte2(copy2)]]) ^   
                           rot3(dec_table[Sbox[byte3(copy2)]]);   
        
        local_pointer[3] =      dec_table[Sbox[byte0(copy3)]]  ^   
                           rot1(dec_table[Sbox[byte1(copy3)]]) ^   
                           rot2(dec_table[Sbox[byte2(copy3)]]) ^   
                           rot3(dec_table[Sbox[byte3(copy3)]]);   
  }
  
#elif (AES_USELITE == ENABLED)
    AES_expand_enckey(key, expkey);
#endif
}   
Esempio n. 2
0
Vector3f Arm::F(VectorXf theta) {
	Vector3f rot1(theta(0), theta(1), theta(2));
	Vector3f rot2(theta(3), theta(4), theta(5));
	Vector3f rot3(theta(6), theta(7), theta(8));
	Vector3f rot4(theta(9), theta(10), theta(11));
    Matrix4f R1; R1 = rodrigues(rot1);
    Matrix4f R2; R2 = rodrigues(rot2);
    Matrix4f R3; R3 = rodrigues(rot3);
    Matrix4f R4; R4 = rodrigues(rot4);

    Matrix4f T1; T1 = list_joints[0]->transformation();
    Matrix4f T2; T2 = list_joints[1]->transformation();
    Matrix4f T3; T3 = list_joints[2]->transformation();
    Matrix4f T4; T4 = list_joints[3]->transformation();

    Vector4f identity(0.0, 0.0, 0.0, 1.0);
    Vector4f result;

    result = R1 * T1 * R2 * T2 * R3 * T3 * R4 * T4 * identity;

    Vector3f ret(result(0), result(1), result(2));
    // cout << "Theta:" << endl << theta;
    // cout << "ret: " << endl << ret << endl;=
    return ret;
}
Esempio n. 3
0
void solve() {
	char s[10];
	int ncmd = 0, begin = 0;
	gets(line);
	while (begin < strlen(line)){
		sscanf(line + begin, "%s", cmd[++ncmd]);
		begin += strlen(cmd[ncmd]);
		while (line[begin] == ' ')
			begin++;
	}

	p = 0;
	while (ncmd) {
		strcpy(s, cmd[ncmd]);
		ncmd--;
		if (strcmp(s, "id") == 0 || strcmp(s, "id-") == 0)
			continue;
		if (strcmp(s, "rot") == 0) rot();
		else if (strcmp(s, "rot-") == 0) rot2();
		else if (strcmp(s, "sym") == 0 || strcmp(s, "sym-") == 0) sym();
		else if (strcmp(s, "bhsym") == 0 || strcmp(s, "bhsym-") == 0) bhsym();
		else if (strcmp(s, "bvsym") == 0 || strcmp(s, "bvsym-") == 0) bvsym();
		else if (strcmp(s, "div") == 0) div();
		else if (strcmp(s, "div-") == 0) div2();
		else if (strcmp(s, "mix") == 0) mix();
		else if (strcmp(s, "mix-") == 0) mix2();
		p = !p;

	}
}
Esempio n. 4
0
SbRotation
SoBillboard::calculateRotation(SoState *state)
{
    SbRotation rot;
#ifdef INVENTORRENDERER
    const SbViewVolume &viewVolume = SoViewVolumeElement::get(state);

    if (SbVec3f(0.0f, 0.0f, 0.0f) == axis.getValue())
    {
        rot = viewVolume.getAlignRotation();
    }
#else
    const SbMatrix &mm = SoModelMatrixElement::get(state);
    SbMatrix imm = mm.inverse();

    SbVec3f toviewer;
    SbVec3f cameray(0.0f, 1.0f, 0.0f);
    const SbViewVolume &vv = SoViewVolumeElement::get(state);

    toviewer = -vv.getProjectionDirection();
    imm.multDirMatrix(toviewer, toviewer);

    (void)toviewer.normalize();

    SbVec3f rotaxis = this->axis.getValue();

    if (rotaxis == SbVec3f(0.0f, 0.0f, 0.0f))
    {
        // 1. Compute the billboard-to-viewer vector.
        // 2. Rotate the Z-axis of the billboard to be collinear with the
        //    billboard-to-viewer vector and pointing towards the viewer's position.
        // 3. Rotate the Y-axis of the billboard to be parallel and oriented in the
        //    same direction as the Y-axis of the viewer.
        rot.setValue(SbVec3f(0.f, 0.0f, 1.0f), toviewer);
        SbVec3f viewup = vv.getViewUp();
        imm.multDirMatrix(viewup, viewup);

        SbVec3f yaxis(0.0f, 1.0f, 0.0f);
        rot.multVec(yaxis, yaxis);
        SbRotation rot2(yaxis, viewup);

        SbVec3f axis;
        float angle;
        rot.getValue(axis, angle);
        rot2.getValue(axis, angle);
        rot = rot * rot2;
        //SoModelMatrixElement::rotateBy(state, (SoNode*) this, rot);
    }
#endif
    else
    {
        fprintf(stderr, "SoBillboard: axis != (0.0, 0.0, 0.0) not implemented\n");
    }

    return rot;
}
Esempio n. 5
0
void
RankTwoTensorTest::rotateTest()
{
  Real sqrt2 = 0.707106781187;
  RealTensorValue rtv0(sqrt2, -sqrt2, 0, sqrt2, sqrt2, 0, 0, 0, 1); // rotation about "0" axis
  RealTensorValue rtv1(sqrt2, 0, -sqrt2, 0, 1, 0, sqrt2, 0, sqrt2); // rotation about "1" axis
  RealTensorValue rtv2(1, 0, 0, 0, sqrt2, -sqrt2, 0, sqrt2, sqrt2); // rotation about "2" axis

  RankTwoTensor rot0(rtv0);
  RankTwoTensor rot0T = rot0.transpose();
  RankTwoTensor rot1(rtv1);
  RankTwoTensor rot1T = rot1.transpose();
  RankTwoTensor rot2(rtv2);
  RankTwoTensor rot2T = rot2.transpose();
  RankTwoTensor rot = rot0*rot1*rot2;

  RankTwoTensor answer;
  RankTwoTensor m3;

  // the following "answer"s come from mathematica of course!

  // rotate about "0" axis with RealTensorValue, then back again with RankTwoTensor
  m3 = _m3;
  answer = RankTwoTensor(-4, 3, 6.363961, 3, 0, -2.1213403, 6.363961, -2.1213403, 9);
  m3.rotate(rtv0);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - answer).L2norm(), 0.0001);
  m3.rotate(rot0T);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - _m3).L2norm(), 0.0001);

  // rotate about "1" axis with RealTensorValue, then back again with RankTwoTensor
  m3 = _m3;
  answer = RankTwoTensor(2, 5.656854, -4, 5.656854, -5, -2.828427, -4, -2.828427, 8);
  m3.rotate(rtv1);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - answer).L2norm(), 0.0001);
  m3.rotate(rot1T);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - _m3).L2norm(), 0.0001);

  // rotate about "2" axis with RealTensorValue, then back again with RankTwoTensor
  m3 = _m3;
  answer = RankTwoTensor(1, -sqrt2, 3.5355339, -sqrt2, 8, -7, 3.5355339, -7, -4);
  m3.rotate(rtv2);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - answer).L2norm(), 0.0001);
  m3.rotate(rot2T);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - _m3).L2norm(), 0.0001);

  // rotate with "rot"
  m3 = _m3;
  answer = RankTwoTensor(-2.9675144, -6.51776695, 5.6213203, -6.51776695, 5.9319805, -2.0857864, 5.6213203, -2.0857864, 2.0355339);
  m3.rotate(rot);
  CPPUNIT_ASSERT_DOUBLES_EQUAL(0, (m3 - answer).L2norm(), 0.0001);
}
// function to calculate rotated desired and current positions
void rotatePositions()
{
    Eigen::Rotation2D<float> rot2(curr_yaw);
    rot2 = rot2.inverse();
    //Eigen::Rotation2D<float> rot2(0.0);
    
    Eigen::Vector2f des_pos, curr_pos, curr_vel;
    des_pos << desired_pos.x, desired_pos.y;
    curr_pos << current_pos.x, current_pos.y;
    curr_vel << current_vel.x, current_vel.y;
    
    rot_desired_pos << (rot2*des_pos)[0],  (rot2*des_pos)[1],  desired_pos.z;
    rot_current_pos << (rot2*curr_pos)[0], (rot2*curr_pos)[1], current_pos.z;
    rot_current_vel << (rot2*curr_vel)[0], (rot2*curr_vel)[1], current_vel.z;
}
Esempio n. 7
0
osg::AnimationPath* createAnimationPath( float radius, float time )
{
    osg::ref_ptr<osg::AnimationPath> path = new osg::AnimationPath;
    path->setLoopMode( osg::AnimationPath::LOOP );
    
    unsigned int numSamples = 32;
    float delta_yaw = 2.0f * osg::PI/((float)numSamples - 1.0f);
    float delta_time = time / (float)numSamples;
    for ( unsigned int i=0; i<numSamples; ++i )
    {
        float yaw = delta_yaw * (float)i;
        osg::Vec3 pos( sinf(yaw)*radius, cosf(yaw)*radius, 0.0f );
        osg::Quat rot1( -yaw, osg::Z_AXIS );
		osg::Quat rot2( -yaw, osg::X_AXIS );
        path->insert( delta_time * (float)i, osg::AnimationPath::ControlPoint(pos, rot2*rot1) );
    }
    return path.release();    
}
Esempio n. 8
0
//==============================================================================
void DebugDrawer::drawSphere(F32 radius, I complexity)
{
#if 1
	Mat4 oldMMat = m_mMat;
	Mat4 oldVpMat = m_vpMat;

	setModelMatrix(m_mMat * Mat4(Vec4(0.0, 0.0, 0.0, 1.0),
		Mat3::getIdentity(), radius));

	begin(GL_LINES);

	// Pre-calculate the sphere points5
	F32 fi = getPi<F32>() / complexity;

	Vec3 prev(1.0, 0.0, 0.0);
	for(F32 th = fi; th < getPi<F32>() * 2.0 + fi; th += fi)
	{
		Vec3 p = Mat3(Euler(0.0, th, 0.0)) * Vec3(1.0, 0.0, 0.0);

		for(F32 th2 = 0.0; th2 < getPi<F32>(); th2 += fi)
		{
			Mat3 rot(Euler(th2, 0.0, 0.0));

			Vec3 rotPrev = rot * prev;
			Vec3 rotP = rot * p;

			pushBackVertex(rotPrev);
			pushBackVertex(rotP);

			Mat3 rot2(Euler(0.0, 0.0, getPi<F32>() / 2));

			pushBackVertex(rot2 * rotPrev);
			pushBackVertex(rot2 * rotP);
		}

		prev = p;
	}

	end();

	m_mMat = oldMMat;
	m_vpMat = oldVpMat;
#endif
}
Esempio n. 9
0
void URotableActor::Rotate(const FRotator& _rotator)
{
	FRotator rot = GetOwner()->GetActorRotation();

	rot.Add(_rotator.Pitch, _rotator.Yaw, _rotator.Roll);
	float pitch = rot.Pitch;
	if (pitch > 20)
		pitch = 20;
	else if (pitch < -20)
		pitch = -20;

	float roll = rot.Roll;
	if (roll > 20)
		roll = 20;
	else if (rot.Roll < -20)
		roll = -20;

	FRotator rot2(pitch, rot.Yaw, roll);

	this->GetOwner()->SetActorRelativeRotation(rot2);
}
Esempio n. 10
0
UInt solve_cubic(double a, double b, double c, double* roots) {
	double p = b - a*a / 3;
	double q = c + (2 * a*a*a - 9 * a * b) / 27;
	if (p == 0 && q == 0) {
		roots[0] = -a / 3;
		return 1;
	}
	complex<double> u;
	if (q > 0) {
		u = curt(q/2 + sqrt(complex<double>(q*q / 4  +  p*p*p / 27)));
	} else {
		u = curt(q/2 - sqrt(complex<double>(q*q / 4  +  p*p*p / 27)));
	}
	// now for the complex part
	//              rot1(1,    0)
	complex<double> rot2(-0.5, sqrt(3.0) / 2);
	complex<double> rot3(-0.5, -sqrt(3.0) / 2);
	complex<double> x1 = p / (3.0 * u)         -  u        -  a / 3.0;
	complex<double> x2 = p / (3.0 * u * rot2)  -  u * rot2 -  a / 3.0;
	complex<double> x3 = p / (3.0 * u * rot3)  -  u * rot3 -  a / 3.0;
	// check if the solutions are real
	UInt count = 0;
	if (abs(x1.imag()) < 0.00001) {
		roots[count] = x1.real();
		count += 1;
	}
	if (abs(x2.imag()) < 0.00001) {
		roots[count] = x2.real();
		count += 1;
	}
	if (abs(x3.imag()) < 0.00001) {
		roots[count] = x3.real();
		count += 1;
	}
	return count;
}
Esempio n. 11
0
glm::vec3 getEulerFromRotationMatrix(glm::mat3 rot, glm::vec3 curAngles)  // order of rotation x->y->z Rx*Ry*Rz 
// glm::translate(x....)
// glm::translate(y....)
// glm::translate(y....)
// x, y , z are angles

{	
	glm::vec3 radAngles = glm::radians(curAngles);
	glm::mat3 rotTransposed = glm::transpose(rot);
	float R11 = rotTransposed[0].x;
	float R12 = rotTransposed[0].y;
	float R13 = rotTransposed[0].z;
	float R21 = rotTransposed[1].x;
	float R22 = rotTransposed[1].y;
	float R23 = rotTransposed[1].z;
	float R31 = rotTransposed[2].x;
	float R32 = rotTransposed[2].y;
	float R33 = rotTransposed[2].z;
	//printf("\nR11 = %f\n",R11);
	//printf("R12 = %f\n",R12);
	//printf("R13 = %f\n",R13);
	//printf("R21 = %f\n",R21);
	//printf("R22 = %f\n",R22);
	//printf("R23 = %f\n",R23);
	//printf("R31 = %f\n",R31);
	//printf("R32 = %f\n",R32);
	//printf("R33 = %f\n",R33);



	// Find 2 possible y values
	float y1 = asin(R13);
	float y2 = M_PI - y1;

	// Find possible z values
	if (abs(y1-M_PI_2)>0.0001) // check whether cos(y) = 0 or not (y = pi/2)
	{
		// y != M_PI_2
		float cy1 = cos(y1); float cy2 = cos(y2);
		float z1 = atan2(-R12/cy1, R11/cy1);
		float z2 = atan2(-R12/cy2, R11/cy2);
		// Find 2 Possible x
		float x1 = atan2(-R23/cy1, R33/cy1);
		float x2 = atan2(-R23/cy2, R33/cy2);

		glm::vec3 rot1(x1,y1,z1);
		glm::vec3 rot2(x2,y2,z2);

		glm::vec3 sub1 = rot1-radAngles;
		glm::vec3 sub2 = rot2-radAngles;
		//qDebug("Sub1 length = %f", glm::length(sub1));
		//qDebug("Sub2 length = %f", glm::length(sub2));

		int r1 = (int)(glm::degrees(sub1.x)) % 360;		
		int r2 = (int)(glm::degrees(sub2.x)) % 360;
		if (r1<r2)
			return glm::degrees(rot1);
		else return glm::degrees(rot2);
	}
	else
	{
		// cos(y) = 0
		// calculate possible x+z
		float xz1 = atan2(R21,R22);
		float x1 = radAngles.x;  // remain x
		float z1 = -x1 + xz1;

		float xz2 = atan2(R12,R22);
		float x2 = radAngles.x;
		float z2 = x2 + xz2;

		glm::vec3 rot1(x1,y1,z1);
		glm::vec3 rot2(x2,y2,z2);

		glm::vec3 sub1 = rot1-radAngles;
		glm::vec3 sub2 = rot2-radAngles;
		if (glm::length(sub1)<glm::length(sub2))
			return glm::degrees(rot1);
		else return glm::degrees(rot2);
	}
}
Esempio n. 12
0
/*******************************************************************************
* Function Name  : AES_decrypt
* Description    : Decrypts one block of 16 bytes
* Input          : - input_pointer: input block address
*                  - expkey: decryption key 
* Output         : output_pointer: output block address
* Return         : None
*******************************************************************************/
void AES_decrypt(u8* input_pointer, u32* output_pointer, u32* expkey)
{
  register u32 s0;
  register u32 s1;
  register u32 s2;
  register u32 s3;
  register u32 t0;
  register u32 t1;
  register u32 t2;
  register u32 t3;
  register int r = 10 >> 1;
  register u32* local_pointer = expkey + (40);
  
    //added ***
  register u32 copy0;
  register u32 copy1;
  register u32 copy2;
  register u32 copy3;
  
  copy0 = *input_pointer;
  copy0 =copy0<<8;
  copy0 |= *(input_pointer+1);
  copy0 =copy0<<8;
  copy0 |= *(input_pointer+2);
  copy0 =copy0<<8;
  copy0 |= *(input_pointer+3);
  
  copy1 = *(input_pointer+4);
  copy1 =copy1<<8;
  copy1 |= *(input_pointer+5);
  copy1 =copy1<<8;
  copy1 |= *(input_pointer+6);
  copy1 =copy1<<8;
  copy1 |= *(input_pointer+7);
  
  copy2 = *(input_pointer+8);
  copy2 =copy2<<8;
  copy2 |= *(input_pointer+9);
  copy2 =copy2<<8;
  copy2 |= *(input_pointer+10);
  copy2 =copy2<<8;
  copy2 |= *(input_pointer+11);
  
  copy3 = *(input_pointer+12);
  copy3 =copy3<<8;
  copy3 |= *(input_pointer+13);
  copy3 =copy3<<8;
  copy3 |= *(input_pointer+14);
  copy3 =copy3<<8;
  copy3 |= *(input_pointer+15);
  
  s0 = copy0^ local_pointer[0];
  s1 = copy1 ^ local_pointer[1];
  s2 = copy2 ^ local_pointer[2];
  s3 = copy3 ^ local_pointer[3];
  
  for (;;) 
  {
    local_pointer -= 8;
    
    t0 =      dec_table[byte0(s0)]  ^
      rot1(dec_table[byte1(s3)]) ^
        rot2(dec_table[byte2(s2)]) ^
          rot3(dec_table[byte3(s1)]) ^
            local_pointer[4];
    t1 =      dec_table[byte0(s1)]  ^
      rot1(dec_table[byte1(s0)]) ^
        rot2(dec_table[byte2(s3)]) ^
          rot3(dec_table[byte3(s2)]) ^
            local_pointer[5];
    t2 =      dec_table[byte0(s2)]  ^
      rot1(dec_table[byte1(s1)]) ^
        rot2(dec_table[byte2(s0)]) ^
          rot3(dec_table[byte3(s3)]) ^
            local_pointer[6];
    t3 =      dec_table[byte0(s3)]  ^
      rot1(dec_table[byte1(s2)]) ^
        rot2(dec_table[byte2(s1)]) ^
          rot3(dec_table[byte3(s0)]) ^
            local_pointer[7];
    
    if (--r == 0) 
    {
      break;
    }
    
    s0 =      dec_table[byte0(t0)]  ^
      rot1(dec_table[byte1(t3)]) ^
        rot2(dec_table[byte2(t2)]) ^
          rot3(dec_table[byte3(t1)]) ^
            local_pointer[0];
    s1 =      dec_table[byte0(t1)]  ^
      rot1(dec_table[byte1(t0)]) ^
        rot2(dec_table[byte2(t3)]) ^
          rot3(dec_table[byte3(t2)]) ^
            local_pointer[1];
    s2 =      dec_table[byte0(t2)]  ^
      rot1(dec_table[byte1(t1)]) ^
        rot2(dec_table[byte2(t0)]) ^
          rot3(dec_table[byte3(t3)]) ^
            local_pointer[2];
    s3 =      dec_table[byte0(t3)]  ^
      rot1(dec_table[byte1(t2)]) ^
        rot2(dec_table[byte2(t1)]) ^
          rot3(dec_table[byte3(t0)]) ^
            local_pointer[3];	   
  }
  
  output_pointer[0] = WORD8_TO_WORD32( InvSbox[byte0(t0)],
                                      InvSbox[byte1(t3)],
                                      InvSbox[byte2(t2)],
                                      InvSbox[byte3(t1)]) ^ local_pointer[0];
  output_pointer[1] = WORD8_TO_WORD32( InvSbox[byte0(t1)],
                                      InvSbox[byte1(t0)],
                                      InvSbox[byte2(t3)],
                                      InvSbox[byte3(t2)]) ^ local_pointer[1];
  output_pointer[2] = WORD8_TO_WORD32( InvSbox[byte0(t2)],
                                      InvSbox[byte1(t1)],
                                      InvSbox[byte2(t0)],
                                      InvSbox[byte3(t3)]) ^ local_pointer[2];
  output_pointer[3] = WORD8_TO_WORD32( InvSbox[byte0(t3)],
                                      InvSbox[byte1(t2)],
                                      InvSbox[byte2(t1)],
                                      InvSbox[byte3(t0)]) ^ local_pointer[3];
}
Esempio n. 13
0
/*******************************************************************************
* Function Name  : AES_keyschedule_dec
* Description    : According to key computes the expanded key (expkey) for AES128 
*                  decryption.
* Input          : key: user key
* Output         : expkey: expanded key
* Return         : None
*******************************************************************************/
void AES_keyschedule_dec(u8* key, u32* expkey)
{
  register u32* local_pointer = expkey;
  register int i = 0;
  register u32 copy0;
  register u32 copy1;
  register u32 copy2;
  register u32 copy3;
  
  AES_keyschedule_enc(key,expkey);
  
  local_pointer[0] = *key;
  local_pointer[0] =local_pointer[0]<<8;
  local_pointer[0] |= *(key+1);
  local_pointer[0] =local_pointer[0]<<8;
  local_pointer[0] |= *(key+2);
  local_pointer[0] =local_pointer[0]<<8;
  local_pointer[0] |= *(key+3);
  
  local_pointer[1] = *(key+4);
  local_pointer[1] =local_pointer[1]<<8;
  local_pointer[1] |= *(key+5);
  local_pointer[1] =local_pointer[1]<<8;
  local_pointer[1] |= *(key+6);
  local_pointer[1] =local_pointer[1]<<8;
  local_pointer[1] |= *(key+7);
  
  local_pointer[2] = *(key+8);
  local_pointer[2] =local_pointer[2]<<8;
  local_pointer[2] |= *(key+9);
  local_pointer[2] =local_pointer[2]<<8;
  local_pointer[2] |= *(key+10);
  local_pointer[2] =local_pointer[2]<<8;
  local_pointer[2] |= *(key+11);
  
  local_pointer[3] = *(key+12);
  local_pointer[3] =local_pointer[3]<<8;
  local_pointer[3] |= *(key+13);
  local_pointer[3] =local_pointer[3]<<8;
  local_pointer[3] |= *(key+14);
  local_pointer[3] =local_pointer[3]<<8;
  local_pointer[3] |= *(key+15);
  
  
//  local_pointer[0] =  key[0];
//  local_pointer[1] =  key[1];
//  local_pointer[2] =  key[2];
//  local_pointer[3] =  key[3];
  
  for (i = 1; i <10; i++) 
  {
    local_pointer += 4;
    copy0 = local_pointer[0]; 
    copy1 = local_pointer[1];
    copy2 = local_pointer[2];
    copy3 = local_pointer[3];
    local_pointer[0] =      dec_table[Sbox[byte0(copy0)]]  ^
      rot1(dec_table[Sbox[byte1(copy0)]]) ^
        rot2(dec_table[Sbox[byte2(copy0)]]) ^
          rot3(dec_table[Sbox[byte3(copy0)]]);
    local_pointer[1] =      dec_table[Sbox[byte0(copy1)]]  ^
      rot1(dec_table[Sbox[byte1(copy1)]]) ^
        rot2(dec_table[Sbox[byte2(copy1)]]) ^
          rot3(dec_table[Sbox[byte3(copy1)]]);
    local_pointer[2] =      dec_table[Sbox[byte0(copy2)]]  ^
      rot1(dec_table[Sbox[byte1(copy2)]]) ^
        rot2(dec_table[Sbox[byte2(copy2)]]) ^
          rot3(dec_table[Sbox[byte3(copy2)]]);
    local_pointer[3] =      dec_table[Sbox[byte0(copy3)]]  ^
      rot1(dec_table[Sbox[byte1(copy3)]]) ^
        rot2(dec_table[Sbox[byte2(copy3)]]) ^
          rot3(dec_table[Sbox[byte3(copy3)]]);
  }
}
Esempio n. 14
0
VolumeCollection* AnalyzeVolumeReader::readNifti(const std::string &fileName, bool standalone, int volId)
    throw (tgt::FileException, std::bad_alloc)
{
    LINFO("Loading nifti file " << fileName);

    std::ifstream file(fileName.c_str(), std::ios::in | std::ios::binary);
    if(!file) {
        throw tgt::FileNotFoundException("Failed to open file: ", fileName);
    }

    nifti_1_header header;
    if (!file.read((char*)&header, sizeof(header))) {
        throw tgt::CorruptedFileException("Failed to read header!", fileName);
    }

    file.close();

    bool bigEndian = false;
    //check if swap is necessary:
    if((header.dim[0] < 0) || (header.dim[0] > 15)) {
        bigEndian = true;
        header.swapEndianess();
    }

    if(header.sizeof_hdr != 348) {
        throw tgt::CorruptedFileException("Invalid header.sizeof_hdr", fileName);
    }

    if(!( (header.magic[0] == 'n') && (header.magic[2] == '1') && (header.magic[3] == 0) ))
        throw tgt::CorruptedFileException("Not a Nifti header!", fileName);

    if(header.magic[1] == '+') {
        if(!standalone)
            LWARNING("Tried to read standalone Nifti as hdr+img!");
        standalone = true;
    }
    else if(header.magic[1] == 'i') {
        if(!standalone)
            LWARNING("Tried to read hdr+img Nifti as standalone!");
        standalone = false;
    }
    else
        throw tgt::CorruptedFileException("Not a Nifti header!", fileName);

    ivec3 dimensions;
    dimensions.x = header.dim[1];
    dimensions.y = header.dim[2];
    dimensions.z = header.dim[3];
    LINFO("Resolution: " << dimensions);

    int numVolumes = header.dim[4];
    LINFO("Number of volumes: " << numVolumes);

    if (hor(lessThanEqual(dimensions, ivec3(0)))) {
        LERROR("Invalid resolution or resolution not specified: " << dimensions);
        throw tgt::CorruptedFileException("error while reading data", fileName);
    }

    vec3 spacing;
    spacing.x = header.pixdim[1];
    spacing.y = header.pixdim[2];
    spacing.z = header.pixdim[3];
    LINFO("Spacing: " << spacing);

    int timeunit = XYZT_TO_TIME(header.xyzt_units);
    int spaceunit = XYZT_TO_SPACE(header.xyzt_units);
    LINFO("timeunit: " << timeunit << " spaceunit: " << spaceunit);

    float dt = header.pixdim[4];
    float toffset = header.toffset;
    switch(timeunit) {
        case NIFTI_UNITS_SEC:
            dt *= 1000.0f;
            toffset *= 1000.0f;
            break;
        case NIFTI_UNITS_MSEC:
            //nothing to do
            break;
        case NIFTI_UNITS_USEC:
            dt /= 1000.0f;
            toffset /= 1000.0f;
            break;
    }

    switch(spaceunit) {
        case NIFTI_UNITS_MM:
            //nothing to do
            break;
        case NIFTI_UNITS_METER:
            spacing *= 1000.0f;
            LWARNING("Units: meter");
            break;
        case NIFTI_UNITS_MICRON:
            spacing /= 1000.0f;
            LWARNING("Units: micron");
            break;
        case NIFTI_UNITS_UNKNOWN:
        default:
            LWARNING("Unknown space unit!");
            break;
    }

    LINFO("Datatype: " << header.datatype);
    std::string voreenVoxelType = "";
    RealWorldMapping denormalize;
    bool applyRWM = header.scl_slope != 0.0f;

    switch(header.intent_code) {
        case IC_INTENT_SYMMATRIX:  /* parameter at each voxel is symmetrical matrix */
            //TODO: should be relatively easy (=> tensors)
        case IC_INTENT_DISPVECT:   /* parameter at each voxel is displacement vector */
        case IC_INTENT_VECTOR:     /* parameter at each voxel is vector */
            //TODO: should be relatively easy
        case IC_INTENT_GENMATRIX:  /* parameter at each voxel is matrix */
            //TODO: should be relatively easy
        case IC_INTENT_POINTSET:   /* value at each voxel is spatial coordinate (vertices/nodes of surface mesh) */
        case IC_INTENT_TRIANGLE:   /* value at each voxel is spatial coordinate (vertices/nodes of surface mesh) */
        case IC_INTENT_QUATERNION:
            throw tgt::UnsupportedFormatException("Unsupported intent code!");
            break;
        case IC_INTENT_ESTIMATE:   /* parameter for estimate in intent_name */
        case IC_INTENT_LABEL:      /* parameter at each voxel is index to label defined in aux_file */
        case IC_INTENT_NEURONAME:  /* parameter at each voxel is index to label in NeuroNames label set */
        case IC_INTENT_DIMLESS:    /* dimensionless value */
        case IC_INTENT_NONE:
            break;
        default:
            LWARNING("Unhandled intent code");
            break;
    }
    //if (header.intent_code == IC_INTENT_SYMMATRIX) {
        //h.objectModel_ = "TENSOR_FUSION_LOW";
    //}
    if(voreenVoxelType == "") {
        switch(header.datatype) {
            case DT_UNSIGNED_CHAR:
                voreenVoxelType = "uint8";
                denormalize = RealWorldMapping::createDenormalizingMapping<uint8_t>();
                break;
            case DT_SIGNED_SHORT:
                voreenVoxelType = "int16";
                denormalize = RealWorldMapping::createDenormalizingMapping<int16_t>();
                break;
            case DT_SIGNED_INT:
                voreenVoxelType = "int32";
                denormalize = RealWorldMapping::createDenormalizingMapping<int32_t>();
                break;
            case DT_FLOAT:
                voreenVoxelType = "float";
                break;
            case DT_DOUBLE:
                voreenVoxelType = "double";
                break;
            case DT_RGB:
                voreenVoxelType = "Vector3(uint8)";
                applyRWM = false;
                break;
            case DT_RGBA32:         /* 4 byte RGBA (32 bits/voxel)  */
                voreenVoxelType = "Vector4(uint8)";
                applyRWM = false;
                break;
            case DT_INT8:           /* signed char (8 bits)         */
                voreenVoxelType = "int8";
                break;
            case DT_UINT16:         /* unsigned short (16 bits)     */
                voreenVoxelType = "uint16";
                denormalize = RealWorldMapping::createDenormalizingMapping<uint16_t>();
                break;
            case DT_UINT32:         /* unsigned int (32 bits)       */
                voreenVoxelType = "uint32";
                denormalize = RealWorldMapping::createDenormalizingMapping<uint32_t>();
                break;
            case DT_INT64:          /* long long (64 bits)          */
            case DT_UINT64:         /* unsigned long long (64 bits) */
            case DT_FLOAT128:       /* long double (128 bits)       */
            case DT_COMPLEX128:     /* double pair (128 bits)       */
            case DT_COMPLEX256:     /* long double pair (256 bits)  */
            case DT_ALL:
            case DT_COMPLEX:
            case 0: //DT_NONE/DT_UNKNOWN
            case DT_BINARY:
            default:
                throw tgt::UnsupportedFormatException("Unsupported datatype!");
        }
    }

    RealWorldMapping rwm(header.scl_slope, header.scl_inter, "");

    int headerskip = static_cast<uint16_t>(header.vox_offset);

    std::string rawFilename = fileName;
    if(!standalone)
        rawFilename = getRelatedImgFileName(fileName);

    mat4 pToW = mat4::identity;

    //Calculate transformation:
    if(header.sform_code > 0) {
        mat4 vToW(header.srow_x[0], header.srow_x[1], header.srow_x[2], header.srow_x[3],
                  header.srow_y[0], header.srow_y[1], header.srow_y[2], header.srow_y[3],
                  header.srow_z[0], header.srow_z[1], header.srow_z[2], header.srow_z[3],
                  0.0f, 0.0f, 0.0f, 1.0f);

        mat4 wToV = mat4::identity;
        if(!vToW.invert(wToV)) {
            LERROR("Failed to invert voxel to world matrix!");
        }

        mat4 vToP = mat4::createScale(spacing); //no offset
        pToW = vToP * wToV;
    }
    else if(header.qform_code > 0) {
        float b = header.quatern_b;
        float c = header.quatern_c;
        float d = header.quatern_d;
        float a = static_cast<float>(sqrt(1.0-(b*b+c*c+d*d)));

        mat4 rot2(a*a+b*b-c*c-d*d,   2*b*c-2*a*d,       2*b*d+2*a*c,     0.0f,
                  2*b*c+2*a*d,       a*a+c*c-b*b-d*d,   2*c*d-2*a*b,     0.0f,
                  2*b*d-2*a*c,       2*c*d+2*a*b,       a*a+d*d-c*c-b*b, 0.0f,
                  0.0f,              0.0f,              0.0f,            1.0f);

        float qfac = header.pixdim[0];
        if(fabs(qfac) < 0.1f)
            qfac = 1.0f;
        mat4 sc = mat4::createScale(vec3(1.0f, 1.0f, qfac));

        mat4 os = mat4::createTranslation(vec3(header.qoffset_x, header.qoffset_y, header.qoffset_z));
        pToW = os * rot2 * sc;
    }

    // Nifti transformations give us the center of the first voxel, we translate to correct:
    pToW = pToW * mat4::createTranslation(-spacing * 0.5f);

    VolumeCollection* vc = new VolumeCollection();
    size_t volSize = hmul(tgt::svec3(dimensions)) * (header.bitpix / 8);

    int start = 0;
    int stop = numVolumes;
    if(volId != -1) {
        //we want to load a single volume:
        start = volId;
        stop = start + 1;
    }

    for(int i=start; i<stop; i++) {
        VolumeRepresentation* volume = new VolumeDisk(rawFilename, voreenVoxelType, dimensions, headerskip + (i * volSize), bigEndian);
        Volume* vh = new Volume(volume, spacing, vec3(0.0f));

        VolumeURL origin(fileName);
        origin.addSearchParameter("volumeId", itos(i));
        vh->setOrigin(origin);

        vh->setPhysicalToWorldMatrix(pToW);
        vh->setMetaDataValue<StringMetaData>("Description", std::string(header.descrip));
        //vh->addMetaData("ActualFrameDuration", new IntMetaData(ih_.frame_duration));
        //vh->addMetaData("FrameTime", new IntMetaData(ih_.frame_start_time));
        vh->setMetaDataValue<IntMetaData>("FrameTime", static_cast<int>(toffset + (i * dt)));
        if(applyRWM)
            vh->setRealWorldMapping(RealWorldMapping::combine(denormalize, rwm));

        vc->add(vh);
    }

    return vc;
}
Esempio n. 15
0
void
testProcrustesImp ()
{
    // Test the empty case:
    IMATH_INTERNAL_NAMESPACE::M44d id = 
        procrustesRotationAndTranslation ((IMATH_INTERNAL_NAMESPACE::Vec3<T>*) 0, 
                                          (IMATH_INTERNAL_NAMESPACE::Vec3<T>*) 0,
                                          (T*) 0,
                                          0);
    assert (id == IMATH_INTERNAL_NAMESPACE::M44d());

    id = procrustesRotationAndTranslation ((IMATH_INTERNAL_NAMESPACE::Vec3<T>*) 0, 
                                           (IMATH_INTERNAL_NAMESPACE::Vec3<T>*) 0,
                                           0);
    assert (id == IMATH_INTERNAL_NAMESPACE::M44d());

    // First we'll test with a bunch of known translation/rotation matrices
    // to make sure we get back exactly the same points:
    IMATH_INTERNAL_NAMESPACE::M44d m;
    m.makeIdentity();
    testTranslationRotationMatrix<T> (m);

    m.translate (IMATH_INTERNAL_NAMESPACE::V3d(3.0, 5.0, -0.2));
    testTranslationRotationMatrix<T> (m);

    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(M_PI, 0, 0));
    testTranslationRotationMatrix<T> (m);
    
    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(0, M_PI/4.0, 0));
    testTranslationRotationMatrix<T> (m);

    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(0, 0, -3.0/4.0 * M_PI));
    testTranslationRotationMatrix<T> (m);

    m.makeIdentity();
    testWithTranslateRotateAndScale<T> (m);

    m.translate (IMATH_INTERNAL_NAMESPACE::V3d(0.4, 6.0, 10.0));
    testWithTranslateRotateAndScale<T> (m);

    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(M_PI, 0, 0));
    testWithTranslateRotateAndScale<T> (m);

    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(0, M_PI/4.0, 0));
    testWithTranslateRotateAndScale<T> (m);

    m.rotate (IMATH_INTERNAL_NAMESPACE::V3d(0, 0, -3.0/4.0 * M_PI));
    testWithTranslateRotateAndScale<T> (m);

    m.scale (IMATH_INTERNAL_NAMESPACE::V3d(2.0, 2.0, 2.0));
    testWithTranslateRotateAndScale<T> (m);

    m.scale (IMATH_INTERNAL_NAMESPACE::V3d(0.01, 0.01, 0.01));
    testWithTranslateRotateAndScale<T> (m);

    // Now we'll test with some random point sets and verify
    // the various Procrustes properties:
    std::vector<IMATH_INTERNAL_NAMESPACE::Vec3<T> > fromPoints;
    std::vector<IMATH_INTERNAL_NAMESPACE::Vec3<T> > toPoints;
    fromPoints.clear(); toPoints.clear();

    for (size_t i = 0; i < 4; ++i)
    {
        const T theta = T(2*i) / T(M_PI);
        fromPoints.push_back (IMATH_INTERNAL_NAMESPACE::Vec3<T>(cos(theta), sin(theta), 0));
        toPoints.push_back (IMATH_INTERNAL_NAMESPACE::Vec3<T>(cos(theta + M_PI/3.0), sin(theta + M_PI/3.0), 0));
    }
    verifyProcrustes (fromPoints, toPoints);

    IMATH_INTERNAL_NAMESPACE::Rand48 random (1209);
    for (size_t numPoints = 1; numPoints < 10; ++numPoints)
    {
        fromPoints.clear(); toPoints.clear();
        for (size_t i = 0; i < numPoints; ++i)
        {
            fromPoints.push_back (IMATH_INTERNAL_NAMESPACE::Vec3<T>(random.nextf(), random.nextf(), random.nextf()));
            toPoints.push_back (IMATH_INTERNAL_NAMESPACE::Vec3<T>(random.nextf(), random.nextf(), random.nextf()));
        }
    }
    verifyProcrustes (fromPoints, toPoints);

    // Test with some known matrices of varying degrees of quality:
    testProcrustesWithMatrix<T> (m);

    m.translate (IMATH_INTERNAL_NAMESPACE::Vec3<T>(3, 4, 1));
    testProcrustesWithMatrix<T> (m);

    m.translate (IMATH_INTERNAL_NAMESPACE::Vec3<T>(-10, 2, 1));
    testProcrustesWithMatrix<T> (m);

    IMATH_INTERNAL_NAMESPACE::Eulerd rot (M_PI/3.0, 3.0*M_PI/4.0, 0);
    m = m * rot.toMatrix44();
    testProcrustesWithMatrix<T> (m);

    m.scale (IMATH_INTERNAL_NAMESPACE::Vec3<T>(1.5, 6.4, 2.0));
    testProcrustesWithMatrix<T> (m);

    IMATH_INTERNAL_NAMESPACE::Eulerd rot2 (1.0, M_PI, M_PI/3.0);
    m = m * rot.toMatrix44();

    m.scale (IMATH_INTERNAL_NAMESPACE::Vec3<T>(-1, 1, 1));
    testProcrustesWithMatrix<T> (m);

    m.scale (IMATH_INTERNAL_NAMESPACE::Vec3<T>(1, 0.001, 1));
    testProcrustesWithMatrix<T> (m);

    m.scale (IMATH_INTERNAL_NAMESPACE::Vec3<T>(1, 1, 0));
    testProcrustesWithMatrix<T> (m);
}
Esempio n. 16
0
/*******************************************************************************  
* Function Name  : AES_decrypt  
* Description    : Decrypts one block of 16 bytes  
* Input          : - input_pointer: input block address  
*                  - expkey: decryption key   
* Output         : output_pointer: output block address  
* Return         : None  
*******************************************************************************/   
void AES_decrypt(ot_u32* input_pointer, ot_u32* output_pointer, ot_u32* expkey) {
#if (AES_USEHW == ENABLED)

#elif (AES_USEFAST == ENABLED)   
  register ot_u32 s0;   
  register ot_u32 s1;   
  register ot_u32 s2;   
  register ot_u32 s3;   
  register ot_u32 t0;   
  register ot_u32 t1;   
  register ot_u32 t2;   
  register ot_u32 t3;   
  register int r = 10 >> 1;   
  register ot_u32* local_pointer = expkey + (40);   
   
  s0 = input_pointer[0] ^ local_pointer[0];   
  s1 = input_pointer[1] ^ local_pointer[1];   
  s2 = input_pointer[2] ^ local_pointer[2];   
  s3 = input_pointer[3] ^ local_pointer[3];   
   
  for (;;)    
  {   
    local_pointer -= 8;   
       
    t0 =      dec_table[byte0(s0)]  ^   
         rot1(dec_table[byte1(s3)]) ^   
         rot2(dec_table[byte2(s2)]) ^   
         rot3(dec_table[byte3(s1)]) ^   
         local_pointer[4];   
    t1 =      dec_table[byte0(s1)]  ^   
         rot1(dec_table[byte1(s0)]) ^   
         rot2(dec_table[byte2(s3)]) ^   
         rot3(dec_table[byte3(s2)]) ^   
         local_pointer[5];   
    t2 =      dec_table[byte0(s2)]  ^   
         rot1(dec_table[byte1(s1)]) ^   
         rot2(dec_table[byte2(s0)]) ^   
         rot3(dec_table[byte3(s3)]) ^   
         local_pointer[6];   
    t3 =      dec_table[byte0(s3)]  ^   
         rot1(dec_table[byte1(s2)]) ^   
         rot2(dec_table[byte2(s1)]) ^   
         rot3(dec_table[byte3(s0)]) ^   
         local_pointer[7];   
       
    if (--r == 0)    
    {   
      break;   
    }   
       
    s0 =      dec_table[byte0(t0)]  ^   
         rot1(dec_table[byte1(t3)]) ^   
         rot2(dec_table[byte2(t2)]) ^   
         rot3(dec_table[byte3(t1)]) ^   
         local_pointer[0];   
    s1 =      dec_table[byte0(t1)]  ^   
         rot1(dec_table[byte1(t0)]) ^   
         rot2(dec_table[byte2(t3)]) ^   
         rot3(dec_table[byte3(t2)]) ^   
         local_pointer[1];   
    s2 =      dec_table[byte0(t2)]  ^   
         rot1(dec_table[byte1(t1)]) ^   
         rot2(dec_table[byte2(t0)]) ^   
         rot3(dec_table[byte3(t3)]) ^   
         local_pointer[2];   
    s3 =      dec_table[byte0(t3)]  ^   
         rot1(dec_table[byte1(t2)]) ^   
         rot2(dec_table[byte2(t1)]) ^   
         rot3(dec_table[byte3(t0)]) ^   
         local_pointer[3];        
  }   
     
  output_pointer[0] = WORD8_TO_WORD32( InvSbox[byte0(t0)],   
                                       InvSbox[byte1(t3)],   
                                       InvSbox[byte2(t2)],   
                                       InvSbox[byte3(t1)]) ^ local_pointer[0];   
  output_pointer[1] = WORD8_TO_WORD32( InvSbox[byte0(t1)],   
                                       InvSbox[byte1(t0)],   
                                       InvSbox[byte2(t3)],   
                                       InvSbox[byte3(t2)]) ^ local_pointer[1];   
  output_pointer[2] = WORD8_TO_WORD32( InvSbox[byte0(t2)],   
                                       InvSbox[byte1(t1)],   
                                       InvSbox[byte2(t0)],   
                                       InvSbox[byte3(t3)]) ^ local_pointer[2];   
  output_pointer[3] = WORD8_TO_WORD32( InvSbox[byte0(t3)],   
                                       InvSbox[byte1(t2)],   
                                       InvSbox[byte2(t1)],   
                                       InvSbox[byte3(t0)]) ^ local_pointer[3];

#elif (AES_USELITE == ENABLED)
      /* Register: ask to the compiler to maintain this variable in the   
   processor's registers and don't store it in RAM */   
  register ot_u32 t0;    
  register ot_u32 t1;   
  register ot_u32 t2;   
  register ot_u32 t3;     
  register ot_u32 s0;   
  register ot_u32 s1;   
  register ot_u32 s2;   
  register ot_u32 s3;   
  register int r =  10; /* Count the round */    
  register ot_u32* local_pointer = expkey + 40;   
  ot_u32 f2,f4,f8;   
       
  s0 = input_pointer[0] ^ local_pointer[0];   
  s1 = input_pointer[1] ^ local_pointer[1];   
  s2 = input_pointer[2] ^ local_pointer[2];   
  s3 = input_pointer[3] ^ local_pointer[3];   
       
  /* First add key: before start the rounds */   
  local_pointer -= 8;   
       
  for (;;) /* Start round */    
  {   
    t0 = WORD8_TO_WORD32( InvSbox[byte0(s0)],   
                          InvSbox[byte1(s3)],   
                          InvSbox[byte2(s2)],   
                          InvSbox[byte3(s1)]) ^ local_pointer[4];   
    t1 = WORD8_TO_WORD32( InvSbox[byte0(s1)],   
                          InvSbox[byte1(s0)],   
                          InvSbox[byte2(s3)],   
                          InvSbox[byte3(s2)]) ^ local_pointer[5];   
    t2 = WORD8_TO_WORD32( InvSbox[byte0(s2)],   
                          InvSbox[byte1(s1)],   
                          InvSbox[byte2(s0)],   
                          InvSbox[byte3(s3)]) ^ local_pointer[6];   
    t3 = WORD8_TO_WORD32( InvSbox[byte0(s3)],   
                          InvSbox[byte1(s2)],   
                          InvSbox[byte2(s1)],   
                          InvSbox[byte3(s0)]) ^ local_pointer[7];   
    /*End of InvSbox,  INVshiftRow,  add key*/   
    s0=inv_mcol(t0);   
    s1=inv_mcol(t1);   
    s2=inv_mcol(t2);   
    s3=inv_mcol(t3);   
    /*End of INVMix column */          
    local_pointer -= 4; /*Follow the key sheduler to choose the right round key*/   
         
    if (--r == 1)    
    {   
      break;   
    }   
     
  }/*End of round*/   
     
  /*Start last round :is the only one different from the other*/   
  t0 = WORD8_TO_WORD32( InvSbox[byte0(s0)],   
                        InvSbox[byte1(s3)],   
                        InvSbox[byte2(s2)],   
                        InvSbox[byte3(s1)]) ^ local_pointer[4];   
  t1 = WORD8_TO_WORD32( InvSbox[byte0(s1)],   
                        InvSbox[byte1(s0)],   
                        InvSbox[byte2(s3)],   
                        InvSbox[byte3(s2)]) ^ local_pointer[5];   
  t2 = WORD8_TO_WORD32( InvSbox[byte0(s2)],   
                        InvSbox[byte1(s1)],   
                        InvSbox[byte2(s0)],   
                        InvSbox[byte3(s3)]) ^ local_pointer[6];   
  t3 = WORD8_TO_WORD32( InvSbox[byte0(s3)],   
                        InvSbox[byte1(s2)],   
                        InvSbox[byte2(s1)],   
                        InvSbox[byte3(s0)]) ^ local_pointer[7];   
  output_pointer[0] = t0;   
  output_pointer[1] = t1;   
  output_pointer[2] = t2;   
  output_pointer[3] = t3;
#endif
}   
Esempio n. 17
0
/*******************************************************************************  
* Function Name  : AES_encrypt  
* Description    : Encrypts one block of 16 bytes  
* Input          : - input_pointer: input block address  
*                  - expkey: encryption key  
* Output         : output_pointer  
* Return         : None  
*******************************************************************************/   
void AES_encrypt(ot_u32* input_pointer, ot_u32* output_pointer, ot_u32* expkey) {
#if (AES_USEHW == ENABLED)

#elif (AES_USEFAST == ENABLED)
  register ot_u32 s0;   
  register ot_u32 s1;   
  register ot_u32 s2;   
  register ot_u32 s3;   
  register ot_u32 t0;   
  register ot_u32 t1;   
  register ot_u32 t2;   
  register ot_u32 t3;   
  register int r = 10 >> 1;   
  register ot_u32* local_pointer = expkey;   
     
  s0 = input_pointer[0] ^ local_pointer[0];   
  s1 = input_pointer[1] ^ local_pointer[1];   
  s2 = input_pointer[2] ^ local_pointer[2];   
  s3 = input_pointer[3] ^ local_pointer[3];   
     
  for (;;) {   
    t0 =      enc_table[byte0(s0)]  ^   
         rot1(enc_table[byte1(s1)]) ^   
         rot2(enc_table[byte2(s2)]) ^   
         rot3(enc_table[byte3(s3)]) ^   
         local_pointer[4];                                 
    t1 =      enc_table[byte0(s1)]  ^   
         rot1(enc_table[byte1(s2)]) ^   
         rot2(enc_table[byte2(s3)]) ^   
         rot3(enc_table[byte3(s0)]) ^   
         local_pointer[5];   
    t2 =      enc_table[byte0(s2)]  ^   
         rot1(enc_table[byte1(s3)]) ^   
         rot2(enc_table[byte2(s0)]) ^   
         rot3(enc_table[byte3(s1)]) ^   
         local_pointer[6];   
    t3 =      enc_table[byte0(s3)]  ^   
         rot1(enc_table[byte1(s0)]) ^   
         rot2(enc_table[byte2(s1)]) ^   
         rot3(enc_table[byte3(s2)]) ^   
         local_pointer[7];   
       
    local_pointer += 8;       
    if (--r == 0) {   
      break;   
    }   
       
    s0 =      enc_table[byte0(t0)]  ^   
         rot1(enc_table[byte1(t1)]) ^   
         rot2(enc_table[byte2(t2)]) ^   
         rot3(enc_table[byte3(t3)]) ^   
         local_pointer[0];   
    s1 =      enc_table[byte0(t1)]  ^   
         rot1(enc_table[byte1(t2)]) ^   
         rot2(enc_table[byte2(t3)]) ^   
         rot3(enc_table[byte3(t0)]) ^   
         local_pointer[1];   
    s2 =      enc_table[byte0(t2)]  ^   
         rot1(enc_table[byte1(t3)]) ^   
         rot2(enc_table[byte2(t0)]) ^   
         rot3(enc_table[byte3(t1)]) ^   
         local_pointer[2];   
    s3 =      enc_table[byte0(t3)]  ^   
         rot1(enc_table[byte1(t0)]) ^   
         rot2(enc_table[byte2(t1)]) ^   
         rot3(enc_table[byte3(t2)]) ^   
         local_pointer[3];   
  }   
     
  output_pointer[0] = WORD8_TO_WORD32( Sbox[byte0(t0)],   
                                       Sbox[byte1(t1)],   
                                       Sbox[byte2(t2)],   
                                       Sbox[byte3(t3)]) ^ local_pointer[0];   
  output_pointer[1] = WORD8_TO_WORD32( Sbox[byte0(t1)],   
                                       Sbox[byte1(t2)],   
                                       Sbox[byte2(t3)],   
                                       Sbox[byte3(t0)]) ^ local_pointer[1];   
  output_pointer[2] = WORD8_TO_WORD32( Sbox[byte0(t2)],   
                                       Sbox[byte1(t3)],   
                                       Sbox[byte2(t0)],   
                                       Sbox[byte3(t1)]) ^ local_pointer[2];   
  output_pointer[3] = WORD8_TO_WORD32( Sbox[byte0(t3)],   
                                       Sbox[byte1(t0)],   
                                       Sbox[byte2(t1)],   
                                       Sbox[byte3(t2)]) ^ local_pointer[3];

#elif (AES_USELITE == ENABLED)
    register ot_u32 t0;   
    register ot_u32 t1;   
    register ot_u32 t2;   
    register ot_u32 t3;     
    register ot_u32 s0;   
    register ot_u32 s1;   
    register ot_u32 s2;   
    register ot_u32 s3;   
    register int r = 10;    // Round counter
    register ot_u32* local_pointer = expkey;   
   
    s0 = input_pointer[0] ^ local_pointer[0];   
    s1 = input_pointer[1] ^ local_pointer[1];   
    s2 = input_pointer[2] ^ local_pointer[2];   
    s3 = input_pointer[3] ^ local_pointer[3];   
    local_pointer += 4;  
   
  // ADD KEY before start round
  for (;;)    
  {   
    t0 = WORD8_TO_WORD32( Sbox[byte0(s0)],   
                          Sbox[byte1(s1)],   
                          Sbox[byte2(s2)],   
                          Sbox[byte3(s3)]);   
    t1 = WORD8_TO_WORD32( Sbox[byte0(s1)],   
                          Sbox[byte1(s2)],   
                          Sbox[byte2(s3)],   
                          Sbox[byte3(s0)]);   
    t2 = WORD8_TO_WORD32( Sbox[byte0(s2)],   
                          Sbox[byte1(s3)],   
                          Sbox[byte2(s0)],   
                          Sbox[byte3(s1)]);   
    t3 = WORD8_TO_WORD32( Sbox[byte0(s3)],   
                          Sbox[byte1(s0)],   
                          Sbox[byte2(s1)],   
                          Sbox[byte3(s2)]);   
    /*End of SBOX + Shift ROW*/   
    s0 = fwd_mcol(t0)^local_pointer[0];   
    s1 = fwd_mcol(t1)^local_pointer[1];   
    s2 = fwd_mcol(t2)^local_pointer[2];   
    s3 = fwd_mcol(t3)^local_pointer[3];   
    /*End of mix colomn*/   
           
    local_pointer += 4;    
    if ( --r == 1)   
    {   
      break;   
    }   
     
  }/*End for(;;)*/   
       
  /*Start Last round*/   
  t0 = WORD8_TO_WORD32( Sbox[byte0(s0)],   
                        Sbox[byte1(s1)],   
                        Sbox[byte2(s2)],   
                        Sbox[byte3(s3)]);   
  t1 = WORD8_TO_WORD32( Sbox[byte0(s1)],   
                        Sbox[byte1(s2)],   
                        Sbox[byte2(s3)],   
                        Sbox[byte3(s0)]);   
  t2 = WORD8_TO_WORD32( Sbox[byte0(s2)],   
                        Sbox[byte1(s3)],   
                        Sbox[byte2(s0)],   
                        Sbox[byte3(s1)]);   
  t3 = WORD8_TO_WORD32( Sbox[byte0(s3)],   
                        Sbox[byte1(s0)],   
                        Sbox[byte2(s1)],   
                        Sbox[byte3(s2)]);   
               
  t0 ^= local_pointer[0];   
  t1 ^= local_pointer[1];   
  t2 ^= local_pointer[2];   
  t3 ^= local_pointer[3];   
       
  /*Store of the result of encryption*/   
  output_pointer[0] = t0;   
  output_pointer[1] = t1;   
  output_pointer[2] = t2;   
  output_pointer[3] = t3;
#endif
}   
Esempio n. 18
0
File: main.c Progetto: ajmas/NewSRT
int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *button_clear, *button_azel, *button_freq, *button_offset;
    GtkWidget *button_help;
    GdkColor color;
    int i, ii;
    int yr, da, hr, mn, sc;
    double secstart;
    char buf[64];
    GdkGeometry geometry;
    GdkWindowHints geo_mask;
//    GdkRectangle update_rect;
    sprintf(d1.catnam, "srt.cat");
    sprintf(d1.hlpnam, "srt.hlp");
    for (i = 0; i < argc - 1; i++) {
        sscanf(argv[i], "%63s", buf);
        if (strstr(buf, "-c") && strlen(buf) == 2)
            sscanf(argv[i + 1], "%63s", d1.catnam);
        if (strstr(buf, "-h") && strlen(buf) == 2)
            sscanf(argv[i + 1], "%63s", d1.hlpnam);
    }
//    d1.azelport = 0x3f8;        // com1 default for old SRT 
    d1.ver = 4;  // SRT software version
    d1.secs = readclock();
    d1.run = 1;
    d1.record = 0;
    d1.entry1 = d1.entry2 = d1.entry3 = d1.entry5 = d1.entry6 = d1.entry8 = d1.helpwindow = d1.vwindow = 0;
    d1.plot = 0;
    d1.start_time = 0.0;
    d1.start_sec = 0.0;
    d1.speed_up = 0;
    d1.ppos = 0;
    d1.printout = 1;
    d1.debug = 0;
    d1.freq = 1420.4;           // default
    d1.bw = 0;                  // set to 2.4 for TV dongle 10 MHz for ADC card in init
    d1.fbw = 0;                 // set in init or srt.cat
    d1.nblk = 5;                // number of blocks in vspectra
    d1.record_int_sec = 0;
    d1.freqcorr = 0;            // frequency correction for L.O. may be needed for TV dongle
    d1.freqchng = 0;
    d1.clearint = 0;
    d1.record_clearint = 0;
    d1.noclearint = 0;
    d1.nfreq = NSPEC;
    d1.plotsec = 1;
    d1.displ = 1;
    d1.noisecal = 0;
//    used for old SRT mount and controller
//    d1.ptoler = 1;
//    d1.countperstep = 10000;    // default large number for no stepping 
//    d1.elcounts_per_deg = (52.0 * 27.0 / 120.0); // default for H-180
//    d1.azcounts_per_deg = 8.0 * 32.0 * 60.0 / (360.0 * 9.0); // default for CASSIMOUNT
//    d1.rod = 1;                 // default to rod as on CASSIMOUNT
//    d1.rod1 = 14.25;            // rigid arm length
//    d1.rod2 = 16.5;             // distance from pushrod upper joint to el axis
//    d1.rod3 = 2.0;              // pushrod collar offset
//    d1.rod4 = 110.0;            // angle at horizon
//    d1.rod5 = 30.0;             // pushrod counts per inch
    d1.azelsim = d1.radiosim = d1.fftsim = 0;
    d1.mainten = 0;
    d1.stowatlim = 1;
    d1.rms = -1;                // display max not rms 
    d1.calcons = 1.0;
    d1.caldone = 0;
    d1.nrfi = 0;
    d1.rfisigma = 6;            // level for RFI reporting to screen
    d1.tload = 300.0;
    d1.tspill = 20.0;
    d1.beamw = 5.0;
    d1.comerr = 0;
    d1.limiterr = 0;
    d1.restfreq = 1420.406;     /* H-line restfreq */
    d1.delay = 0;
    d1.azoff = 0.0;
    d1.eloff = 0.0;
    d1.drift = 0;
    d1.tstart = 0;
    d1.tsys = 100.0;            // expected on cold sky
    d1.pwroff = 0.0;
    d1.tant = 100.0;
    d1.calpwr = 0;
    d1.yfac = 0;
    d1.calon = 0;
    d1.calmode = 0;
    d1.docal = 0;
    d1.tcal = 290;              // absorber or bushes
    d1.sourn = 0;
    d1.track = 0;
    d1.scan = 0;
    d1.bsw = 0;
    d1.nbsw = 1;
    d1.obsn = 0;
    d1.stopproc = 0;
    d1.fstatus = 0;
    d1.cmdfl = 0;
    d1.south = 1;
    d1.hgt = 0;
    d1.dongle = 0;              // set to zero initially - set to 1 in Init_Device if dongle
    d1.npoly = 25;              // number of terms in polynomial fit of bandpass
    pwrst = pwrprev = 0.0;
    soutrack[0] = 0;
    sprintf(d1.cmdfnam, "cmd.txt");
    sprintf(d1.datadir, "./");  // default to local directory

    if (!catfile())
        return 0;
    d1.foutstatus = 0;
// to get permission su root chown root srtn then chmod u+s srtn then exit 
    if (!d1.azelsim) {
        if (d1.printout)
            printf("initializing antenna controller\n");
        i = rot2(&d1.aznow, &d1.elnow, -1, buf); // initialize
        i = rot2(&d1.aznow, &d1.elnow, 1, buf); // read
        if (i < 0) {
            printf("Couldn't talk to antenna controller\n");
            return 0;
        }
    } else {
        if (d1.stowatlim) {
            d1.azprev = d1.azlim1;
            d1.elprev = d1.ellim1;
        } else {
            d1.azprev = d1.stowaz;
            d1.elprev = d1.stowel;
        }
    }
    setgid(getgid());
    setuid(getuid());
    if (d1.mainten == 0) {
        if (d1.stowatlim) {
            d1.azcmd = d1.azlim1;
            d1.elcmd = d1.ellim1;
        } else {
            d1.azcmd = d1.stowaz;
            d1.elcmd = d1.stowel;
        }
        d1.azcount = 0;
        d1.elcount = 0;
        d1.stow = 1;
    }
    if (d1.azlim1 > d1.azlim2) {
        d1.south = 0;           // dish pointing North for southern hemisphere
        if (d1.azlim2 < 360.0)
            d1.azlim2 += 360.0;
    }

    if (!d1.radiosim)
        Init_Device(0);

    if (d1.displ) {
        gtk_init(&argc, &argv);
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        geometry.min_width = 500;
        geometry.min_height = 300;
        geo_mask = GDK_HINT_MIN_SIZE;
        gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geometry, geo_mask);
        //Table size determines number of buttons across the top
        table = gtk_table_new(30, NUMBUTTONS, TRUE);

        drawing_area = gtk_drawing_area_new();
        gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
        color.red = 0xffff;
        color.blue = 0xffff;
        color.green = 0xffff;
        gtk_widget_show(drawing_area);
        gtk_table_attach_defaults(GTK_TABLE(table), drawing_area, 0, NUMBUTTONS, 3, 30);

        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit), NULL);

        gtk_container_add(GTK_CONTAINER(window), table);

        g_signal_connect(G_OBJECT(drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL);
        g_signal_connect(G_OBJECT(drawing_area), "configure_event", (GtkSignalFunc) configure_event, NULL);

        g_signal_connect(G_OBJECT(drawing_area), "button_press_event",
                         (GtkSignalFunc) button_press_event, NULL);

        gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK
                              | GDK_LEAVE_NOTIFY_MASK
                              | GDK_BUTTON_PRESS_MASK
                              | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);


        button_clear = gtk_button_new_with_label("clear");
        button_stow = gtk_button_new_with_label("stow");
        button_azel = gtk_button_new_with_label("azel");
        button_npoint = gtk_button_new_with_label("npoint");
        button_bsw = gtk_button_new_with_label("beamsw");
        button_freq = gtk_button_new_with_label("freq");
        button_offset = gtk_button_new_with_label("offset");
        button_record = gtk_button_new_with_label("record");
        button_cmdfl = gtk_button_new_with_label("cmdfl");
        button_cal = gtk_button_new_with_label("cal");
        button_help = gtk_button_new_with_label("help");
        button_exit = gtk_button_new_with_label("exit");

        g_signal_connect(G_OBJECT(button_clear), "clicked", G_CALLBACK(button_clear_clicked), NULL);
        g_signal_connect(G_OBJECT(button_stow), "clicked", G_CALLBACK(button_stow_clicked), NULL);
        g_signal_connect(G_OBJECT(button_azel), "clicked", G_CALLBACK(button_azel_clicked), NULL);
        g_signal_connect(G_OBJECT(button_npoint), "clicked", G_CALLBACK(button_npoint_clicked), NULL);
        g_signal_connect(G_OBJECT(button_bsw), "clicked", G_CALLBACK(button_bsw_clicked), NULL);
        g_signal_connect(G_OBJECT(button_freq), "clicked", G_CALLBACK(button_freq_clicked), NULL);
        g_signal_connect(G_OBJECT(button_offset), "clicked", G_CALLBACK(button_offset_clicked), NULL);
        g_signal_connect(G_OBJECT(button_record), "clicked", G_CALLBACK(button_record_clicked), NULL);
        g_signal_connect(G_OBJECT(button_cmdfl), "clicked", G_CALLBACK(button_cmdfl_clicked), NULL);
        g_signal_connect(G_OBJECT(button_cal), "clicked", G_CALLBACK(button_cal_clicked), NULL);
        g_signal_connect(G_OBJECT(button_help), "clicked", G_CALLBACK(button_help_clicked), NULL);
        g_signal_connect(G_OBJECT(button_exit), "clicked", G_CALLBACK(button_exit_clicked), NULL);

        // test setting up tooltips instead of the "enter"/"leave" used below
        tooltips = gtk_tooltips_new();
        gtk_tooltips_set_tip(tooltips, button_clear,
                             "click to clear integration and reset time plot to 1/4-scale", NULL);
        gtk_tooltips_set_tip(tooltips, button_stow, "click to stow antenna", NULL);
        gtk_tooltips_set_tip(tooltips, button_azel, "click to enter az el coordinates", NULL);
        gtk_tooltips_set_tip(tooltips, button_npoint, "click to start npoint scan", NULL);
        gtk_tooltips_set_tip(tooltips, button_bsw, "click to start beam switch", NULL);
        gtk_tooltips_set_tip(tooltips, button_freq, "click to enter new frequency in MHz [bandwidth] [nfreq]",
                             NULL);
        gtk_tooltips_set_tip(tooltips, button_offset, "click to enter offsets", NULL);
        if (!d1.cmdfl)
            gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to start cmd file", NULL);
        else
            gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to stop cmd file", NULL);

        gtk_tooltips_set_tip(tooltips, button_cal, "click to start calibration", NULL);
        gtk_tooltips_set_tip(tooltips, button_help, "click to open help window", NULL);
        record_tooltip();


        gtk_table_attach(GTK_TABLE(table), button_clear, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_stow, 1, 2, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_azel, 2, 3, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_npoint, 3, 4, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_bsw, 4, 5, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_freq, 5, 6, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_offset, 6, 7, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_record, 7, 8, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_cmdfl, 8, 9, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_cal, 9, 10, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_help, 10, 11, 0, 2, GTK_FILL, GTK_FILL, 0, 0);
        gtk_table_attach(GTK_TABLE(table), button_exit, 11, 12, 0, 2, GTK_FILL, GTK_FILL, 0, 0);



        gtk_widget_show(button_clear);
        gtk_widget_show(button_stow);
        gtk_widget_show(button_azel);
        gtk_widget_show(button_npoint);
        gtk_widget_show(button_bsw);
        gtk_widget_show(button_freq);
        gtk_widget_show(button_offset);
        gtk_widget_show(button_record);
        gtk_widget_show(button_cmdfl);
        gtk_widget_show(button_cal);
        gtk_widget_show(button_help);
        gtk_widget_show(button_exit);


        gtk_widget_show(table);
        gtk_widget_show(window);
        clearpaint();
    }
    ii = 0;
    if (d1.printout) {
        toyrday(d1.secs, &yr, &da, &hr, &mn, &sc);
        printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource);
    }
    zerospectra(0);
    for (i = 0; i < d1.nfreq; i++)
        bspec[i] = 1;
    secstart = d1.nsecstart = -1;
    d1.secs = readclock();
    while (d1.run) {
        zerospectra(1);
        if (d1.clearint) {
            if (d1.displ)
                cleararea();
            zerospectra(0);
            d1.clearint = 0;
        }
        if (d1.freqchng) {
            if (d1.dongle)
                Init_Device(1);
            if (d1.printout) {
                toyrday(d1.secs, &yr, &da, &hr, &mn, &sc);
                printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource);
            }
            if (!d1.radiosim) {
                sleep(1);
            }
            zerospectra(0);
            d1.freqchng = 0;
        }
        if (d1.docal) {
            if (d1.docal == 1) {
                sprintf(d1.recnote, "* calibration started\n");
                outfile(d1.recnote);
            }
            if (d1.bsw) {
                d1.bsw = 0;
                d1.azoff = 0.0;
            }
            if (d1.scan) {
                d1.scan = 0;
                d1.eloff = d1.azoff = 0.0;
            }
            if (d1.slew)
                d1.slew = 0;
            if (d1.docal == 1)
                cal(0);
            d1.docal = 2;
            cal(1);
            if (d1.integ >= NCAL) {
                cal(2);
                d1.docal = 0;
            }
        }

        if (d1.displ)
            cleararea();
        azel(d1.azcmd, d1.elcmd); // allow time after cal 
        if (d1.comerr == -1)
            return 0;
        if (!d1.slew) {
            pwr = 0.0;
        }
        if (!d1.slew)
            vspectra();
        d1.secs = readclock();
        aver();
        d1.integ2++;
        if (d1.record_int_sec && d1.integ2 >= d1.record_int_sec) {
            outfile(" ");
            if (d1.record_clearint && d1.track && !d1.bsw && !d1.scan)
                d1.clearint = 1;
            d1.integ2 = 0;
        }
        if (d1.displ) {
            if (!d1.plot)
                Repaint();
            while (gtk_events_pending() || d1.stopproc == 1) {
                gtk_main_iteration();
                d1.plot = 0;
            }
        }
        if (!d1.displ && d1.domap)
            scanplot();
    }
    return 0;
}