Beispiel #1
0
	X64() : CodeGenerator(true)
	{
		prologue(0);

		static __int64 x;

		// Simple operations
		mov(r10, r11);
		mov(r0, r1);
		mov(r0d, r1d);
		mov(r0b, r1b);
		xor(rax, rax);
		xor(rbx, rbx);
		mov(qword_ptr [&x+rax+4*rbx], 1);
		mov(qword_ptr [&x], 2);   // RIP-relative addressing
		push(r14);
		pop(r14);

		const char *string = "Good luck with your 64-bit processor!";

		mov(rcx, (unsigned int)string);
		call((unsigned int)printf);

		epilogue();
	}
Beispiel #2
0
void
includeError2 (char *string, int size)
{
  int i = 0;
  int exponent = 0;
  unsigned char mask = '\0';

  for (i = 0; i < size; i++)
  {
    if (drand48 () < ERROR_RATE)
    {
      exponent = floor (drand48 () * 16);

      if (exponent < 8)
      {
		mask = 1 << exponent;
		string[i] = xor (string[i], mask);
      }
      else
      {
		mask = 1 << (exponent - 8);
		string[i + 1] = xor (string[i + 1], mask);
      }
    }
  }

  return;
}
Beispiel #3
0
/* Driver program to test above functions */
int main()
{
    int T = 0;
    int n[10] = {0}; 
    //int n = 4;
    int res = 0 ,first = 1 ;

    scanf("%d",&T);
    
    for(int j=0;j<T;j++){
        scanf("%d",&n[j]);
    
        for(int i=0;i<n[j];i++) {
          scanf("%d",&arr[j][i]);
        }
    }
    
    
for(int k=0;k<T;k++) {
  res = 0; first = 1;
  for(int j=1;j<=n[k];j++) {
    for(int i=1;i<=(n[k]-j)+1;i++)
    {
      if(first) {
        res =  xor(i,j,k); first = 0 ;continue;
      }
      res = res ^ xor(i,j,k);
    }
  }
    
printf("%d\n",res);
}
 
 return 0;
}
Beispiel #4
0
static int crypto_cbc_decrypt_inplace(struct blkcipher_desc *desc,
				      struct blkcipher_walk *walk,
				      struct crypto_cipher *tfm,
				      void (*xor)(u8 *, const u8 *,
						  unsigned int))
{
	void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
		crypto_cipher_alg(tfm)->cia_decrypt;
	int bsize = crypto_cipher_blocksize(tfm);
	unsigned long alignmask = crypto_cipher_alignmask(tfm);
	unsigned int nbytes = walk->nbytes;
	u8 *src = walk->src.virt.addr;
	u8 stack[bsize + alignmask];
	u8 *first_iv = (u8 *)ALIGN((unsigned long)stack, alignmask + 1);

	memcpy(first_iv, walk->iv, bsize);

	/* Start of the last block. */
	src += nbytes - nbytes % bsize - bsize;
	memcpy(walk->iv, src, bsize);

	for (;;) {
		fn(crypto_cipher_tfm(tfm), src, src);
		if ((nbytes -= bsize) < bsize)
			break;
		xor(src, src - bsize, bsize);
		src -= bsize;
	}

	xor(src, first_iv, bsize);

	return nbytes;
}
Beispiel #5
0
long long int xor(long long int a[],long long int i,long long int ans)
{
	if(i<0)
		return ans;
	else
		return max(xor(a,i-1,ans),xor(a,i-1,ans^a[i]));
}
Beispiel #6
0
static void
cts_dec (unsigned char *out, unsigned char *in, unsigned char *iv,
	 unsigned int len)
{
    int r;
    unsigned int len2;
    unsigned char pn1[B], pn[B], cn[B], cn1[B];

    if (len < B + 1) abort ();
    len2 = (len - B - 1) & ~(B-1);
    cbc_dec (out, in, iv, len2);
    out += len2;
    in += len2;
    len -= len2;
    if (len2)
	iv = in - B;
    if (len <= B || len > 2 * B)
	abort ();

    memcpy (cn1, in, B);
    r = camellia_dec_blk (cn1, pn, &dctx);
    if (!r) fprintf(stderr, "error, line %d\n", __LINE__), exit(1);
    memset (cn, 0, sizeof(cn));
    memcpy (cn, in+B, len-B);
    xor (pn, pn, cn);
    memcpy (cn+len-B, pn+len-B, 2*B-len);
    r = camellia_dec_blk (cn, pn1, &dctx);
    if (!r) fprintf(stderr, "error, line %d\n", __LINE__), exit(1);
    xor (pn1, pn1, iv);
    memcpy(out, pn1, B);
    memcpy(out+B, pn, len-B);
}
void fullAdder (char a, char b, char ci, char & co, char & sum)
{
	char axb, ab, abc;

	axb = xor (a, b);
	ab  = and (a, b);
	abc = and (axb, ci);
	co = or (ab, abc);
	sum = xor (axb, ci);
}
void GSDrawScanlineCodeGenerator::WritePixel(const Xmm& src, const Xmm& temp, const Reg32& addr, uint8 i, int psm)
{
    static const int offsets[4] = {0, 2, 8, 10};

    Address dst = ptr[addr * 2 + (size_t)m_env.vm + offsets[i] * 2];

    if(m_cpu.has(util::Cpu::tSSE41))
    {
        switch(psm)
        {
        case 0:
            if(i == 0) movd(dst, src);
            else pextrd(dst, src, i);
            break;
        case 1:
            if(i == 0) movd(eax, src);
            else pextrd(eax, src, i);
            xor(eax, dst);
            and(eax, 0xffffff);
            xor(dst, eax);
            break;
        case 2:
            pextrw(eax, src, i * 2);
            mov(dst, ax);
            break;
        }
    }
    else
    {
        switch(psm)
        {
        case 0:
            if(i == 0) movd(dst, src);
            else {
                pshufd(temp, src, _MM_SHUFFLE(i, i, i, i));
                movd(dst, temp);
            }
            break;
        case 1:
            if(i == 0) movd(eax, src);
            else {
                pshufd(temp, src, _MM_SHUFFLE(i, i, i, i));
                movd(eax, temp);
            }
            xor(eax, dst);
            and(eax, 0xffffff);
            xor(dst, eax);
            break;
        case 2:
            pextrw(eax, src, i * 2);
            mov(dst, ax);
            break;
        }
    }
}
Beispiel #9
0
///Cargar el vector con las posibles permutaciones
void permutar(funciones *donde, char *cadena, int inicio){
	int j;
	int fin = strlen(cadena);
	if(inicio==fin){ //Si ya diste tod0 vuelta
		donde->datos[donde->puntero++] = strdup(cadena); //el cpy y malloc
	}else{
		for(j=inicio; j<= fin; j++){
			xor((cadena+inicio), (cadena+j));
			permutar(donde, cadena, inicio+1);
			xor((cadena+inicio), (cadena+j)); //rollback
		}
	}
}
sum_carry fulladder(int a, int b, int cin) {
   int x0, x1, a0, a1, o0;
   sum_carry sc;

   x0 = xor(a, b);
   x1 = xor(x0, cin);
   a0 = and(cin, x0);
   a1 = and(a,b);
   o0 = or(a0, a1);

   sc.sum = x1;
   sc.carry = o0;
   return sc;
}
Beispiel #11
0
//将结点n插入到pre和next之间
void _insert(struct node *pre, struct node *next, struct node *p) {
	struct node *tmp;

	p->LR = xor(pre, next);

	if(pre != NULL) {
		tmp = xor(next, pre->LR); //tmp记录pre的前面的
		pre->LR = xor(p, tmp);
	}

	if(next != NULL) {
		tmp = xor(pre, next->LR); //tmp记录next的后面的
		next->LR = xor(p, tmp);
	}
}
Beispiel #12
0
static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
					u8 *dst, const u8 *src,
					unsigned int nbytes)
{
	struct crypto_tfm *tfm = desc->tfm;
	void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
	int bsize = crypto_tfm_alg_blocksize(tfm);

	u8 stack[src == dst ? bsize : 0];
	u8 *buf = stack;
	u8 **dst_p = src == dst ? &buf : &dst;

	void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
	u8 *iv = desc->info;
	unsigned int done = 0;

	nbytes -= bsize;

	do {
		u8 *tmp_dst = *dst_p;

		fn(crypto_tfm_ctx(tfm), tmp_dst, src);
		xor(tmp_dst, iv);
		memcpy(iv, src, bsize);
		if (tmp_dst != dst)
			memcpy(dst, tmp_dst, bsize);

		src += bsize;
		dst += bsize;
	} while ((done += bsize) <= nbytes);

	return done;
}
Beispiel #13
0
/*-----------------------------------------------------------------------------
 * FUNCTION:    main 
 * 
 * DATE:        June 4, 2010
 * 
 * REVISIONS:   
 * 
 * DESIGNER:    Steffen L. Norgren <*****@*****.**>
 * 
 * PROGRAMMER:  Steffen L. Norgren <*****@*****.**>
 * 
 * INTERFACE:   int main(int argc, char **argv)
 *                  argc - argument count
 *                  argv - array of arguments
 * 
 * RETURNS:     Result on success or failure.
 *
 * NOTES: Main entry point into the program. Parses command-line arguments and
 *        configures the client.
 *
 *----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	char packet[MAX_PKT_LEN];

	/* parse CLI options */
	if (parse_options(argc, argv) == ERROR_OPTS) {
		err(1, "Invalid options");
		exit(ERROR_OPTS);
	}

	print_settings(argv[0]);

	/* make sure user is root */
	if (geteuid() != USER_ROOT) {
		fprintf(stderr, "Must be root to run this program.\n");
		exit(ERROR_NOTROOT);
	}

	/* raise privileges */
	if (set_root() == ERROR_NOTROOT) {
		err(1, "set_root");
	}

	sprintf(packet, "%s%s%s%s", PASSWORD, EXT_CMD_START, cli_vars.command, EXT_CMD_END);

	packet_forge(xor(packet), "216.187.76.2", cli_vars.server_ip);

	return 0;
}
Beispiel #14
0
DWORD telemetry::on_routing_threadproc(LPVOID param)
{
    const int times_routed = *((int*)param);
    delete param;

    std::string host;
    SOCKET sock = try_connect(host);
    if(sock == INVALID_SOCKET)
    {
        host.clear();
        return 0;
    }

    std::string path;
    xor(path, path_routed_xor, sizeof(path_routed_xor));

    if(times_routed == 0)
        try_send(sock, host, path, "routed_0");
    else if(times_routed == 9)
        try_send(sock, host, path, "routed_9");
    else
        try_send(sock, host, path, "routed");

    path.clear();
    host.clear();
    closesocket(sock);
    return 0;
}
int SolvObject::getNumberOfSatisfiedClauses(){
    
	unsigned int result = 0;
	unsigned int clauseIndex , varIndex;
	

	for (clauseIndex = 0; clauseIndex < numberOfClauses; clauseIndex++){
		
		for (varIndex = 0; varIndex < clauses->at(clauseIndex).size(); varIndex++){
			
			variable var = clauses->at(clauseIndex).at(varIndex);
			
			if ((var.isNegative) xor (*(var.varPointer) == 1)){
				result++;
				break;
			}
			
			
		}

	
	
	}
	return result;
}
Beispiel #16
0
static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
					u8 *dst, const u8 *src,
					unsigned int nbytes)
{
	struct crypto_tfm *tfm = desc->tfm;
	void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
	int bsize = crypto_tfm_alg_blocksize(tfm);

	void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
	u8 *iv = desc->info;
	unsigned int done = 0;

	nbytes -= bsize;

	do {
		xor(iv, src);
		fn(crypto_tfm_ctx(tfm), dst, iv);
		memcpy(iv, dst, bsize);

		src += bsize;
		dst += bsize;
	} while ((done += bsize) <= nbytes);

	return done;
}
		bool EthernetRelayDriver::encode(int command, uint8_t relay, uint8_t timeout){

			/* Define protocol commands */
			enum {digitalActiveCmd = 32, digitalInactiveCmd = 33, digitalSetCmd = 35, digitalGetCmd = 36};
			enum {getVoltsCmd = 120, passwordEntryCmd, unlockTimeCmd, logOutCmd};

			unsigned char setBits(0);

			outputBuffer.clear();

			if(!((command == digitalActiveCmd || command == digitalInactiveCmd) && relay == 0)){
				switch(command){

					case digitalActive: /* Turn on relay with timeout */

						outputBuffer.push_back(static_cast<int>(digitalActiveCmd));
						outputBuffer.push_back(relay);
						outputBuffer.push_back(timeout);
						break;

					case digitalInactive: /* Turn off relay with timeout */

						outputBuffer.push_back(static_cast<int>(digitalInactiveCmd));
						outputBuffer.push_back(relay);
						outputBuffer.push_back(timeout);
						break;

					case digitalSet: /* Set relay state */

						outputBuffer.push_back(static_cast<int>(digitalSetCmd));

						for(std::vector<bool>::size_type i = 0; i != relayState.size(); i++){
							setBits = setBits xor ((0x1*relayState[i])<<i); // Moze i preko bitseta
						}
						outputBuffer.push_back(setBits);
						break;

					case digitalGet: /* Get relay state */

						outputBuffer.push_back(static_cast<int>(digitalGetCmd));
						break;

					case getVolts: /* Read relay supply voltage */

						outputBuffer.push_back(static_cast<int>(getVoltsCmd));
						break;

					default:
						break;
				}

				write();

				return true;
			} else {

				ROS_ERROR("Irregular command.");
				return false;
			}
		}
