Пример #1
0
// static
void Serdes::DeserializeInfo(std::vector<int8_t> const & bytes, Info & result)
{
  MemReader reader(bytes.data(), bytes.size());
  NonOwningReaderSource source(reader);

  auto version = static_cast<int8_t>(Version::Unknown);
  ReadPrimitiveFromSource(source, version);
  if (version == static_cast<int8_t>(Version::V0))
  {
    try
    {
      // TODO: Use temporary object InfoV0 and implement method to convert it to Info,
      // TODO: when InfoV1 will be implemented.
      coding::DeserializerJson des(source);
      des(result);
    }
    catch (base::Json::Exception & ex)
    {
      LOG(LERROR, ("Cannot deserialize eye file. Exception:", ex.Msg(), "Version:", version,
                   "File content:", std::string(bytes.begin(), bytes.end())));
    }
    return;
  }

  MYTHROW(UnknownVersion, ("Unknown data version:", static_cast<int>(version)));
}
Пример #2
0
static void
destests(void)
{
	des("", "");
	des("The quick brown fox jumps over the lazy dog",
	    "51551eab3ebab959553caaed64a3dd9c49f595a630c45cb7317332f8ade70308c4e97aeabbdc7f19");
	des("test des encryption",
	    "7ced9849bed3f7efc1686c89759bafa8");
}
Пример #3
0
void rfb_crypt(CARD8 *dst_buf, CARD8 *src_buf, unsigned char *password)
{
  unsigned char key[8];

  memset(key, 0, 8);
  strncpy((char *)key, (char *)password, 8);
  deskey(key, EN0);
  des(src_buf, dst_buf);
  des(src_buf + 8, dst_buf + 8);
}
Пример #4
0
/**
  * @brief  Build ethernet frame and send out.
  * @param  See below.
  * @retval Not sure.
  */
