Re: There are lots of things that can be done to increase the complexity of hidden data



On Sep 8, 4:43 pm, hayes...@xxxxxxxxx wrote:
A little while back I posted on here about bitswapinghttp://groups.google..com/group/sci.crypt/browse_thread/thread/7904308...

I thought I would follow that up with general code that can be used
for a variety of things.

Such as shuffling or mixing which is great if you want to make a card
game.

void byteshuffle(unsigned char *list,unsigned char *password, unsigned
int filesize)
{
    unsigned int length=0,pwlength=0;
    //while(list[length]){length++;}
    length=filesize;
    while(password[pwlength]){pwlength++;}
    unsigned int T=0,i=0;
    unsigned char Tbyte[4];
    for (unsigned int count=0;count<length-3;count++)
    {
        T=password[i]%3;
        //cout<<"i:"<<(int)i<<" ";
        i++;
        if(i>pwlength-1){i=0;}
        //cout<<"T:"<<T<<" ";
        if(T==0)
        {
                Tbyte[0]=list[count];Tbyte[1]=list[count
+1];Tbyte[2]=list[count+2];Tbyte[3]=list[count+3];
                list[count]=Tbyte[3];list[count+1]=Tbyte[2];list[count
+2]=Tbyte[1];list[count+3]=Tbyte[0];
        }
        if(T==1)
        {
                Tbyte[0]=list[count];Tbyte[1]=list[count
+1];Tbyte[2]=list[count+2];Tbyte[3]=list[count+3];
                list[count]=Tbyte[1];list[count+1]=Tbyte[0];list[count
+2]=Tbyte[3];list[count+3]=Tbyte[2];
        }
        if(T==2)
        {
                Tbyte[0]=list[count];Tbyte[1]=list[count
+1];Tbyte[2]=list[count+2];Tbyte[3]=list[count+3];
                list[count]=Tbyte[2];list[count+1]=Tbyte[3];list[count
+2]=Tbyte[0];list[count+3]=Tbyte[1];
        }

    }
    //cout<<"\n";

}

/
*******************************************************************************************************************************

*******************************************************************************************************************************/
Then there is the ever important byte shift if you want to create say
something that worked using data going around and around. Such as
program for keeping track of packages on a carousel conveyor.

void ByteShift(unsigned char *A, bool LR, unsigned distance)
{
     unsigned int length=0;
     while(A[length]){length++;}
     if (LR==0)
     {
         char TByte;
         for (unsigned int count=0;count<distance;count++)
         {
             unsigned int index;
             TByte=A[0];
             for (index=0;index<length-1;index++)
             {
                 A[index]=A[index+1];
             }
             A[index]=TByte;
         }
     }
     if (LR==1)
     {
         char TByte;
         for (unsigned int count=0;count<distance;count++)
         {
             unsigned int index=0;
             TByte=A[length-1];
             for (index=length-1;index>0;index--)
             {
                 A[index]=A[index-1];
             }
             A[0]=TByte;
         }
     }}

/
***********************************************************************************************************************************
**********************************************************************************************************************************/
Then bit rotation code that can be used to create large rotating
patterns of bits that are preset.

void BShift(unsigned char *A, bool LR, unsigned int distance,unsigned
int size)
{
     unsigned int length=0;
     bool *BitPointer;
     //while (A[length]){length++;}
     length=size;
     BitPointer= new bool[8*length];
     //copy bits from A to BitPointer list

     //shift bits
     bool Tbit=0;
     if (LR==0)
     {
         for (unsigned int count=0;count<distance;count++)
         {
             unsigned int index=0;
             Tbit=(A[0]>>7)%2;
             for (index=0;index<length-1;index++)
             {
                 //cout<<(int)A[index]<<" "<<(int)A[index+1]<<" ";
                 A[index]=(A[index]<<1);
                 A[index]=A[index]+((A[index+1]>>7)%2);
                 //cout<<(int)A[index]<<" "<<(int)A[index+1]<<"\n";
             }
             A[index]=(A[index]<<1)+Tbit;
         }
     }
     if (LR==1)
     {
         for (unsigned int count=0;count<distance;count++)
         {
             unsigned int index=0;
             Tbit=A[length-1]%2;
             for (index=length-1;index>0;index--)
             {
                 //cout<<(int)A[index]<<" "<<(int)A[index-1]<<" ";
                 A[index]=((A[index]>>1)+((A[index-1]%2)*128));
                 //cout<<(int)A[index]<<" "<<(int)A[index-1]<<"\n";
             }
             A[0]=(A[0]>>1)+(128*Tbit);
         }
     }

}