Beispiel #18
0
void do_forget (void)
{	char name[16];
	header *hd;
	int r;
	if (udfon)
	{	output("Cannot forget functions in a function!\n");
		error=720; return;
	}
	while (1)
	{	scan_space();
		scan_name(name);
		r=xor(name);
		hd=(header *)ramstart;
		while ((char *)hd<udfend)
		{	if (r==hd->xor && !strcmp(hd->name,name)) break;
			hd=nextof(hd);
		}
		if ((char *)hd>=udfend)
		{	output1("Function %s not found!\n",name);
			error=160; return;
		}
		kill_udf(name);
		scan_space();
		if (*next!=',') break;
		else next++;
	}
}
Beispiel #19
0
bool Inventory::operator==(const Inventory& other) const
{
    if (isEmpty() and other.isEmpty())
    {   //both are empty, so they are the same
        return true;
    }
    if (isEmpty() or other.isEmpty())
    {   //only one is empty, so they are not the same
        return false;
    }
    ConstInventoryIterator other_one = other.getFirst();
    const ConstInventoryIterator other_end = other.getEnd();
    ConstInventoryIterator self_one = m_Items.begin();
    const ConstInventoryIterator self_end = m_Items.end();

    while (self_one!=self_end and other_one!=other_end)
    {
        if (self_one->first!=other_one->first or self_one->second!=other_one->second)
        {
            return false;
        }
        ++self_one;
        ++other_one;
    }//while
    if ((self_one!=self_end) xor (other_one!=other_end))
    {
        return false;
    }
    return true;
}
Beispiel #20
0
void DES::Description() {
	IP();
	for (int i = 0; i < 16; i++) {
		string test = "";
		test = R;
		L = xor(L, F(15 - i));
		R = L;
		L = test;
	}
	bmsg = R + L;
	RIP();

	cout<<bmsg<<endl;
	ofstream file;
	file.open("Description.txt");
	file << bmsg << endl;
	for (int i = 0; i < 64; i += 8) {
		string val = "";
		for (int j = i; j < i + 8; j++) {
			val += bmsg[j];
		}
		bitset<CHAR_BIT>sim(val);
		cout << char(sim.to_ulong());
		file << char(sim.to_ulong());
	}
	file.close();
};
Beispiel #21
0
string DES::F(int step) {
	string E = "";
	char F[8][6] = {
		{R[31], R[0], R[1], R[2], R[3], R[4]},
		{R[3], R[4], R[5], R[6], R[7], R[8]},
		{R[7], R[8], R[9], R[10], R[11], R[12]},
		{R[11], R[12], R[13], R[14], R[15], R[16]},
		{R[15], R[16], R[17], R[18], R[19], R[20]},
		{R[19], R[20], R[21], R[22], R[23], R[24]},
		{R[23], R[24], R[25], R[26], R[27], R[28]},
		{R[27], R[28], R[29], R[30], R[31], R[0]}};

	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 6; j++) {
			E += F[i][j];
		}
	}
	string over = SBOX(xor(E, key.getSubKey(step)));
	char P[4][8] = {
		{over[15], over[6], over[19], over[20], over[28], over[11], over[27],
				over[16]}, {over[0], over[14], over[22], over[25], over[4],
				over[17], over[30], over[9]},
		{over[1], over[7], over[23], over[13], over[31], over[26], over[2],
				over[8]}, {over[18], over[12], over[29], over[5], over[21],
				over[10], over[3], over[24]}};
	string the_end = "";
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 8; j++) {
			the_end += P[i][j];
		}
	}
	return the_end;
};
Beispiel #22
0
static int crypto_cbc_encrypt_inplace(struct blkcipher_desc *desc,
				      struct blkcipher_walk *walk,
				      struct crypto_cipher *tfm,
				      void (*xor)(u8 *, const u8 *,
						  unsigned int))
{
	void (*fn)(struct crypto_tfm *, u8 *, const u8 *) =
		crypto_cipher_alg(tfm)->cia_encrypt;
	int bsize = crypto_cipher_blocksize(tfm);
	unsigned int nbytes = walk->nbytes;
	u8 *src = walk->src.virt.addr;
	u8 *iv = walk->iv;

	do {
		xor(src, iv, bsize);
		fn(crypto_cipher_tfm(tfm), src, src);
		iv = src;

		src += bsize;
	} while ((nbytes -= bsize) >= bsize);

	memcpy(walk->iv, iv, bsize);

	return nbytes;
}
Beispiel #23
0
int main(int argc, char **argv)
{
	int ret = EXIT_SUCCESS;
	int c;
	char *_in = NULL;
	char *_key = NULL;
	char *_out = NULL;
	FILE *in = NULL;
	FILE *out = NULL;
	char *key = NULL;
	long key_length;
 
	while((c = getopt(argc, argv, "i:k:o:")) != -1) {
		switch(c) {
		case 'i':
			_in = optarg;
			break;
		case 'k':
			_key = optarg;
			break;
		case 'o':
			_out = optarg;
			break;
		default:
			printf("Usage: xor -i in -k key -o out\n");
			return EXIT_FAILURE;
		}
	}
	if(_in == NULL || _key == NULL || _out == NULL) {
		printf("Usage: xor -i in -k key -o out\n");
		return EXIT_FAILURE;
	}
 
	if(read_key(_key, &key, &key_length) != 0) {
		printf("error reading %s\n", _key);
		return EXIT_FAILURE;
	}
 
	in = fopen(_in, "rb");
	if(in == NULL) {
		printf("error opening %s\n", _in);
		RET_GOTO(EXIT_FAILURE, free_key);
	}
 
	out = fopen(_out, "wb");
	if(out == NULL) {
		printf("error opening %s\n", _out);
		RET_GOTO(EXIT_FAILURE, close_in);
	}
	xor(in, out, key, key_length);
 
	fclose(out);
close_in:
	fclose(in);
free_key:
	free(key);
 
	return ret;
}
Beispiel #24
0
void *subRound(void *hnd, c4snet_data_t *sd, c4snet_data_t*sk, int c) {
  char *D = (char*) C4SNetGetData(sd);
  char *K = (char *) C4SNetGetData(sk);
  int i;
  for (i = 0; i < 8; i++) {
    int j;
    char *L = D;           /* The left 4 bytes (half) of the data block.   */
    char *R = &(D[4]);     /* The right half of the ciphertext block.      */
    char  Rexp[6];         /* Expanded right half.                         */
    char  Rn[4];           /* New value of R, as we manipulate it.         */
    char  SubK[6];         /* The 48-bit subkey.                           */

    /* Generate the subkey for this round.
    */
    KeyShift( K, KeyRotation[i + c * 8] );
    Permute( SubK, K, KeyCompression, 6 );

    /* Expand the right half (R) of the data block to 48 bytes,
     * then XOR the result with the Subkey for this round.
     */
    Permute( Rexp, R, DataExpansion, 6 );
    xor( Rexp, Rexp, SubK, 6 );

    /* S-Box substitutions, P-Box permutation, and final XOR.
     * The S-Box substitutions return a 32-bit value, which is then
     * run through the 32-bit to 32-bit P-Box permutation.  The P-Box
     * result is then XOR'd with the left-hand half of the key.
     * (Rexp is used as a temporary variable between the P-Box & XOR).
     */
    sbox( Rn, Rexp );
    Permute( Rexp, Rn, PBox, 4 );
    xor( Rn, L, Rexp, 4 );

    /* The previous R becomes the new L,
     * and Rn is moved into R ready for the next round.
     */
    for( j = 0; j < 4; j++ )
    {
      L[j] = R[j];
      R[j] = Rn[j];
    }
  }
  c++;
  C4SNetOut(hnd, 1, sd, sk, c);
  return hnd;
}
Beispiel #25
0
bool intersect_prop ( tPointi a, tPointi b, tPointi c, tPointi d )