int enet_send
(
    /* Pointer to wireless network layer's environment structure. */
    wnet_envar_t *p_wnet, 

    /* Pointer to wireless network layer transfer information. */
    wnet_txinfo_t *txinfo, 

    /* Data address. */
    uint8_t *pdata, 

    /* Data length. */
    uint32_t length
)
{
    wnet_enet_header_st_ptr enet_header_ptr = NULL;

    
    /* Reserve room for ENET header. */
    pdata -= WNET_ENET_HEADER_ST_LEN;
    length += WNET_ENET_HEADER_ST_LEN;
    enet_header_ptr = (wnet_enet_header_st_ptr)pdata;

    /* Initialize enet frame header.  */
    memset(enet_header_ptr, 0, WNET_ENET_HEADER_ST_LEN);

    /* Set enet frame destination address and source address. */
    COPY_MAC_ADDR(enet_header_ptr->dest_address, BroadcastAddr);
    
    /* Mac address is bind to the CPU's unique ID */
    enet_header_ptr->src_address[0] = 0x00;
    enet_header_ptr->src_address[1] = 0x11;
    enet_header_ptr->src_address[2] = 0x22;
    enet_header_ptr->src_address[3] = des(2);
    enet_header_ptr->src_address[4] = des(1);
    enet_header_ptr->src_address[5] = des(0);


    switch (txinfo->protocol) 
    {
        case WNET_TRANS_PROT_DSMP:
        { 
            enet_header_ptr->ether_type = cv_ntohs(LLC_ETHERTYPE_DSMPv1);    break;
        }
    
        default:
        {
            OSAL_MODULE_DBGPRT(MODULE_NAME, OSAL_DEBUG_INFO, "Invalid protocol[0x%04x], dropped.\n", txinfo->protocol);
            return -1;
        }
    }
    
    return fp_send(p_wnet, txinfo, pdata, length);
}
Пример #5
0
void des(int y, int x)
{
    if(map[y][x]!=0)    return;
    map[y][x] = 1;
    //prtout(4,4);
    //printf("\n");
    des(y,x+1);
    des(y,x-1);
    des(y+1,x);
    des(y-1,x);
    return;
}
Пример #6
0
static void DREover(const unsigned char *ECMdata, unsigned char *DW)
{
    uchar key[8];
    if(ECMdata[2] >= (43+4) && ECMdata[40] == 0x3A && ECMdata[41] == 0x4B)
    {
        memcpy(key, &DESkeys[(ECMdata[42] & 0x0F) * 8], 8);

        doPC1(key);

        des(key, DES_ECS2_DECRYPT, DW); // even DW post-process
        des(key, DES_ECS2_DECRYPT, DW+8); // odd DW post-process
    };
};
Пример #7
0
/*
 *   marscha@2006
 *   Encrypt bytes[length] in memory using key.
 *   Key has to be 8 bytes, length a multiple of 8 bytes.
*/
void
vncEncryptBytes2(unsigned char *where, const int length, unsigned char *key) {
	int i, j;
	deskey(key, EN0);
	for (i = 0; i< 8; i++)
		where[i] ^= key[i];
	des(where, where);
	for (i = 8; i < length; i += 8) {
		for (j = 0; j < 8; j++)
			where[i + j] ^= where[i + j - 8];
		des(where + i, where + i);
	}
}
Пример #8
0
// static
void Serdes::DeserializeMapObjects(std::vector<int8_t> const & bytes, MapObjects & result)
{
  MemReader reader(bytes.data(), bytes.size());
  NonOwningReaderSource source(reader);

  std::string tmp(bytes.begin(), bytes.end());
  std::istringstream is(tmp);

  std::string eventString;
  MapObjectEvent event;
  MapObject poi;

  try
  {
    while (getline(is, eventString))
    {
      if (eventString.empty())
        return;

      coding::DeserializerJson des(eventString);
      des(event);
      poi.SetBestType(event.m_bestPoiType);
      poi.SetPos(event.m_poiPos);
      poi.SetDefaultName(event.m_defaultName);
      poi.SetReadableName(event.m_readableName);

      bool found = false;
      result.ForEachInRect(poi.GetLimitRect(), [&found, &poi, &event](MapObject const & item)
      {
        if (item != poi)
          return;

        if (!found)
          found = true;

        item.GetEditableEvents().push_back(event.m_event);
      });

      if (!found)
      {
        poi.GetEditableEvents().push_back(event.m_event);
        result.Add(poi);
      }
    }
  }
  catch (base::Json::Exception & ex)
  {
    LOG(LERROR, ("Cannot deserialize map objects. Exception:", ex.Msg(), ". Event string:",
                 eventString, ". Content:", std::string(bytes.begin(), bytes.end())));
  }
}
Пример #9
0
/*
 *   marscha@2006
 *   Decrypt bytes[length] in memory using key.
 *   Key has to be 8 bytes, length a multiple of 8 bytes.
 */
