Ejemplo n.º 1
0
/*--------------------------------------------------------------------------------*/
AudioObjectParameters& AudioObjectParameters::Modify(const Modifier& modifier, const ADMAudioObject *object)
{
  if (modifier.rotation.IsSet())
  {
    SetPosition(GetPosition() * modifier.rotation.Get());
    if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.rotation.Get());
    if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.rotation.Get());

    Position size(GetWidth(), GetDepth(), GetHeight());
    size *= modifier.rotation.Get();
    SetWidth(static_cast<float>(size.pos.x));
    SetDepth(static_cast<float>(size.pos.y));
    SetHeight(static_cast<float>(size.pos.z));
  }
  if (modifier.position.IsSet()) SetPosition(GetPosition() + modifier.position.Get());
  if (modifier.scale.IsSet())
  {
    SetPosition(GetPosition() * modifier.scale.Get());
    if (IsMinPositionSet()) SetMinPosition(GetMinPosition() * modifier.scale.Get());
    if (IsMaxPositionSet()) SetMaxPosition(GetMaxPosition() * modifier.scale.Get());

    Position size(GetWidth(), GetDepth(), GetHeight());
    size *= modifier.scale.Get();
    SetWidth(static_cast<float>(size.pos.x));
    SetDepth(static_cast<float>(size.pos.y));
    SetHeight(static_cast<float>(size.pos.z));
  }
  if (modifier.gain.IsSet()) SetGain(GetGain() * modifier.gain.Get());

  // apply specific modifications (from derived classes)
  modifier.Modify(*this, object);

  return *this;
}
Ejemplo n.º 2
0
//--------------------------------------------------------------
//
// Implementation of sample code
//
//--------------------------------------------------------------
OSErr RVSetVideoRequest (VideoRequestRecPtr requestRecPtr)
{
	GDHandle		aMonitor;
	Boolean			displayMgrPresent;
	unsigned long	displayMgrVersion;
	OSErr			err;
	Boolean			isColor;
	long			value = 0;

	Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion);
	Gestalt(gestaltDisplayMgrAttr,&value);
	displayMgrPresent=value&(1<<gestaltDisplayMgrPresent);
	if (displayMgrPresent)
	{
		if (requestRecPtr->displayMode && requestRecPtr->depthMode)
		{
			if (requestRecPtr->availBitDepth == 1)	// Based on avail bit depth, 
				isColor = KMonoDev;					// set the device to a mono device, or
			else isColor = kColorDev;				// set the device to a color device
			SetDeviceAttribute(requestRecPtr->screenDevice,gdDevType,isColor);		
			
			// see how many monitors we have, aMonitor will be nil if we have only one.
			aMonitor = DMGetFirstScreenDevice (dmOnlyActiveDisplays);			// get the first guy
			aMonitor = DMGetNextScreenDevice ( aMonitor, dmOnlyActiveDisplays );	// get the next guy
			
			if (nil == aMonitor || displayMgrVersion >= 0x00020000)
			{
				// only call DMSetDisplayMode if we have one monitor or DM2.0 is installed
				// since DM1.0 does not automatically gravitate monitors and our gravitate code
				// is not implemented.
				err = DMSetDisplayMode(	requestRecPtr->screenDevice,	// GDevice
						requestRecPtr->displayMode,						// DM1.0 uses this
						&requestRecPtr->depthMode,						// DM1.0 uses this
						(unsigned long) &(requestRecPtr->switchInfo),	// DM2.0 uses this rather than displayMode/depthMode combo
						nil);
				if (noErr == err)
				{
					// Do the monitor gravitate here if we are using a version less than DM2.0
					if (displayMgrVersion < 0x00020000)
						GravitateMonitors ();
				}
				else if (kDMDriverNotDisplayMgrAwareErr == err)
				{
					// DM not supported by driver, so all we can do is set the bit depth
					err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor);
				}
			}
			else
			{
				// we have more than one monitor and DM1.0 is installed, so all we can do is set the bit depth
				err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor);
			}
			
			return (err);	// we did try to set the request
		}
	}
	return (-1);	// return a generic error
}
Ejemplo n.º 3
0
KVTelBlocking::KVTelBlocking(UInt_t n): KVTelescope()
{
   //Create blocking telescope number 'n'.
   //By default the BIC pressure is 30 (Torr)

   if (n) {                     //default ctor must not add detectors, or Clone() will give a telescope with 2 more detectors!!
      SetNumber(n);
      Add(new KVBIC(30.));
      Add(new KVSiB(500.));
      SetDepth(1, 0.);
      SetDepth(2, 119.);        //SIB is 119mm behind BIC
   }
   SetName(Form("TEL_BLOCK_%d", (Int_t)n));
}
Ejemplo n.º 4
0
RayTracer::RayTracer(int maxD){
	SetDepth(maxD);
	avoidShadows = false;
	avoidAllLightButKaKe = false;
	avoidRefractions = false;
	avoidReflections = false;
}
Ejemplo n.º 5
0
/********************************************************************************************

>	BOOL MaskedFilterExportOptions::CopyFromMasked(MaskedFilterExportOptions *pOther) 

	Author:		Stefan_Stoykov (Xara Group Ltd) <*****@*****.**>
	Created:	15/07/97
	Inputs:		pOther - the other MaskedFilterExportOptions object to copy the data from
	Purpose:	Sets the contents of this object from the passed object. This differs form the
				more general function in that it  doesn't require the two objects to be of the
				same class. Used to convert from/to PNG options and MakeBitmapExportOptions.
	See Also:	BitmapExportOptions::MakeCopy()

********************************************************************************************/
BOOL MaskedFilterExportOptions::CopyFromMasked(MaskedFilterExportOptions *pOther) 
{
	if (pOther == NULL)
		return FALSE;
	
	//BitmapExportOptions members
	m_SelectionType		= pOther->m_SelectionType;
	m_OutputSize		= pOther->m_OutputSize;
	m_PixelOutputSize	= pOther->m_PixelOutputSize;
	m_pBmpDlgParam		= pOther->m_pBmpDlgParam;		
	m_NumColsInPalette	= pOther->m_NumColsInPalette;
	m_UseSystemColours	= pOther->m_UseSystemColours;
	m_bSeparateLayerFiles = pOther->m_bSeparateLayerFiles;
	m_bTempFileFlag		= pOther->m_bTempFileFlag;

	SetDPI(pOther->GetDPI());
	SetDepth(pOther->GetDepth());
	SetTransparencyIndex(pOther->GetTransparencyIndex());
	if (pOther->IsValid())
		MarkValid();
	else
		MarkInvalid();

	//MaskedFilterExportOptions
	m_Dither		= pOther->m_Dither;
	m_bInterlaced	= pOther->m_bInterlaced;

	return TRUE;
}
Ejemplo n.º 6
0
void AudioObjectParameters::MultiplyByScene(float width, float height, float depth)
{
  Position pos = GetPosition().Cart();
  pos.pos.x *= width;
  pos.pos.y *= depth;
  pos.pos.z *= height;
  SetPosition(GetPosition().polar ? pos.Polar() : pos);

  if (IsMinPositionSet())
  {
    Position pos = GetMinPosition().Cart();
    pos.pos.x *= width;
    pos.pos.y *= depth;
    pos.pos.z *= height;
    SetMinPosition(GetMinPosition().polar ? pos.Polar() : pos);
  }

  if (IsMaxPositionSet())
  {
    Position pos = GetMaxPosition().Cart();
    pos.pos.x *= width;
    pos.pos.y *= depth;
    pos.pos.z *= height;
    SetMaxPosition(GetMaxPosition().polar ? pos.Polar() : pos);
  }

  SetWidth(GetWidth() * width);
  SetHeight(GetHeight() * height);
  SetDepth(GetDepth() * depth);

  if (excludedZones) excludedZones->MultiplyByScene(width, height, depth);
}
Ejemplo n.º 7
0
/*--------------------------------------------------------------------------------*/
void AudioObjectParameters::DivideByScene(float width, float height, float depth)
{
  Position pos = GetPosition().Cart();
  pos.pos.x /= width;
  pos.pos.y /= depth;
  pos.pos.z /= height;
  SetPosition(GetPosition().polar ? pos.Polar() : pos);

  if (IsMinPositionSet())
  {
    Position pos = GetMinPosition().Cart();
    pos.pos.x /= width;
    pos.pos.y /= depth;
    pos.pos.z /= height;
    SetMinPosition(GetMinPosition().polar ? pos.Polar() : pos);
  }

  if (IsMaxPositionSet())
  {
    Position pos = GetMaxPosition().Cart();
    pos.pos.x /= width;
    pos.pos.y /= depth;
    pos.pos.z /= height;
    SetMaxPosition(GetMaxPosition().polar ? pos.Polar() : pos);
  }

  SetWidth(GetWidth() / width);
  SetHeight(GetHeight() / height);
  SetDepth(GetDepth() / depth);
  
  if (excludedZones) excludedZones->DivideByScene(width, height, depth);
}
CParticleSystemManager::CParticleSystemManager(float depth)
{
	CLogManager::Instance()->LogMessage( "Initializing Particle System manager." );
	m_eType = PARTICLESYSTEM;

	SetDepth( depth );
}
Ejemplo n.º 9
0
void CAsteroid::Respawn()
{

	int stochast = rand()%100;
	int sum = 0;
	bool isRepossed = false;
	CODEManager* ode = CODEManager::Instance();

	for(unsigned int i = 0; i < ode->m_pUniverse->m_vRespawnAreas.size(); i++)
	{
		if(isRepossed) continue;
		sum += ode->m_pUniverse->m_vRespawnAreas[i].chance;
		if(stochast < sum) { ReposAtArea(ode->m_pUniverse->m_vRespawnAreas[i]); isRepossed = true; }
	}

	if(!isRepossed) ReposAtOrbit();

	Vector n;
	m_oPhysicsData.m_pOwner->SetLinVelocity(n);
	m_oPhysicsData.m_pOwner->SetAngVelocity(n);
	SetForce(n);

	m_fThrowTime = 0;
	m_fTemperatureTime = 0.0f;
	m_iMilliSecsInOrbit = 0;
	m_iWallBounces = 0;
	m_pHoldingPlayer = NULL;
	m_pThrowingPlayer = NULL;
	SetDepth(-1.0);
	SetAlpha(1.0);

}
Ejemplo n.º 10
0
OGSprite* SpriteFactory::CreateBend(const QString& a_type,
                     const QPointF& a_p1,
                     const QPointF& a_p2,
                     const QPointF& a_p3,
                     float a_depth)
{
    auto v1 = a_p2 - a_p1;
    auto v2 = a_p3 - a_p2;

    QString id = "IMAGE_GLOBAL_PIPE_BEND_";

    if (v1.y() > 0 || v2.y() < 0)
        id += (v2.x() < 0 || v1.x() > 0 ? "TR_" + a_type : "TL_" + a_type);
    else
        id += (v2.x() < 0 || v1.x() > 0 ? "BR_" + a_type : "BL_" + a_type);

    auto src = CreateImageSource(id);

    if (!src)
        return nullptr;

    auto spr = std::unique_ptr<OGSprite>(new OGSprite(src));
    spr->SetPosition(a_p2.x(), -a_p2.y());
    spr->SetDepth(a_depth);
    spr->CenterOrigin();

    return spr.release();
}
Ejemplo n.º 11
0
OGSprite* SpriteFactory::CreateCap(WOGPipe* a_pipe,
                                   const QString& a_id,
                                   bool a_visible)
{
    auto src = CreateImageSource(a_id);

    if (!src || a_pipe->vertex->size() < 2)
        return nullptr;

    QPointF p1 = a_pipe->vertex->at(0);
    QPointF p2 = a_pipe->vertex->at(1);
    auto v = p2 - p1;
    float angle = (v.x() == 0 ? (v.y() > 0 ? 0 : 180) : (v.x() > 0 ? 90 : -90));

    float x = p1.x();
    float y = -p1.y();

    auto spr = std::unique_ptr<OGSprite>(new OGSprite(x, y, src));
    spr->CenterOrigin();
    spr->SetAngle(angle);
    spr->SetVisible(a_visible);
    spr->SetDepth(a_pipe->depth);

    return spr.release();
}
Ejemplo n.º 12
0
obj_Saw_Bar::obj_Saw_Bar()
{
	image = ImageManager::GetInstance().GetImage(ImageManager::IMG_SAW_BAR);
	SetDepth(-12);
	
	SetCollidable(false);
	direction = 0;
}
Ejemplo n.º 13
0
CMapiFolder::CMapiFolder( const PRUnichar *pDisplayName, ULONG cbEid, LPENTRYID lpEid, int depth, LONG oType)
{
  m_cbEid = 0;
  m_lpEid = NULL;
  SetDisplayName( pDisplayName);
  SetEntryID( cbEid, lpEid);
  SetDepth( depth);
  SetObjectType( oType);
  SetDoImport( TRUE);
}
Ejemplo n.º 14
0
cCloud::cCloud(cResources* a_pResources)
   : cObject(a_pResources),
     m_Speed(5)
{
   SetType("Cloud");
   SetSolid(true);
   LoadAnimations("Media/Title.ani");
   PlayAnimationLoop("Cloud1");
   SetDepth(1, kNormal);
   SetCollidable(false);
}
Ejemplo n.º 15
0
void CRTreeCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange
	m_pic.CreateEmpty();
	m_lBoxWidth=100;
	m_lBoxHeight=50;
	m_lGapWidth=50;
	m_lDepth=-1;
	m_list=NULL;
	SetDepth(4);
}
Ejemplo n.º 16
0
Wall_Fake::Wall_Fake(void)
{
	SetID(WALL_FAKE);
	boundUp=0;
	boundDown=0;
	boundLeft=0;
	boundRight=0;
	SetDepth(0);
	SetCollidable(false);
	image = ImageManager::GetInstance().GetImage(ImageManager::IMG_WALL);
}
Ejemplo n.º 17
0
CMapiFolder::CMapiFolder( const CMapiFolder *pCopyFrom)
{
  m_lpEid = NULL;
  m_cbEid = 0;
  SetDoImport( pCopyFrom->GetDoImport());
  SetDisplayName(pCopyFrom->m_displayName.get());
  SetObjectType( pCopyFrom->GetObjectType());
  SetEntryID( pCopyFrom->GetCBEntryID(), pCopyFrom->GetEntryID());
  SetDepth( pCopyFrom->GetDepth());
  SetFilePath(pCopyFrom->m_mailFilePath.get());
}
Ejemplo n.º 18
0
bool ETHRenderEntity::DrawAmbientPass(const float maxHeight, const float minHeight,
									  const bool enableLightmaps, const ETHSceneProperties& sceneProps,
									  const float parallaxIntensity)
{
	if (!m_pSprite || IsHidden())
		return false;

	Vector4 v4FinalAmbient = Vector4(sceneProps.ambient, 1.0f);
	v4FinalAmbient.x = Min(1.0f, v4FinalAmbient.x + m_properties.emissiveColor.x);
	v4FinalAmbient.y = Min(1.0f, v4FinalAmbient.y + m_properties.emissiveColor.y);
	v4FinalAmbient.z = Min(1.0f, v4FinalAmbient.z + m_properties.emissiveColor.z);
	v4FinalAmbient = v4FinalAmbient * m_v4Color;

	SetDepth(maxHeight, minHeight);

	const VideoPtr& video = m_provider->GetVideo();

	const bool applyLightmap = (m_pLightmap && enableLightmaps && IsStatic());
	if (applyLightmap)
	{
		m_pLightmap->SetAsTexture(1);
	}

	// sets the alpha mode according to the entity's property
	const Video::ALPHA_MODE& am = GetBlendMode();

	if (am != video->GetAlphaMode())
		video->SetAlphaMode(am);

	ValidateSpriteCut(m_pSprite);
	m_pSprite->SetRect(m_spriteFrame);
	SetOrigin();

	const bool shouldUseFourTriangles = ShouldUseFourTriangles(parallaxIntensity);
	const float angle = (m_properties.type == ETHEntityProperties::ET_VERTICAL) ? 0.0f : GetAngle();
	const Vector2 pos = ETHGlobal::ToScreenPos(GetPosition(), sceneProps.zAxisDirection);

	if (shouldUseFourTriangles)
		m_pSprite->SetRectMode(Sprite::RM_FOUR_TRIANGLES);

	m_pSprite->DrawOptimal(pos,	ConvertToDW(v4FinalAmbient), angle, GetCurrentSize());

	if (shouldUseFourTriangles)
		m_pSprite->SetRectMode(Sprite::RM_TWO_TRIANGLES);

	if (applyLightmap)
	{
		video->UnsetTexture(1);
	}
	return true;
}
Ejemplo n.º 19
0
/********************************************************************************************

>	virtual BOOL MakeBitmapExportOptions::RetrieveDefaults()

	Author:		Colin_Barfoot (Xara Group Ltd) <*****@*****.**>
	Created:	29/10/96
	Purpose:	See BitmapExportInfo for interface details: gets GIF specific preferences

********************************************************************************************/
BOOL MakeBitmapExportOptions::RetrieveDefaults()
{
	BOOL ok = FALSE;

	if (MaskedFilterExportOptions::RetrieveDefaults())
	{
		SetDPI(g_Dpi);
		SetDepth(g_Depth);
		SetDither(g_Dither);
		ok = TRUE;
	}

	return ok;
}
Ejemplo n.º 20
0
/*--------------------------------------------------------------------------------*/
AudioObjectParameters& AudioObjectParameters::operator *= (const PositionTransform& transform)
{
  Position centre = GetPosition(), corner = centre;

  SetPosition(centre * transform);
 
  if (centre.polar)
  {
    corner.pos.az += GetWidth();
    corner.pos.el += GetHeight();
    corner.pos.d  += GetDepth();
  }
  else
  {
    corner.pos.x  += GetWidth();
    corner.pos.y  += GetDepth();
    corner.pos.z  += GetHeight();
  }

  corner = (corner * transform) - centre;

  if (centre.polar)
  {
    SetWidth(static_cast<float>(corner.pos.az));
    SetHeight(static_cast<float>(corner.pos.el));
    SetDepth(static_cast<float>(corner.pos.d));
  }
  else
  {
    SetWidth(static_cast<float>(corner.pos.x));
    SetDepth(static_cast<float>(corner.pos.y));
    SetHeight(static_cast<float>(corner.pos.z));
  }
  
  return *this;
}
void
InternalResampleAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("InternalResampleAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("useTargetVal")) != 0)
        SetUseTargetVal(node->AsBool());
    if((node = searchNode->GetNode("targetVal")) != 0)
        SetTargetVal(node->AsInt());
    if((node = searchNode->GetNode("width")) != 0)
        SetWidth(node->AsInt());
    if((node = searchNode->GetNode("height")) != 0)
        SetHeight(node->AsInt());
    if((node = searchNode->GetNode("depth")) != 0)
        SetDepth(node->AsInt());
    if((node = searchNode->GetNode("prefersPowersOfTwo")) != 0)
        SetPrefersPowersOfTwo(node->AsBool());
    if((node = searchNode->GetNode("defaultVal")) != 0)
        SetDefaultVal(node->AsFloat());
    if((node = searchNode->GetNode("useBounds")) != 0)
        SetUseBounds(node->AsBool());
    if((node = searchNode->GetNode("minX")) != 0)
        SetMinX(node->AsDouble());
    if((node = searchNode->GetNode("minY")) != 0)
        SetMinY(node->AsDouble());
    if((node = searchNode->GetNode("minZ")) != 0)
        SetMinZ(node->AsDouble());
    if((node = searchNode->GetNode("maxX")) != 0)
        SetMaxX(node->AsDouble());
    if((node = searchNode->GetNode("maxY")) != 0)
        SetMaxY(node->AsDouble());
    if((node = searchNode->GetNode("maxZ")) != 0)
        SetMaxZ(node->AsDouble());
    if((node = searchNode->GetNode("useArbitrator")) != 0)
        SetUseArbitrator(node->AsBool());
    if((node = searchNode->GetNode("arbitratorLessThan")) != 0)
        SetArbitratorLessThan(node->AsBool());
    if((node = searchNode->GetNode("arbitratorVarName")) != 0)
        SetArbitratorVarName(node->AsString());
    if((node = searchNode->GetNode("distributedResample")) != 0)
        SetDistributedResample(node->AsBool());
}
Ejemplo n.º 22
0
// conversion to mono bitmap:
bool wxBitmap::CreateFromImageAsBitmap(const wxImage& img)
{
    // convert alpha channel to mask, if it is present:
    wxImage image(img);
    image.ConvertAlphaToMask();
    
    int width = image.GetWidth();
    int height = image.GetHeight();

    SetHeight( height );
    SetWidth( width );

    SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );

    SetDepth( 1 );

    GdkVisual *visual = wxTheApp->GetGdkVisual();

    // Create picture image

    unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

    GdkImage *data_image =
        gdk_image_new_bitmap( visual, data_data, width, height );

    // Create mask image

    GdkImage *mask_image = (GdkImage*) NULL;

    if (image.HasMask())
    {
        unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height );

        mask_image =  gdk_image_new_bitmap( visual, mask_data, width, height );

        wxMask *mask = new wxMask();
        mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );

        SetMask( mask );
    }