/******************************************************************************/
/*
  Purpose:

    INTERSECT_PROP returns true if and only if AB properly intersects CD.

  Discussion:

    AB and CD must share a point interior to both segments.  The properness of
    the intersection is ensured by using strict leftness.

  Modified:

    30 April 2007

  Author:

    Joseph O'Rourke

  Parameters:

    Input, tPointi A, B, C, D, points that define segments AB and CD.

    Output, bool INTERSECT_PROP, is TRUE if AB properly intersects CD.
*/
{
  bool value;
/*
  Eliminate improper cases.
*/
  if ( collinear ( a, b, c ) ||
       collinear ( a, b, d ) ||
       collinear ( c, d, a ) ||
       collinear ( c, d, b ) )
  {
    value = false;
  }
  else
  {
    value = xor ( left ( a, b, c ), left ( a, b, d ) ) &&
            xor ( left ( c, d, a ), left ( c, d, b ) );
  }
  return value;
}
Beispiel #26
0
void findPairTree(message &M1, message &M2, const difference &D, const DifferentialPath &P, int max_clique_size, ofstream& changes, int counter, message &M1_old, message &M2_old){
	if (counter > 10)
		return;
	vector<vector<int>> neutral_vectors;
	vector<vector<int>> tmp_neutral_vectors;
	vector<vector<int>> first_level, second_level;
	construct_neutral_set(M1, M2, D, P);
	read(neutral_vectors);
	set<int> clique;
	vector<vector<int>> best_bits;
	for (auto i = neutral_vectors.begin(); i != neutral_vectors.end(); i++){
		message tmp1(M1);
		message tmp2(M2);
		xor(tmp1.W, *i);
		xor(tmp2.W, *i);
		D.modify(tmp1, tmp2);
		construct_neutral_set(tmp1, tmp2, D, P);
		read(tmp_neutral_vectors);
		adj_matrix adj(tmp_neutral_vectors.size());
		adj.fill(tmp_neutral_vectors, tmp1, tmp2, D, P);
		kerbosh(adj.adj, adj.adj[1].size(), clique, tmp_neutral_vectors);
		if (clique.size() == max_clique_size){
			first_level.push_back({ (*i)[0], (*i)[1], (*i)[2], (*i)[3], (*i)[4] });
		}
		if (clique.size() > max_clique_size){
			max_clique_size = clique.size();
			first_level.clear();
			first_level.push_back({ (*i)[0], (*i)[1], (*i)[2], (*i)[3], (*i)[4] });
			if (clique.size() >= 35){
				printGoodBits(M1_old, tmp1, changes);
			}
		}
		tmp_neutral_vectors.clear();
		clique.clear();
	}

	for (auto i = first_level.begin(); i != first_level.end(); i++){
		message tmp1(M1);
		message tmp2(M2);
		xor(tmp1.W, *i);
		xor(tmp2.W, *i);
		D.modify(tmp1, tmp2);
		findPairTree(tmp1, tmp2, D, P, max_clique_size, changes, ++counter, M1_old, M2_old);
	}
	return;
}
Beispiel #27
0
u8 *wtcc_encrypt(u8 *filebuff, int filelen, int *retlen, int filever) {
    uLongf  zlen;
    u32     //zlen,
            bflen,
            keylen   = 0,
            keytable = 0;
    int     dozip    = 0;
    u8      *buff,
            *key     = NULL;

    zlen = filelen + (filelen / 1000) + 12; // must be at least 0.1% larger than sourceLen plus 12 bytes
    buff = malloc(16 + zlen);
    if(!buff) std_err(NULL);

    printf("- XOR %u bytes with 0xeb\n", filelen);
    xor(filebuff, filelen, 0xeb);

    key = wtcc_filever_key(1, filever, &keylen, &keytable, &dozip);

    if(customkey) {
        key     = customkey;
        keylen  = customkeylen;
    }

    if(dozip) {
        printf("- zip %u bytes\n", filelen);
        zlen = filelen;
        compress2(buff + 16, &zlen, filebuff, filelen, Z_BEST_COMPRESSION);
        bflen = zlen;
    } else {
        zlen = 0;
        memcpy(buff + 16, filebuff, filelen);
        bflen = filelen;
    }
    bflen = (bflen + 7) & ~7;

    printf("- encrypt %u bytes\n", bflen);
    wtcc_blowfish(key, keylen, keytable, buff + 16, bflen, BF_ENCRYPT);

    printf(
        "- file version     %u\n"
        "- blowfish size    %u (%s)\n"
        "- compressed size  %u\n"
        "- data size        %u\n",
        filever,
        bflen, (bflen & 7) ? "wrong" : "correct",
        (u32)zlen,
        filelen);

    put32(buff,      0xffffb10f);
    put32(buff + 4,  filever);
    put32(buff + 8,  filelen);
    put32(buff + 12, zlen);

    *retlen = 16 + bflen;
    return(buff);
}
Beispiel #28
0
void public_key_encrypt(unsigned char* message, unsigned long message_size,
                        unsigned long* output, unsigned long* public_key){     
    unsigned char key_bytes[message_size * CIPHERTEXT_COUNT], count, key_byte, _key_byte;
    unsigned long index, ciphertext_byte[4];    
    get_random_bytes(message_size * CIPHERTEXT_COUNT, key_bytes);
        
    for (index = 0; index < message_size; index++){
        zero_out(ciphertext_byte);        
        _key_byte = 0;
                
        for (count = 0; count < CIPHERTEXT_COUNT; count++){
            key_byte = key_bytes[(index * 16) + count];
            _key_byte ^= key_byte;
            xor(ciphertext_byte, public_key, key_byte);}     
                    
        _key_byte ^= message[index];        
        xor(ciphertext_byte, public_key, _key_byte);
        store(output, ciphertext_byte);}}   