void
vncDecryptBytes(unsigned char *where, const int length, const unsigned char *key) {
	int i, j;
	deskey((unsigned char*) key, DE1);
	for (i = length - 8; i > 0; i -= 8) {
		des(where + i, where + i);
		for (j = 0; j < 8; j++)
			where[i + j] ^= where[i + j - 8];
	}
	/* i = 0 */
	des (where, where);
	for (i = 0; i < 8; i++)
		where[i] ^= key[i];
}
Пример #10
0
int
vncDecryptPasswdFromFile2(char *fname,
			  char *passwdFullControl, char *passwdViewOnly)
{
    FILE *fp;
    int i, ch;
    char passwd[16];

    if (strcmp(fname, "-") != 0) {
	if ((fp = fopen(fname,"r")) == NULL)
	    return 0;		/* Could not open the file */
    } else {
	fp = stdin;
    }

    for (i = 0; i < 16; i++) {
	ch = getc(fp);
	if (ch == EOF)
	    break;
	passwd[i] = ch;
    }

    if (fp != stdin)
	fclose(fp);

    if (i < 8)
	return 0;		/* Could not read eight bytes */

    deskey(s_fixedkey, DE1);

    /* Decoding first (full-control) password */
    if (passwdFullControl != NULL) {
	des(passwd, passwd);
	memcpy(passwdFullControl, passwd, 8);
	passwdFullControl[8] = '\0';
    }

    /* Decoding second (view-only) password if available */
    if (i == 16 && passwdViewOnly != NULL) {
	des(&passwd[8], &passwd[8]);
	memcpy(passwdViewOnly, &passwd[8], 8);
	passwdViewOnly[8] = '\0';
    }

    /* Destroying our copy of clear-text passwords */
    memset(passwd, 0, 16);

    return (i < 16) ? 1 : 2;
}
Пример #11
0
char *
vncDecryptPasswdFromFile(char *fname)
{
    FILE *fp;
    int i, ch;
    unsigned char *passwd = (unsigned char *)malloc(9);

    if (strcmp(fname, "-") != 0) {
	if ((fp = fopen(fname,"r")) == NULL)
	    return NULL;
    } else {
	fp = stdin;
    }

    for (i = 0; i < 8; i++) {
	ch = getc(fp);
	if (ch == EOF)
	    break;
	passwd[i] = ch;
    }

    if (fp != stdin)
	fclose(fp);

    if (i != 8)                 /* Could not read eight bytes */
	return NULL;

    deskey(s_fixedkey, DE1);
    des(passwd, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
Пример #12
0
void CLogOutputSink::writeLogMessage( String& strMsg )
{
    if ( strMsg.length() > 1 && strMsg[strMsg.length()-2] == '\r' )
        strMsg.erase(strMsg.length()-2,1);

    const char* szMsg = strMsg.c_str(); 

#if defined( OS_WINDOWS_DESKTOP )
		::OutputDebugStringA(szMsg);
#elif defined( OS_PLATFORM_MOTCE )
		::OutputDebugStringW(common::convertToStringW(strMsg).c_str());
#elif defined(OS_WP8)
		::OutputDebugStringA(szMsg);
#elif defined( OS_SYMBIAN )
        TPtrC8 des((const TUint8*)szMsg);
      	RDebug::RawPrint(des);
        return;
#endif

#if !defined( OS_PLATFORM_MOTCE )
    for( int n = 0; n < (int)strMsg.length(); n+= 100 )
        fwrite(szMsg+n, 1, min(100,strMsg.length()-n) , stdout );

    fflush(stdout);
#endif
}
// original RMessage is supplied so that remote demux plugin can extract necessary details
// using DeMux utility
TInt CMMFIlbcDecoderIntfcDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
	{
	TMMFDevSoundCIMessageData data;
	TInt result = KErrGeneral;

	// decode message
	iUtility->GetSyncMessageDataL(aMessage, data);

	switch (data.iCommand)
		{
		case EMMFDevSoundCIIlbcDecoderIntfcGetComfortNoiseGeneration:
			{
			TPckgBuf<TBool> cng; 
			iUtility->ReadFromInputDesL(aMessage, &cng);

			result = DoGetComfortNoiseGenerationL(cng());

			TPckgBuf<TBool> des(cng());
			iUtility->WriteToOutputDesL(aMessage, des);

			break;
			}
		default:
			{
			User::Leave(KErrNotSupported);
			}
		}

	return result;
	}
Пример #14
0
//--------------------------------------------------------------
void testApp::update() {
	
	float t = (ofGetElapsedTimef()) * 0.9f;
	float div = 250.0;
	
	for (int i=0; i<NUM_BILLBOARDS; i++) {
		
		// noise 
		ofVec3f vec(ofSignedNoise(t, billboards.getVertex(i).y/div, billboards.getVertex(i).z/div),
								ofSignedNoise(billboards.getVertex(i).x/div, t, billboards.getVertex(i).z/div),
								ofSignedNoise(billboards.getVertex(i).x/div, billboards.getVertex(i).y/div, t));
		
		vec *= 10 * ofGetLastFrameTime();
		billboardVels[i] += vec;
		billboards.getVertices()[i] += billboardVels[i]; 
		billboardVels[i] *= 0.94f; 
    	billboards.setNormal(i,ofVec3f(12 + billboardSizeTarget[i] * ofNoise(t+i),0,0));
	}
	
	
	// move the camera around
	float mx = (float)mouseX/(float)ofGetWidth();
	float my = (float)mouseY/(float)ofGetHeight();
	ofVec3f des(mx * 360.0, my * 360.0, 0);
	cameraRotation += (des-cameraRotation) * 0.03;
	zoom += (zoomTarget - zoom) * 0.03;
	
}
// original RMessage is supplied so that remote demux plugin can extract necessary details
// using DeMux utility
TInt CMMFG711EncoderIntfcDeMux::DoSendSlaveSyncCommandResultL(const RMmfIpcMessage& aMessage)
	{
	TMMFDevSoundCIMessageData data;
	TInt result = KErrNone;

	// decode message
	iUtility->GetSyncMessageDataL(aMessage, data);

	switch (data.iCommand)
		{
		case EMMFDevSoundCIG711EncoderIntfcGetVadMode:
			{
			TPckgBuf<TBool> vadModeOn; 
			iUtility->ReadFromInputDesL(aMessage, &vadModeOn);

			result = DoGetVadMode(vadModeOn());

			TPckgBuf<TBool> des(vadModeOn());
			iUtility->WriteToOutputDesL(aMessage, des);

			break;
			}
		default:
			{
			User::Leave(KErrNotSupported);
			}
		}

	return result;
	}
Пример #16
0
LOCAL_C void RunTest(TInt aSize)
	{
	const TInt KTestRunUs = KTestRunSeconds * 1000000;

	RThread t;
	TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
	test(r==KErrNone);
	t.SetPriority(EPriorityLess);
	TRequestStatus s;
	t.Logon(s);
	t.Resume();
	ServerSem.Wait();
	test(Server.Handle() != KNullHandle);

	RMySession sess;
	TRequestStatus stat;
	test(sess.Connect(Server,stat) == KErrNone);
	User::WaitForRequest(stat);	// connected

	Count=0;
	TPtr8 des((TUint8*)Dest, 0, aSize);
	sess.Test(des);
	User::After(KTestRunUs);
	t.Kill(0);
	User::WaitForRequest(s);
	sess.Close();
	Server.Close();
	CLOSE_AND_WAIT(t);

	TInt us=10*KTestRunUs/Count;
	test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10);
	}
Пример #17
0
void SDes(char orientation, char PlainText[8], char Key[8], char Encipher[8])
{
    char m[8];
    char k[8];

    m[0]=PlainText[7];
    m[1]=PlainText[6];
    m[2]=PlainText[5];
    m[3]=PlainText[4];
    m[4]=PlainText[3];
    m[5]=PlainText[2];
    m[6]=PlainText[1];
    m[7]=PlainText[0];

    k[0]=Key[7];
    k[1]=Key[6];
    k[2]=Key[5];
    k[3]=Key[4];
    k[4]=Key[3];
    k[5]=Key[2];
    k[6]=Key[1];
    k[7]=Key[0];

    if (orientation==0)  des(m,k);
    else undes(m,k);

    Encipher[0]=m[7];
    Encipher[1]=m[6];
    Encipher[2]=m[5];
    Encipher[3]=m[4];
    Encipher[4]=m[3];
    Encipher[5]=m[2];
    Encipher[6]=m[1];
    Encipher[7]=m[0];
}
Пример #18
0
int main(int argc, char* argv[])
{
	Maze m;
	Maze::Step src(1, 1), des(6, 5);
	std::cout<<(m.findPath(src, des) == true ? "find a path" : "No path") <<std::endl;
	Maze m1;
	m1.findAllPath(src, des);

	char a[12][20] = {
	    {L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L},
   	 	{L,L,L,L,L,L,L,L,L,L,L,L,L,L,W,L,L,L,L,L},
    	{L,L,W,W,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L},
    	{L,L,W,W,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L},
    	{L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L,L},
    	{L,L,L,L,L,L,L,W,W,L,L,L,L,L,L,L,L,L,L,L},
    	{L,L,L,L,L,L,L,L,W,W,L,L,L,L,L,L,L,L,L,L},
    	{L,L,L,L,L,L,L,L,L,W,W,W,L,L,L,L,L,L,L,L},
    	{L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L},
    	{L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L},
   	 	{L,L,L,L,L,L,L,L,L,L,W,W,W,W,W,W,L,L,L,L},
    	{L,L,L,L,W,W,L,L,L,L,W,W,W,W,W,W,L,L,L,L}
  	};
	Matrix ma(a);
	ma.changeW2O(5,8);
	std::cout<<"After change W to O"<<std::endl;
	ma.output();
	return 0;
}
Пример #19
0
/*
    解密(若len不是16的倍数, 解密会失败, return 0)
    key--8字节密钥
    in--密文, 字符串
    len--密文长度, 应是16的倍数
    return--解密后的明文, 字符串. 外部使用后应首先判断是否为0; 若不为0, 应free  
*/
char * decrypt_str(unsigned char *key, char *in, int len)
{
    char *buf = 0;
    char *p = 0;
    int bufLen;
    int resident = len % 16;/*因为一个字节由两个16进制字符表示,而且每块是8个字节*/
    if (resident != 0)
        return 0;/*failed*/

    bufLen = len / 2;
    buf = (char *)malloc(bufLen+1);
    buf[bufLen] = '\0';
    /*转换十六进制字符串为字节数组*/
    hexStr2bytes(in, len, buf);

    p = buf;
    /*init key*/
    deskey_jp(key, DE1);
    while(p < (buf + bufLen)) {
        /*ECB decrypt*/
        des((unsigned char *)p, (unsigned char *)p);
        p = p + 8;
    }
    /*清除填充在末尾的0. 由于0与'\0'等值, 所以不必再清除*/
    
    return buf;
        
}
Пример #20
0
int main() {
    char *key = "browsers";
    unsigned char data[16];
    int j;
    FILE *in, *out;

    deskey(key, EN0);
    
    in = fopen("challenge", "r");
    if (!in) {
        printf("failed opening challenge\n");
        exit(1);
    }
    fread(data, 1, 16, in);
    fclose(in);

    for (j=0; j<16; j += 8) {
        des(data+j, data+j);
    }

    out = fopen("out", "w+");
    if (!out) {
        printf("failed opening out\n");
        exit(1);
    }
    fwrite(data, 1, 16, out);
    fclose(out);

    return 0;
}
Пример #21
0
void DMediaDriverFlashWin32::CompleteWrite()
//
// Do the actual write in the completion
// Transfer data in blocks from the client and AND it to the 'flash'
//
	{
	__KTRACE_OPT(KLOCDRV,Kern::Printf("Flash:WriteComplete"));

	TInt r = KErrNone;
	TUint8* flash = iBase + (TInt)iWriteReq->Pos();
	TInt len = (TInt)iWriteReq->Length();
	TInt offset = 0;
	while (len > 0)
		{
		TInt size = Min(len, KDataBufSize);
		TPtr8 des(iData,size);
		r = iWriteReq->ReadRemote(&des, offset);
		if (r!=KErrNone)
			break;
		len -= size;
		offset += size;
		const TUint8* ptr = iData;
		do
			{
			*flash++ &= *ptr++;
			} while (--size > 0);
		}

	if (iState == EWriting)
		iState = EIdle;
	Complete(EReqWrite,r);
	if (iState == ESuspended)
		StartErase();
	}
Пример #22
0
TInt DMediaDriverFlashWin32::DoRead()
	{
	if (iWriteReq)
		return 1;	// write in progress so defer read
	
	__KTRACE_OPT(KLOCDRV,Kern::Printf("Flash:DoRead"));

	if (iState==EErasePending)
		{
		iTimer.Cancel();
		iState = ESuspended;
		}
	if (iState==EIdle || iState==ESuspended)
		{
		// can do the read now
		TInt pos=(TInt)iReadReq->Pos();
		TInt len=(TInt)iReadReq->Length();

		TPtrC8 des(iBase+pos,len);
		TInt r=iReadReq->WriteRemote(&des,0);
		Complete(EReqRead,r);
		if (iState==ESuspended)
			StartErase();
		}
	else if (iState==EErase)
		{
		// erase in progress - suspend it
		SuspendErase();
		}
	else if (iState==EEraseNoSuspend)
		iState=ESuspendPending;
	// wait for suspend to complete
	return KErrNone;
	}
Пример #23
0
OrderedTask* 
TaskFileXCSoar::GetTask(const Waypoints *waypoints, unsigned index) const
{
  assert(index == 0);

  if (protected_task_manager == NULL)
    return NULL;

  DataNode* root = DataNodeXML::load(path);
  if (!root)
    return NULL;

  if (_tcscmp(root->get_name().c_str(),_T("Task")) == 0) {
    OrderedTask* task = protected_task_manager->task_blank();
    Deserialiser des(*root, waypoints);
    des.deserialise(*task);
    if (task->check_task()) {
      delete root;
      return task;
    }
    delete task;
    delete root;
    return NULL;
  }
  delete root;
  return NULL;
}
Пример #24
0
char *
vncDecryptPasswdFromFile(char *fname)
{
    FILE *fp;
    int i, ch;
    unsigned char *passwd = (unsigned char *)malloc(9);

    if ((fp = fopen(fname,"r")) == NULL) return NULL;

    for (i = 0; i < 8; i++) {
        ch = getc(fp);
        if (ch == EOF) {
            fclose(fp);
            return NULL;
        }
        passwd[i] = ch;
    }

    fclose(fp);

    deskey(fixedkey, DE1);
    des(passwd, passwd);

    passwd[8] = 0;

    return (char *)passwd;
}
Пример #25
0
bool LevelDirector::LoadLevel( const std::string & level )
{
	Reset();
	LevelAIDeserializer root( *this );
	XMLDeserializer des( root );
	return des.Deserialize( level );
}
Пример #26
0
int
vncEncryptAndStorePasswd(char *passwd, char *fname)
{
    FILE *fp;
    int i;
    unsigned char encryptedPasswd[8];

    if ((fp = fopen(fname,"w")) == NULL) return 1;

    chmod(fname, S_IRUSR|S_IWUSR);

    /* pad password with nulls */

    for (i = 0; i < 8; i++) {
        if (i < strlen(passwd)) {
            encryptedPasswd[i] = passwd[i];
        } else {
            encryptedPasswd[i] = 0;
        }
    }

    /* Do encryption in-place - this way we overwrite our copy of the plaintext
       password */

    deskey(fixedkey, EN0);
    des(encryptedPasswd, encryptedPasswd);

    for (i = 0; i < 8; i++) {
        putc(encryptedPasswd[i], fp);
    }

    fclose(fp);
    return 0;
}
Пример #27
0
void CmSaliencyRC::Evaluate(CStr gtImgsW, CStr &salDir, CStr &resName)
{
	vecS des(SAL_TYPE_NUM);
	for (int i = 0; i < SAL_TYPE_NUM; i++)
		des[i] = SAL_TYPE_DES[i];
	CmEvaluation::Evaluate(gtImgsW, salDir, resName, des);
}
Пример #28
0
Файл: LL.c Проект: joyjitc/lab
int main()
{
	int ch;
	while(1)
	{
		printf("\n1)Insert\n2)Delete\n3)Display\n4)Sort in ascending order\n5)Sort in descending order\n6)Search for an element\n7)Reverse\n8)Exit\nEnter your choice ::");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1: insert();
                    display();
					break;
			case 2: del();
                    display();
					break;
			case 3: display();
					break;
			case 4: asc();
					display();
					break;
			case 5: des();
					display();
					break;
			case 6: search();
					break;
			case 7: reverse();
					display();
					break;
			case 8: exit(1);

		}
	}
}
Пример #29
0
void SoundProtoManager::LoadResources()
{
	SoundsDeserializer root;
	root.m_soundDes.SetReceiver<SoundProtoManager>( *this, &SoundProtoManager::AddResource );
	root.m_soundDes.SetGetter<SoundProtoManager>( *this, &SoundProtoManager::GetResource );
	XMLDeserializer des( root );
	des.Deserialize( "Data/Protos/sounds.xml" );	
}
Пример #30
0
int DES::decrypt ( char key[8], char* data, int blocks )
{
   if ((!data)||(blocks<1))
	  return 0;
   deskey ( (unsigned char *)key, DECRYPT );
   des ( (unsigned char *)data, (unsigned char *)data, blocks);
   return 1;
};