Загрузка...

Неразрешённый внешний элемент

Тема в разделе C/C++ создана пользователем didiwot 6 окт 2019. 79 просмотров

Загрузка...
  1. didiwot
    didiwot Автор темы 6 окт 2019 0 21 сен 2019
    https://pastebin.com/tjRGPNkq

    #include <ctype.h>
    #include <vector>
    #include <iostream>
    #include <iterator>
    #include <string>
    using namespace std;
    char arr_en[5][5];
    char arr_ru[4][8];

    int request() {
    setlocale(LC_ALL, "Russian");
    string req;
    cout << "какой язык вы выбираете? \n";
    cin >> req;

    if (req == "ru") int main_ru();
    if (req == "en") int main_en();
    else {
    cout << "Не могу иденфицировать выбранный язык";
    }
    return 0;
    }


    int has_duplication_en(char letter) {
    int i, j;
    int size = sizeof(arr_en) / sizeof(arr_en[0]);
    int result = 0;
    for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
    result = (int)letter ^ (int)arr_en[j];
    if (result == 0) return 1;
    }
    }
    return 0;
    }


    int main_en() {
    setlocale(LC_ALL, "Engish");
    int i, j;
    char letters[] = { 'K', 'E', 'Y', 'W', 'O', 'R', 'D', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I' ,'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
    char key[] = { 'K', 'E', 'Y', 'W', 'O', 'R', 'D' };

    vector<char> plain;
    vector<char> cipher_text;
    char c;
    char pre_char;
    pre_char = ' ';
    printf("Enter plain text to encrypt: \n");
    while (c = getchar()) {
    if (c == '\n' || c == '\0') break;
    c = toupper(c);
    if (c != ' ') { // we do not consider spaces
    if (c == 'J') c = 'I';
    if (pre_char == c) {
    plain.push_back('X');
    plain.push_back(c);
    }
    else {
    plain.push_back(c);
    }
    pre_char = c;
    }
    }
    // if length of key array is odd, we add 'X' to the end of key
    if (plain.size() % 2 == 1) {
    plain.push_back('X');
    }

    // filling array with key and letters of alphabet
    int m = 0;
    for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
    while (has_duplication_en(letters[m])) {
    m++;
    }
    arr_en[j] = letters[m];
    }
    }

    // encrytion
    int n = 0;
    int first_i, first_j, second_i, second_j;
    while (n < plain.size()) {
    for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
    if (arr_en[j] == plain.at(n)) {
    first_i = i;
    first_j = j;
    }
    if (arr_en[j] == plain.at(n + 1)) {
    second_i = i;
    second_j = j;
    }
    }
    }
    // if both two letters are in the same row
    if (first_i == second_i) {
    cipher_text.push_back(arr_en[first_i][(first_j + 1) % 5]);
    cipher_text.push_back(arr_en[second_i][(second_j + 1) % 5]);
    }

    // if both two letters are in the same column
    else if (first_j == second_j) {
    cipher_text.push_back(arr_en[(first_i + 1) % 5][first_j]);
    cipher_text.push_back(arr_en[(second_i + 1) % 5][second_j]);
    }
    // otherwise we consider the rectangle that they form
    else {
    cipher_text.push_back(arr_en[first_i][second_j]);
    cipher_text.push_back(arr_en[second_i][first_j]);
    }
    n += 2;
    }


    // result : ecnrypted message
    printf("Encrypted message: \n");
    std::copy(cipher_text.begin(), cipher_text.end(), std::ostream_iterator<char>(std::cout, " "));
    printf("\n");



    // demonstration
    printf("Playcipher Matrix: \n");
    for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
    printf("%c ", arr_en[j]);
    }
    printf("\n");
    }
    return 0;
    }


    int has_duplication_ru(char letter) {
    int i, j;
    int size = sizeof(arr_ru) / sizeof(arr_ru[0]);
    int result = 0;
    for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
    result = (int)letter ^ (int)arr_ru[i][j];
    if (result == 0) return 1;
    }
    }
    return 0;
    }


    int main_ru() {
    setlocale(LC_ALL, "Russian");
    int i, j;
    char arr_ru[4][8];
    char letters[] = { 'К', 'Ю', 'Ч', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л' ,'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Щ', 'Ъ', 'Ы', 'Ь','Э','Ю','Я' };
    char key[] = { 'К', 'Л', 'Ю', 'Ч' };

    vector<char> plain;
    vector<char> cipher_text;
    char c;
    char pre_char;
    pre_char = ' ';
    printf("Введите текст, который надо закодировать: \n");
    while (c = getchar()) {
    if (c == '\n' || c == '\0') break;
    c = toupper(c);
    if (c != ' ') { // we do not consider spaces
    if (c == 'Ё') c = 'Е';
    if (pre_char == c) {
    plain.push_back('Х');
    plain.push_back(c);
    }
    else {
    plain.push_back(c);
    }
    pre_char = c;
    }
    }
    // if length of key array is odd, we add 'X' to the end of key
    if (plain.size() % 2 == 1) {
    plain.push_back('Х');
    }

    // filling array with key and letters of alphabet
    int m = 0;
    for (i = 0; i < 4; i++) {
    for (j = 0; j < 8; j++) {
    while (has_duplication_ru(letters[m])) {
    m++;
    }
    arr_ru[i][j] = letters[m];
    }
    }

    // encrytion
    int n = 0;
    int first_i, first_j, second_i, second_j;
    while (n < plain.size()) {
    for (i = 0; i < 4; i++) {
    for (j = 0; j < 8; j++) {
    if (arr_ru[i][j] == plain.at(n)) {
    first_i = i;
    first_j = j;
    }
    if (arr_ru[i][j] == plain.at(n + 1)) {
    second_i = i;
    second_j = j;
    }
    }
    }
    // if both two letters are in the same row
    if (first_i == second_i) {
    cipher_text.push_back(arr_ru[first_i][(first_j + 1) % 4]);
    cipher_text.push_back(arr_ru[second_i][(second_j + 1) % 8]);
    }

    // if both two letters are in the same column
    else if (first_j == second_j) {
    cipher_text.push_back(arr_ru[(first_i + 1) % 4][first_j]);
    cipher_text.push_back(arr_ru[(second_i + 1) % 8][second_j]);
    }
    // otherwise we consider the rectangle that they form
    else {
    cipher_text.push_back(arr_ru[first_i][second_j]);
    cipher_text.push_back(arr_ru[second_i][first_j]);
    }
    n += 2;
    }


    // result : ecnrypted message
    printf("Зашифрованное сообщение: \n");
    std::copy(cipher_text.begin(), cipher_text.end(), std::ostream_iterator<char>(std::cout, " "));
    printf("\n");



    // demonstration
    printf("Матрица Плейфера: \n");
    for (i = 0; i < 4; i++) {
    for (j = 0; j < 8; j++) {
    printf("%c ", arr_ru[i][j]);
    }
    printf("\n");
    }
    return 0;
    }[/i][/i][/i][/i][/i]
     
Top