I have a problem with linking a class-friendly function and its private variables. The training task consists in creating a program that encrypts and decrypts the entered text based on the key with a Vigener cipher. Please help me! (here is link to dropmefiles and archive, where program places. *It's my first question in stackoverflow https://dropmefiles.com/JZFJd here there is code of declaration class with friendly-funcion ("Vigenere_square.h"):
#pragma once
#include <iostream>
#include <string>
#include <fstream>
class Vigenere_square
{
private:
const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
size_t size;
char** array;
public:
Vigenere_square();
~Vigenere_square();
//friend void encode();
//friend void decode();
//friend void output();
friend string encode_string(const string& text, const string& key, const Vigenere_square& vs);
};
and here code of "encode.cpp" file:
#include "encode.h"
using namespace std;
string encode_string(const string& text, const string& key, const Vigenere_square& vs)
{
string text2, key2;
while (key2.length() <= text.length())
{
key2 += key;
}
size_t row, column, k;
for (size_t k = 0; k < text.length(); k++)
{
size_t row = vs.ALPHABET.find(key2[k]);
size_t column = vs.ALPHABET.find(text[k]);
if (row < vs.size && column < vs.size) {
text2 += vs.array[row][column];
}
else {
text2 += text[k];
}
}
return text2;
}
I'm just a student, but I really don't know what I have to learn or understand. There is a very stupid mistake, but I can't find it.
You are missing header inclusion. Instead of
#include "encode.h", use#include "Vigenere_square.h".Friend functions may not be necessity here, just use public member functions.
If you need to expose private members, you can use setter/getter.