Memory out of range C++
<p>I am implementing a code for DES. It takes in 8 bytes of data and returns out 8 Bytes of encoded data. Problem occurs when I try to send in a file which has a size exceeding 10 MB,
the stack memory goes out of range. I am freeing up the allocated memory wherever I can but still the error persists.
Here is my code for the same.</p>

<pre><code>        // DES.cpp : Defines the entry point for the console application.
//
#include&lt;iostream&gt;
#include "stdafx.h"
#include "des.h"
using namespace std;

//loads of const array declarations here
    des::des(const char Key[17]){
        // constructor work
    }

    void des::tokey_56(){
        //works on the keys and converts it to 56 bits.
        tokey_48(); //called to convert to 48 bit keys.
    }

    void leftshift(int a[],int shift){
        //leftshifts a by shif number of bits
    }



    void des::tokey_48(){
        /* */
            //makes 16 subkeys of 48bits each.
    }
    //This function calculates permutation using the const arrays decalared above.
    Byte* des::permute(Byte bytes[],const int permutatn[],int permlen,int bytelen){
        Byte *newbytes=new Byte[permlen/8];
        //init
        for(int i=0;i&lt;permlen/8;i++)
            newbytes[i]=0;
        //initclose
        /*for(int i=0;i&lt;bytelen;i++){
        printf("%d - ",bytes[i]);
        }*/
        for(int i=0;i&lt;permlen;i++){
            int temp=permutatn[i];
            int index1=(permutatn[i]-1)/8;
            int index2=(permutatn[i]-1)%8;
            int tempvar=bytes[index1]&amp;masks[index2];
            int tempvar_1;
            tempvar_1=(tempvar&gt;0)?masks[i%8]:0;
            newbytes[i/8]= newbytes[i/8] | tempvar_1;
            /*if(i==13){
            printf(" %d-%d ",bytes[index1],newbytes[i/8]);
            }*/
        }

        /*for(int i=0;i&lt;permlen/8;i++){
        printf("%d - ",newbytes[i]);
        }*/
        return newbytes;
    }


    void des::create_sub_array(Byte array[], Byte subarray[],int start,int end){
        // creates 2 subarrays from start to end
    }

    void des::swap(Byte a[],Byte b[]){
        // Swaps array a and b
    }

    //This is the main DES function (Key,Right)
    Byte* des::function_des(Byte right[],Byte k[]){
        Byte *right_p=new Byte[6];
        Byte *B=new Byte[8];
        right_p=permute(right,E,48,4);
        for(int i=0;i&lt;6;i++){
            right_p[i]=right_p[i]^k[i];
            //printf(" %d ",right_p[i]);
        }

        B[0]=(right_p[0]&amp;0xFC)&gt;&gt;2;
        B[1]=( ((right_p[0]&amp;0x3 )&lt;&lt;4)|0x0F ) &amp; ( ((right_p[1]&amp;0xF0)&gt;&gt;4)|0xF0 );  
        B[2]=( ((right_p[1]&amp;0x0F)&lt;&lt;2)|0x03 ) &amp; ( ((right_p[2]&amp;0xC0)&gt;&gt;6)|0xFC );
        B[3]=(right_p[2]&amp;0x3F);
        B[4]=(right_p[3]&amp;0xFC)&gt;&gt;2;
        B[5]=( ((right_p[3]&amp;0x3 )&lt;&lt;4)|0x0F ) &amp; ( ((right_p[4]&amp;0xF0)&gt;&gt;4)|0xF0 );  
        B[6]=( ((right_p[4]&amp;0x0F)&lt;&lt;2)|0x03 ) &amp; ( ((right_p[5]&amp;0xC0)&gt;&gt;6)|0xFC );
        B[7]= (right_p[5]&amp;0x3F);

        for(int i=0;i&lt;8;i++){
            int row=( ((B[i]&amp;0x20)&gt;&gt;4)|0x01) &amp; ( (B[i]&amp;0x01)|0x3E);
            int column= (B[i]&amp;0x1E)&gt;&gt;1;
            //using SBoxes
            switch(i){
            case 0: B[0]=S1[row][column];
                break;
            case 1: B[1]=S2[row][column];
                break;
            case 2: B[2]=S3[row][column];
                break;
            case 3: B[3]=S4[row][column];
                break;
            case 4: B[4]=S5[row][column];
                break;
            case 5: B[5]=S6[row][column];
                break;
            case 6: B[6]=S7[row][column];
                break;
            case 7: B[7]=S8[row][column];
                break;
            }
        }
        for(int i=0,j=0; i&lt;4; i++,j+=2){
            B[i]=(B[j]&lt;&lt;4)|(B[j+1]);
        }
        B=permute(B,P,32,4);
        delete[] right_p;
        return B;
    }

    void des::XOR(Byte a[],Byte b[],int len){
        //XOR Function bit by bit.
    }

   //This Function is called from outside the class DES with a 8 byte packet
    Byte* des::encode(Byte bytes[8]){
        Byte *encoded=new Byte[8];
        tokey_56();
        bytes=permute(bytes,IP,64,8);
        Byte left[4],right[4];
        create_sub_array(bytes,left,0,4);
        create_sub_array(bytes,right,4,8);
        //printf("\n\n");
        for(int i=0;i&lt;16;i++){
            Byte *newright=new Byte[4];
            newright=function_des(right,key48[i]);
            XOR(left,newright,4);
            swap(left,right);
            delete[] newright;
        }
        swap(left,right);
        for(int i=0;i&lt;4;i++){
            encoded[i]=left[i];
            encoded[i+4]=right[i];
        }
        encoded=permute(encoded,IPi,64,8);

        //print final coded message
        /*(for(int i=0;i&lt;8;i++){
            printf("%2X",encoded[i]);
        }*/
        return encoded;
    }

    Byte* des::decode(Byte bytes[8]){
        Byte *decoded=new Byte[8];
        tokey_56();
        bytes=permute(bytes,IP,64,8);
        Byte left[4],right[4];
        create_sub_array(bytes,left,0,4);
        create_sub_array(bytes,right,4,8);
        //printf("\n\n");
        for(int i=0;i&lt;16;i++){
            Byte *newright=new Byte[4];
            newright=function_des(right,key48[15-i]);
            XOR(left,newright,4);
            swap(left,right);
            delete[] newright;
        }
        swap(left,right);
        for(int i=0;i&lt;4;i++){
            decoded[i]=left[i];
            decoded[i+4]=right[i];
        }
        decoded=permute(decoded,IPi,64,8);

        /*for(int i=0;i&lt;8;i++){
            printf("%2X",decoded[i]);
        }*/
        return decoded;
    }
