void vig2_enc()
{
cout << "Vigenere and Line-Trans Encoder." <<
endl << "NOTE: the original file will be OVERWRITE, so backup it yourself!" << endl;
fstream fin, fout;
string strin, strout;
int m, i, n, t, counter = 0, chars[27], en_chars[27];
for (int i = 0; i < 27; i++){
chars[i] = 0;
en_chars[i] = 0;
}
cout << "Input File:";
cin >> strin;
cout << "Temp File:";
cin >> strout;
cout << "m, n, t:";
cin >> m >> n >> t;
int* x = new int[m];
//char key[100], in;
char in;
char *key = new char[n];
make_key(key, n);
cout << "The Key for This Encoding is below:" << endl;
for (i = 0; i < n; i++)
cout << key[i];
for (i = 0; i < m; i++)
x[i] = i;
shuffle(x, m);
//output x
cout << endl << "x[] is as below:" << endl;
for (i = 0; i < m; i++){
cout << x[i] << " ";
}
cout << endl;
//compute frequency of each letter(BEFORE ENCODING)
fin.open(strin.c_str(), ios::in);
while (fin >> in && !fin.eof()){
if (!isalpha(in)) //ignore non-english byte
continue;
counter++;
chars[(in & 0xDF) - 64]++;
}
// fin.flush();
//fin.clear();
//fin.seekg( 0, ios_base::beg );
fin.close();
//fin.clear();
////////////////////////////////////////////////
for (i = 0; i < n; i++)
cout << key[i];
cout << endl;
fin.seekg(0, ios::beg);
fin.open(strin.c_str(), ios::in);
fout.open(strout.c_str(), ios::out);
//vigenere first
_vig_enc(key, n, fin, fout,true);
//fin.clear();
fin.close();
fout.close();
//fin.open(strout.c_str(), ios::in);
//fout.open(strin.c_str(), ios::out);
//line next
line_enc(x, m, fin, fout);
//line_enc(x, m, fout, fin);
//fin.close();
//fout.close();
delete[] x;
delete[] key;
//compute frequency of each encoded letter(AFTER ENCODING)
//fin.open(strin.c_str(), ios::in);
fin.open(strin.c_str(),ios::in);
while (fin >> in && !fin.eof()){
if (!isalpha(in)) //ignore non-english byte
continue;
en_chars[(in & 0xDF) - 64]++;
}
fin.close();
//fin.clear();
////////////////////////////////////////////////////////
print_frequency(counter, chars, en_chars);
delete[] x;
delete[] key;
}
{
cout << "Vigenere and Line-Trans Encoder." <<
endl << "NOTE: the original file will be OVERWRITE, so backup it yourself!" << endl;
fstream fin, fout;
string strin, strout;
int m, i, n, t, counter = 0, chars[27], en_chars[27];
for (int i = 0; i < 27; i++){
chars[i] = 0;
en_chars[i] = 0;
}
cout << "Input File:";
cin >> strin;
cout << "Temp File:";
cin >> strout;
cout << "m, n, t:";
cin >> m >> n >> t;
int* x = new int[m];
//char key[100], in;
char in;
char *key = new char[n];
make_key(key, n);
cout << "The Key for This Encoding is below:" << endl;
for (i = 0; i < n; i++)
cout << key[i];
for (i = 0; i < m; i++)
x[i] = i;
shuffle(x, m);
//output x
cout << endl << "x[] is as below:" << endl;
for (i = 0; i < m; i++){
cout << x[i] << " ";
}
cout << endl;
//compute frequency of each letter(BEFORE ENCODING)
fin.open(strin.c_str(), ios::in);
while (fin >> in && !fin.eof()){
if (!isalpha(in)) //ignore non-english byte
continue;
counter++;
chars[(in & 0xDF) - 64]++;
}
// fin.flush();
//fin.clear();
//fin.seekg( 0, ios_base::beg );
fin.close();
//fin.clear();
////////////////////////////////////////////////
for (i = 0; i < n; i++)
cout << key[i];
cout << endl;
fin.seekg(0, ios::beg);
fin.open(strin.c_str(), ios::in);
fout.open(strout.c_str(), ios::out);
//vigenere first
_vig_enc(key, n, fin, fout,true);
//fin.clear();
fin.close();
fout.close();
//fin.open(strout.c_str(), ios::in);
//fout.open(strin.c_str(), ios::out);
//line next
line_enc(x, m, fin, fout);
//line_enc(x, m, fout, fin);
//fin.close();
//fout.close();
delete[] x;
delete[] key;
//compute frequency of each encoded letter(AFTER ENCODING)
//fin.open(strin.c_str(), ios::in);
fin.open(strin.c_str(),ios::in);
while (fin >> in && !fin.eof()){
if (!isalpha(in)) //ignore non-english byte
continue;
en_chars[(in & 0xDF) - 64]++;
}
fin.close();
//fin.clear();
////////////////////////////////////////////////////////
print_frequency(counter, chars, en_chars);
delete[] x;
delete[] key;
}