library/src/utility/BP-StringUtilities.cc
// XOR "Encrypts" a provided value.  Value can contain binary data.  Since
// xored values do not change length during "encrypting" data.
XOR "Encrypts" a provided value.  Value can contain binary data.  Since
xored values do not change length during "encrypting" data.
XOR " Encrypts " a provided value . Value can contain binary data . Since xored values do not change length during " encrypting " data .
unsigned char * BP_XOREncrypt(unsigned char *val, size_t val_length, unsigned char * key, size_t key_length)
{
	if(!val)
		return NULL;
	if(!val_length)
		return NULL;
	if(!key)
		return NULL;
	if(!key_length)
		return NULL;
	unsigned char *out_val = (unsigned char *) bpcalloc(val_length, 1);
	if(!out_val)
		return NULL;
	memcpy(out_val, val, val_length);
	size_t val_count = 0;
	size_t outer_n = 0;
	for(; outer_n < val_length; outer_n++)
	{
		out_val[outer_n] = out_val[outer_n] ^ key[val_count];
		val_count++;
		if(val_count == val_length)
			val_count = 0;
	}
	return out_val;
}
unsigned char * BP_XOREncrypt ( unsigned char * val , size_t val_length , unsigned char * key , size_t key_length ) { if ( ! val ) return NULL ; if ( ! val_length ) return NULL ; if ( ! key ) return NULL ; if ( ! key_length ) return NULL ; unsigned char * out_val = ( unsigned char * ) bpcalloc ( val_length , 1 ) ; if ( ! out_val ) return NULL ; memcpy ( out_val , val , val_length ) ; size_t val_count = 0 ; size_t outer_n = 0 ; for ( ; outer_n < val_length ; outer_n ++ ) { out_val [ outer_n ] = out_val [ outer_n ] ^ key [ val_count ] ; val_count ++ ; if ( val_count == val_length ) val_count = 0 ; } return out_val ; }
XOR "Encrypts" a provided value.
XOR " Encrypts " a provided value .
// ensure we have non-zero pointers and size references // attempt to allocate space for buffer // copy in data // index counter for key //Loop through each byte of file until EOF //XOR the data and write it to a file // keep track of value count // return bin value on success