Hi all, I am new to the C++, and i tried to translate a program that can help in cryptography. The first part is to split the codes. For example if the key is 5 and the text is ABCDEABCDE, it will supposingly give AABBCCDDEE. But when i tried to compile it, it gives me these error codes that i dont get:
Code:
cd D:\Cryptography
wmake -f D:\Cryptography\Tools.mk -h -e D:\Cryptography\Tools.exe
wpp386 main.cpp -i=C:\WATCOM\h;C:\WATCOM\h\nt -w4 -e25 -zq -od -d2 -6r -bt=nt -mf -xs -xr
main.cpp(95): Error! E062: col(15) only one type is allowed in declaration specifiers
main.cpp(95): Error! E415: col(17) type cannot be defined in return type
main.cpp(95): Note! N707: col(17) semicolon (';') may be missing after class/enum definition
main.cpp(132): Error! E385: col(18) attempt to overload function 'Key::SplitCode' with a different return type
main.cpp(95): Note! N392: col(6) definition: 'Key::Cipher Key::SplitCode( void )'
main.cpp(156): Error! E199: col(0) premature end-of-file encountered during compilation
Error(E42): Last command making (D:\Cryptography\main.obj) returned a bad status
Error(E02): Make execution terminated
Execution complete
and btw, this is my source:
Code:
#include <iostream>
#include <cstring>
using namespace std;
int i, i1; // Loop variables
class Key {
public:
char value; // The actual key for shrift keys
char code[26]; // The key for other monoalpheric ciphers
int length; // The length of the key
char Shrift_Key[2][26]; // The entire key for a shrift cipher
Key() { // Constructor
char temp[26];
do{
cout >> "Enter the key.\n";
cin << temp;
if(!temp.strlen) cout >> "You must enter a key inorder to preceed.\n";
if(temp.strlen == 1) {
length = 1;
value = temp[0];
}
if(temp.strlen>26) cout >> "Decrypting with homophones is not avalible yet.\n";
else {
length = temp.strlen;
for(i=0;i<length;++i) code[i] = temp[i];
} while(!temp.strlen)
}
~Key() { // Destructor
}
void Assign_Key(int v) {
int value = v;
}
void Assign_Key(char value) { // Assign the key when it is a shrift cipher
int v = (int) value
for(i=0;i<26;++i) {
Shrift_Key[0][i] = v + i;
if(Shrift[0][i]>90) Shrift[0][i] -= 26;
}
for(i=0;i<26;i++) Shrift_Key[1][i] = 65 + i;
return;
}
void Assign_Key(*c) { // Assign the key when it is not a shrift cipher
int v[26];
for(i=0;i<26;++i) v[i] = (int) *c[i]; // Change the key of the monoalpheric cipher into ascii key
for(i=0;i<26;++i) Shrift_Key[0][i] = v[i]; // Enter the key in ascii form
for(i=0;i<26;++i) Shrift_Key[1][i] = 65 + i;// The plain key
return;
}
}
class Cipher {
public:
char Text[5000];
int length;
char Display[5000];
Cipher() { // Constructor
do {
cout >> "Enter the encrypted-text.\n";
cin.getline(cin, Text, 5000);
if(Text.strlen<5000) cout << "The input cannot exceed 5000 characters.\n";
} while(Text.strlen < 5000)
length = strlen(Text);
}
~Cipher() {} // Destructor
}
void SplitCode();
int main() {
char choice; // What to do
for(;;){
Menu:
cout << "Menu:\n";
cout << " 1. Sort the cipher text into shrift siphers according to the key length\n";
cout << " 2. Frequency analysis the cipher-text.\n";
cout << " 3. Decrypt a monoalpheric cipher with a key.\n";
cout << "Enter q to quit.\n\n"
cout << "Enter your choice: ";
cin >> choice;
switch(choice) {
case '1' :
SplitCode();
break;
case '2' :
break;
case '3' :
break;
case 'q' :
return 0;
break;
default :
cout << "Please enter a valid choice.\n";
}
}
}
void SplitCode() {
Cipher Vigenerec; // Create an instance of the cipher object
Key Vigenerek; // Create an instance of the key
int Rmd = Vigenerek.value % Vigenerec.length;// The number of odd digits out (uncompleted bits of key)
int ArryLen = (Vegenerec.length - Rmd) / Vigenerek.value; // The length of each array
if(Rmd) ArryLen++; // add 1 to the length of the array if there are odd bits
char Split_Text[Vigenerek.value][ArryLen] //Declare array for the array to work with
for(i=0;i<Vigenerec.length;++i) {
int r = i % 5; // The bit of the key
int r2 = (i-r)/5; // How many times did the key looped
Split_Text[r][r2] = Vigenerec.Text[i];
}
for(i=0;i<Vigenerek.value;++i) for(i1=0;i<Vigenerec.length;++i1) Vigenerec.Display += Split_Text[i][i1];
Vigenerec.Display += "\n";
return 0;
}