/
***********************************************************************************************************************************
***********************************************************************************************************************************/
Then you have bit change algorithms that I guess you could use for
reordering bits for different formats

unsigned char BitChange( unsigned char A,unsigned char B)
{
      bool b0=0,b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0;
      b0=A
%2;b1=(A>>1)%2;b2=(A>>2)%2;b3=(A>>3)%2;b4=(A>>4)%2;b5=(A>>5)%2;b6=(A>>6)%2;b7=(A>>7)%2;
      if((B%8)==0)//1
      {
              return (255-A);
      }
      if((B%8)==1)//2
      {
               unsigned char h1,h2,t;
               h2=A%16;
               h1=(A-h2)/16;
               t=(16*h2)+h1;
               return t;

      }
      if((B%8)==2)//3
      {
               unsigned char t=0;
               t=t+b6;
               t=(t<<1)+b7;
               t=(t<<1)+b4;
               t=(t<<1)+b5;
               t=(t<<1)+b2;
               t=(t<<1)+b3;
               t=(t<<1)+b0;
               t=(t<<1)+b1;
               return t;
      }
      if((B%8)==3)//4
      {
               unsigned char t=0;
               t=t+b2;
               t=(t<<1)+b3;
               t=(t<<1)+b0;
               t=(t<<1)+b1;
               t=(t<<1)+b6;
               t=(t<<1)+b7;
               t=(t<<1)+b4;
               t=(t<<1)+b5;
               return t;
      }
      if((B%8)==4)//5
      {
               unsigned char t=0;
               t=t+b3;
               t=(t<<1)+b2;
               t=(t<<1)+b1;
               t=(t<<1)+b0;
               t=(t<<1)+b7;
               t=(t<<1)+b6;
               t=(t<<1)+b5;
               t=(t<<1)+b4;
               return t;
      }
      if((B%8)==5)//6
      {
               unsigned char t=0;
               t=t+b5;
               t=(t<<1)+b4;
               t=(t<<1)+b7;
               t=(t<<1)+b6;
               t=(t<<1)+b1;
               t=(t<<1)+b0;
               t=(t<<1)+b3;
               t=(t<<1)+b2;
               return t;
      }
      if((B%8)==6)//7
      {
               unsigned char t=0;
               t=t+b1;
               t=(t<<1)+b0;
               t=(t<<1)+b3;
               t=(t<<1)+b2;
               t=(t<<1)+b5;
               t=(t<<1)+b4;
               t=(t<<1)+b7;
               t=(t<<1)+b6;
               return t;
      }
      return A;

}

/
***********************************************************************************************************************************
***********************************************************************************************************************************/

Then of course someone can build a set of pseudo random integers based
upon both the password and the data.
However one has to remember the list must be reproducible when trying
to retrieve the data. Since you don't have the original data when
doing something like decryption you may only have things like hash or
length, bit count or what ever added data you may have stored in some
header or attachment.

The issue with Oring in Integers is the file can be various byte
lengths and may not be a full integer length at the end. Not much of
an issue if you read the next section

//Table length could be up to 3 bytes shorter than message
void OrTable(unsigned int *Table, unsigned char *Message, unsigned int
TableLength)
{
     unsigned char *S;
     S=(unsigned char *)Table;
     for (unsigned int count=0;count<TableLength*4;count++)
     {
         Message[count]=Message[count]^S[count];
     }

}

/
***********************************************************************************************************************************
***********************************************************************************************************************************/

Well you could repeat a complex set of process which I only listed a
few above. To give you an idea on what really can be done. The more
times you would repeat such process the more displaced original data
parts become and the more random the data at the end appears to be. It
would require a massive amount of exploration to tie an single bit to
any original byte in the initial file.

So I haven't given a complete method of encryption but I hope I have
given a few ideas and repeated some that people before me have all
made. It is only a matter of combining them in the right order to make
good use of them.

To make a quick point similar functions have been used for many
different things. Which is why I am made the short comments about
alternative uses.
Basically any means of manipulating data can be put to some use in
dealing with cryptography.
These functions or similar ones can be found in many other publicly
available programs and source on the web and have nothing to do with
cryptography.
A good example of duel use is pseudo random number generators using
seeds. They are used in designing terrain algorithms.
When I worked for DOD one of my job functions was programming material
handling PLCs. Which is were a lot of this came in use before then it
was in ladder logic now it is in C but you can also find it in event
programming for things like games and other software. Like I said
nothing new or not already available.

.



Relevant Pages