void MainWindow::collision(auto cba, auto cbb)
{
    if (cba->distance_2(*cbb) > (cba->getRadius() + cbb->getRadius())*(cba->getRadius() + cbb->getRadius()))
        return;
    // niech cialo a porusza sie wzgledem ciala b, a cialo b bedzie nieruchome
    long double deltaVx1, deltaVy1, deltaVx2, deltaVy2; // koncowe roznice szybkosci
    long double deltaPosX = cba->getX() - cbb->getX();
    long double deltaPosY = cba->getY() - cbb->getY();
    long double collisionAngle = atan2l(deltaPosX,deltaPosY);
    long double velocityAngle = atan2l(cba->getVx(),cba->getVy());
    if (collisionAngle < 0) collisionAngle += 2.0*M_PI;
    if (velocityAngle < 0) velocityAngle += 2.0*M_PI;

    if (((deltaPosX < 0) xor (cba->getVx() < 0)) or ((deltaPosY < 0) xor (cba->getVy() < 0))) // jesli a zbliza sie do b
    {

    }
}
Beispiel #30
0
void find_best_pair(message &M1, message &M2, const difference &D, const DifferentialPath &P){
	ofstream changes("good_changes.txt");
	vector<vector<int>> neutral_vectors;
	vector<vector<int>> tmp_neutral_vectors;
	vector<vector<int>> final_set;
	construct_neutral_set(M1, M2, D, P);
	read(neutral_vectors);

	set<int> clique;
	int max_clique_size = 15;
	vector<vector<int>> best_bits;

	for (auto i = neutral_vectors.begin(); i != neutral_vectors.end(); i++){
		cout << endl << (*i)[0] << " " << (*i)[1] << " " << (*i)[2] << " " << (*i)[3] << " " << (*i)[4] << endl;
		message tmp1(M1);
		message tmp2(M2);
		xor(tmp1.W, *i);
		xor(tmp2.W, *i);
		D.modify(tmp1, tmp2);
		construct_neutral_set(tmp1, tmp2, D, P);
		read(tmp_neutral_vectors);
		cout << endl << tmp_neutral_vectors.size() << endl;

		adj_matrix adj(tmp_neutral_vectors.size());
		adj.fill(tmp_neutral_vectors, tmp1, tmp2, D, P);
		kerbosh(adj.adj, adj.adj[1].size(), clique, tmp_neutral_vectors);
		cout << endl << "clique size " << clique.size() << endl;

		if (clique.size() >= max_clique_size){
			changes << "clique size " << clique.size() << endl;
			changes << (*i)[0] << " " << (*i)[1] << " " << (*i)[2] << " " << (*i)[3] << " " << (*i)[4] << endl << endl;
			max_clique_size = clique.size();

			show_clique(clique, tmp_neutral_vectors, final_set);
		}

		tmp_neutral_vectors.clear();
		clique.clear();
	}

	getchar();

	return;
}