</code></pre>

<p>The Header file for the class DES is declared below.</p>

<pre><code>#pragma once
#include&lt;ctype.h&gt;
#include&lt;string.h&gt;
#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
#include"stdafx.h"
using namespace std;

typedef unsigned char Byte;

class des
{
private:
    static const int PC_1[56];
    static const int PC_2[];
    static const int IP[];
    static const int E[];
    static const int S1[4][16];
    static const int S2[4][16];
    static const int S3[4][16];
    static const int S4[4][16];
    static const int S5[4][16];
    static const int S6[4][16];
    static const int S7[4][16];
    static const int S8[4][16];
    static const int P[];
    static const int IPi[];
    static const char binary[16][5];
    static const Byte masks[8];
    //static const Byte masks_1[8];
    char key[16][5];
    int key_56[56];
    //int key_48[16][48];
    Byte key48[16][6];
public:

    char toBinary();
    des(const char Key[17]);
    void tokey_56();
    void tokey_48();
    Byte* encode(Byte bytes[]);
    Byte* des::decode(Byte bytes[8]);
    Byte* permute(Byte byte[],const int permutatn[],int permlen,int bytelen);
    void create_sub_array(Byte array[],Byte subarray[],int start,int end);
    void swap(Byte a[],Byte b[]);
    void XOR(Byte a[],Byte b[],int len);
    Byte* function_des(Byte right[],Byte k[]);
    ~des(void){}
};
</code></pre>

<p>Id appreciate some help if someone tells me how to effectively handle the memory given to me.</p>
