this is my first try at making a stream cipher so im not keeping my hopes up.
i
m trying to create a one time pad based on a given key.
i take the users (char*) key and loadit into an unsigned long[256] array and a unsigned char array[1024]
then do some math than can't be reversed - atleast im hoping this is the case - on the key to make a hash value.
and store it.
Code:
}
for( int N = 0; N < 16; N++){//repeat everything 16 times
//cipher the key. uses 'p' the last bite stored from above
for( i = 0; i < 255; i+=2){
c->key[i] = c->key[i] ^ (c->key[i+1] + 1); //xor from the front
c->key[255-i] = c->key[255-i] ^ c->key[254-i];//xor from the back
p = 0xFF000000 & (c->key[255-i] << p%24);
p >>= 24;
//placement and value.
c->key[i] = c->key[p] + c->key[i];
}
from this i do some more maths and create a hash for the pad.
i use the bites from the key to access whatever element it happends to be pointing to and xor it with some stuff
one of the values i xor it with gets replaced by whatever (g^d) ^ (e^f) happens to be at the time.
Code:
//compute the pad
j = 0;
for( i = 0; i < 1024; i++){
p = c->key[j];
//load key bits
g = p & 0x00FF; p >>= 8;
f = p & 0x00FF; p >>= 8;
e = p & 0x00FF; p >>= 8;
d = p & 0x00FF;
c->pad[i] = c->pad[i] ^ (d + (e^f)); //basic xor w/ addition
c->pad[g] = c->pad[d] ^ (c->pad[e] + c->pad[f]);//basic xor w/ addition using pad[f]
c->pad[f] = (g^d) ^ (e^f); //destroying pad[f]
//please correct me if im wrong but this is basicly a one way hash.
//i see no way to recover the data at pad[e]. without that then there is no way to decipher?
//and some simple bit shifting.
c->pad[i] = c->pad[i] ^ (c->pad[g] << 4);
c->pad[i] = c->pad[i] ^ (c->pad[d] >> 4);
j++;
if (j >= 256)
j = 0;
}
}
the way i figure every 1 or 0 in the key has a chance to affect every other 1/0 in the hash
at the moment the max key size is 256.
source posted with this.
i looking for ways to take the c->key and get the user key from it
or any way to get the origional text.
above is just to setup the pad.
to encript data this is what i've come up with
Code:
void xorp::xor(codeblock* c, char* data, int len){
int p = 0, k = 0;
for( int N = 0; N < 16; N++){
for( int d = 0; d < len; d++){
data[d] = data[d] ^ c->pad[p];
data[d] = data[d] ^ c->key[k];
//cycle through the pad.
p++;
if (p >= 1024)
p = 0;
//cycle through the key.
k++;
if (k >= 256)
k = 0;
k = k ^ (c->pad[p] >> k%24) ;//alter k based on data at pad[p]
}
}
}
simple. the data is xor'ed with the pad. then the key hash
k will be changing alot through the process.
by shifting k by k%24 i will shift all the bites off and have nothing... ERROR ERROR.. i'll fix this later.
anyway by shifting k a few bites and xor'ng it with pad[p] it should prevent and data from being xored with the same 2 things twice.
add on top of that , that this process will be repeated 16 times. making the chances of this very low and shouldn't weaken the cipher any.
any good links are welcome.