Ejemplo n.º 23
0
Vehicle::Vehicle(type vehicleType, const TexturesModel& textures, float depth)
: Vehicle(vehicleType, textures) {
    SetDepth(depth);
}
Ejemplo n.º 24
0
Archivo: motet.c Proyecto: cckayne/MOTE
int main(int argc, char *argv[])
{
	// stir depth and nonce length
	ub4 dep, sdep = MAXM, lnce = NLEN;
	ub4 rounds = 7;
	#ifdef MOTE-REPO
	enum CSPRNG rng = MOTE8;
	enum CSPRNG hasher = BB512;
	#else
	#ifdef BB-REPO
	enum CSPRNG rng = BB128;
	enum CSPRNG hasher = MOTE32;	
	#else
	enum CSPRNG rng = MOTE32;
	enum CSPRNG hasher = BB512;
	#endif
	#endif
	enum ciphermode cmode   = cmNone;
	enum ciphertype ctype	= ctNone;
	enum outputform oform	= ofASC;
	// input: message & key-phrase
	char msg[MAXM] = ""; 
	char key[MAXM] = "";
	// ciphertext & plaintext
	char ctx[MAXM], ptx[MAXM];
	// derived & stretched key
	char kdf[MAXK] = "";
	// IV/nonce
	char nce[MAXK] = "";
	// check the command line
	if (argc >= 5) {
		if ((argc>=2) && strlen(argv[1])<MAXM) strcpy(msg,argv[1]);
		if ((argc>=3) && strlen(argv[1])<MAXK) strcpy(key,argv[2]);
		if (argc>=4)
			if ((strcmp(argv[3],"d")==0) || (strcmp(argv[3],"D")==0))
				 cmode = cmDecipher; else
			if ((strcmp(argv[3],"e")==0) || (strcmp(argv[3],"E")==0)) 
				 cmode = cmEncipher; else cmode = cmNone;
		if (argc>=5)
			#ifdef NEVER
			if ((strcmp(argv[4],"v")==0) || (strcmp(argv[4],"V")==0))
				 ctype = ctVernam; else
			#endif
			if ((strcmp(argv[4],"c")==0) || (strcmp(argv[4],"C")==0))
				 ctype = ctCaesar; else
			if ((strcmp(argv[4],"m")==0) || (strcmp(argv[4],"M")==0)) 
				ctype = ctCaesarM; else ctype = ctNone;
		if (argc>=6) 
			if ((strcmp(argv[5],"a")==0) || (strcmp(argv[5],"A")==0))
				oform = ofASC; else oform = ofHEX;
		if (argc>=7) rng = (enum CSPRNG)(atoi(argv[6]) % 7);
	}
	// sanity checks
	if (TRUE) {
		if ((strlen(msg)<MINM) || (strlen(key)<MINK)) { info(); exit(0); }
		if ((cmode==cmNone) || (ctype==ctNone))       { info(); exit(0); }
		// only hex output available for Vernam
		if (ctype==ctVernam) oform=ofHEX;
		// output mode MOD 26? (not possible with Vernam)
		if ((oform==ofASC) && (ctype!=ctVernam)) { MOD=26; START='A'; }
		// no nonce scrambling or mixing available with hex output
		if (oform==ofHEX) SCRAMBLER=NONCE=MIX=FALSE;
	}
	// B E G I N  P R E P A R A T I O N
	// preliminary seeding
	rSeedAll(key,rounds);
	
	if (SCRAMBLER) {
		sdep = SetDepth(rng,strlen(key));
		#ifdef LOG
		char tmp[12]=""; sprintf(tmp,"%d",sdep);
		log_add("RNG",rName(rng));
		log_add("HSH",rName(hasher));
		log_add("DEP",tmp);
		#endif
	}
	
	if (NONCE) {
		// obtain nonce/IV hash of fixed or random length
		strcpy(nce,rNonce(hasher,FALSE));
		// note nonce length for later
		lnce = strlen(nce);
	}

	// Key-derivation starts:
	if (TRUE) {
		// 1) seed MOTE with a key-derived hash
		strcpy(kdf,rHash(hasher,key,rStateSize(rng)*4));
		rSeed(rng,kdf,rounds);
		// 2) calculate stir-depth
		dep = rDepth(rng,kdf);
		// 3) warm up MOTE with <dep> rounds
		rStir(rng,dep); 
	}
	#ifdef TEST
		#ifdef LOG
		log_add("DKY",leftstr(kdf,LINE));
		#endif
	#endif
	// Key-derivation ends.
	
	if (SCRAMBLER) {
		// prepare scrambler's random pool
		RandPool_Fill(rng);
	}
	// E N D  P R E P A R A T I O N.
	
	// B E G I N  M A I N  C I P H E R  S E Q U E N C E
	// Mode: Encipher
	if (cmode==cmEncipher) {
		// pre-process message if output is mod 26
		if (oform==ofASC) strcpy(msg, PreProcessText(msg));
			#ifdef LOG
			if (oform==ofASC) log_add("MSG",msg);
			#endif
		// Encrypt: Vernam XOR
		if (ctype==ctVernam)  strcpy(ctx, Vernam(rng,msg));
		// Encrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ctx, rCaesarStr(rng, cmEncipher, msg, MOD, START));
		// Encrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ctx, rmCaesarStr(rng, cmEncipher, msg, MOD, START));
		// convert to hexadecimal as appropriate
		if (oform==ofHEX) strcpy(ctx,ascii2hex(ctx));
			#ifdef LOG
			log_add(" CT",ctx);
			#endif
		if (MIX) {
			// Mix: Vigenere-cipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("NCE",nce);
				log_add("VCT",ctx);
				#endif
		}
		if (NONCE) {
			// append ciphertext to nonce
			strcat(nce,ctx); strcpy(ctx,nce);
				#ifdef LOG
				log_add("NCT",ctx);
				#endif
		}
		if (SCRAMBLER) {
			// prepare scrambler context & scramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,Scrambled(ctx,sdep));
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
		}
	}
	// Mode: Decipher
	if (cmode==cmDecipher) {
		// Convert hexadecimal ciphertext to ASCII (not in mod 26)
		if (oform==ofHEX) strcpy(ctx, hex2ascii(msg)); else strcpy(ctx, msg);
		if (SCRAMBLER) {
				#ifdef LOG
				log_add("SCT",ctx);
				#endif
			// prepare scrambler context & unscramble ciphertext
			InitRandPairs(rng,sdep,strlen(ctx));
			strcpy(ctx,unScrambled(ctx,sdep));
				#ifdef LOG
				log_add("UST",ctx);
				#endif
		}
		if (NONCE) {
			// detach ciphertext from nonce
			strcpy(nce,leftstr(ctx,lnce));
			strcpy(ctx,rightstr(ctx,strlen(msg)-lnce));
				#ifdef LOG
				log_add("VCT",ctx);
				log_add("NCE",nce);
				#endif
		}
		if (MIX) {
			// Un-mix: Vigenere-decipher the ciphertext on the nonce
			strcpy(ctx,Vig(rng,cmode,ctx,nce,MOD,START,FALSE));
				#ifdef LOG
				log_add("UVC",ctx);
				#endif
		}
		// Decrypt: Vernam XOR
		if (ctype==ctVernam) strcpy(ptx, Vernam(rng,ctx));
		// Decrypt: Caesar MOD
		if (ctype==ctCaesar)  strcpy(ptx, rCaesarStr(rng, cmDecipher, ctx, MOD, START));
		// Decrypt: Caesar MIX
		if (ctype==ctCaesarM) strcpy(ptx, rmCaesarStr(rng, cmDecipher,ctx, MOD, START));
		// post-process plaintext if output is mod 26
		if (oform==ofASC) strcpy(ptx, PostProcessText(ptx));
	}  
	// E N D  M A I N  C I P H E R  S E Q U E N C E .
	#ifdef LOG
	log_show ();
	log_clear();
	#endif
	// P R O G R A M  O U T P U T
	if ((strcmp(ptx,"") != 0) || (strcmp(ctx,"") != 0)) {
		// Mode: Encipher
		if (cmode==cmEncipher) puts(ctx);
		// Mode: Decipher
		if (cmode==cmDecipher) puts(ptx);
		
		// belt'n'braces memory wipe
		if (TRUE) {
			rResetAll(); rResetAll();
			memset(msg,0,sizeof(msg));memset(msg,0xFF,sizeof(msg));memset(msg,0,sizeof(msg));
			memset(key,0,sizeof(key));memset(key,0xFF,sizeof(key));memset(key,0,sizeof(key));
			memset(kdf,0,sizeof(kdf));memset(kdf,0xFF,sizeof(kdf));memset(kdf,0,sizeof(kdf));
			memset(ctx,0,sizeof(ctx));memset(ctx,0xFF,sizeof(ctx));memset(ctx,0,sizeof(ctx));
			memset(ptx,0,sizeof(ptx));memset(ptx,0xFF,sizeof(ptx));memset(ptx,0,sizeof(ctx));
			dep=0;
		}
		
	} else info();

	return 0;
}
Ejemplo n.º 25
0
obj_Test::obj_Test(void)
{
  sprite.Init(Bitmap::IMG_TEST, 0,0);
  mask.Init(0,0,0,32,0,32);
  SetDepth(0);
}
Ejemplo n.º 26
0
void Widget::SetSize (float width, float height, float depth) {
    SetWidth (width); SetHeight (height); SetDepth (depth);
}