Code:
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
int main()
{
scramble();
return 0;
}
void scramble()
{
char sInput[8192];
char sOutput[1024];
char sOutput2[4096];
char sOutput3[4096];
int iLoopTest1;
int iLoopTest2;
char s64bitenc[8192];
char sixbit[6];
char sixbit2[6];
char key[100];
const char sAlphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\0";
int iRotate = 0;
int iLength = 0;
int iBuffer = 0;
int i = 0, x = 0, y = 0, z = 0;
cout << "Put anything you want to encrypt in the file encryption.txt\n";
infile.open("encryption.txt",ios::in);
strcpy(sInput,"\0");
while (!infile.eof())
{
infile.getline(sInput, 8192, '\0'); // read up to the null terminator OR 8192 chars;
//infile >> sBuffer;
//strcat(sInput,sBuffer);
}
infile.close();
cout << endl << sInput << endl << endl;
//code goes here
strcpy(sOutput3,sInput); //this is so you don't need the whole code
iLength = strlen(sOutput3);
i = x = y = z = 0;
strcpy(sOutput3,"0100100001100101011011000110110001101111");
iLength = strlen(sOutput3);
strcpy(s64bitenc,"\0"); //remove leading garbage characters
// for (z=0; z <= iLength/(134/6)+1; z++)
for (z=0; z <= iLength; z++)
{
//for (i=0; i <= 6; x=x+6, i++, y++)
for (i=0; i <= 6; x=x+6, i++, y++)
{
//cout << char( bin_dec(binnum) ) << endl;
sixbit[0] = sOutput3[0+x];
sixbit[1] = sOutput3[1+x];
sixbit[2] = sOutput3[2+x];
sixbit[3] = sOutput3[3+x];
sixbit[4] = sOutput3[4+x];
sixbit[5] = sOutput3[5+x];
sixbit[6] = '\0';
strcpy(sixbit2,sixbit);
// s64bitenc[y] = char( bin_dec2(sixbit,sixbit2) );
iLoopTest1 = bin_dec2(sixbit,sixbit2);
if (iLoopTest1 != iLoopTest2)
{
strcat(s64bitenc,itoa(bin_dec2(sixbit,sixbit2),sixbit2,10));
strcat(s64bitenc," ");
iLoopTest2 = iLoopTest1;
iLoopTest1 = -5;
}
else
{
break;
break;
}
}
}
s64bitenc[y] = '\0'; //remove trailing garbage characters
cout << s64bitenc << endl;
outfile.open("encryption.txt",ios::out);
outfile << s64bitenc;
outfile.close();
// 1 2 3 4 5
// 1 3 5 2 4
} //end of encrypt function
int bin_dec2(char sBinvalue[6],char sBinvalue2[6])
{
long unsigned int iDecNum = 0;
char sBinChar[8];
sBinChar[0] = '0';
sBinChar[1] = '0';
sBinChar[2] = sBinvalue[0];
sBinChar[3] = sBinvalue[1];
sBinChar[4] = sBinvalue[2];
sBinChar[5] = sBinvalue[3];
sBinChar[6] = sBinvalue[4];
sBinChar[7] = sBinvalue[5];
sBinChar[8] = '\0';
// itoa(iBinvalue,sBinvalue,8);
_strrev(sBinChar);
if (sBinChar[0]=='1')
{ iDecNum = iDecNum + 1; }
if (sBinChar[1]=='1')
{ iDecNum = iDecNum + 2; }
if (sBinChar[2]=='1')
{ iDecNum = iDecNum + 4; }
if (sBinChar[3]=='1')
{ iDecNum = iDecNum + 8; }
if (sBinChar[4]=='1')
{ iDecNum = iDecNum + 16; }
if (sBinChar[5]=='1')
{ iDecNum = iDecNum + 32; }
if (sBinChar[6]=='1')
{ iDecNum = iDecNum + 64; }
if (sBinChar[7]=='1')
{ iDecNum = iDecNum + 128; }
if (sBinChar[8]=='1')
{ iDecNum = iDecNum + 256; }
//cout << iDecNum << endl; //cout the binary number in decimal
return iDecNum; //return the value from the function
}