• Познакомьтесь с пентестом веб-приложений на практике в нашем новом бесплатном курсе

    «Анализ защищенности веб-приложений»

    🔥 Записаться бесплатно!

  • CTF с учебными материалами Codeby Games

    Обучение кибербезопасности в игровой форме. Более 200 заданий по Active Directory, OSINT, PWN, Веб, Стеганографии, Реверс-инжинирингу, Форензике и Криптографии. Школа CTF с бесплатными курсами по всем категориям.

Помогите пожалуйста перевести код C++ в C

Yarkdov

New member
01.03.2023
1
0
BIT
0
#include <iostream>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

#define N 5
#define M 5
char alphabet[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

void Delsymb(char symb, char c[])
{
for (char* a = c, *b = alphabet; *a; ++a, ++b) {
while (*a == symb) ++a;
*b = *a;
}

}

void Createtable(char t[][N], string& keyword)
{
// Составляем таблицу
int cnt = 0;
string::iterator it = keyword.begin();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
{
if (it != keyword.end())
{
t[j] = (*it);
Delsymb(*it, alphabet);
++it;
}
else
{
t[j] = alphabet[cnt];
cnt++;
}
}
cout << endl << "-----Матрица алфавита-----" << endl;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << t[j] << " ";
}
cout << endl;
}
}

void remove_spaces(string& str){
for (int i = 0; i < str.length(); i++) {
if (str == ' ') {
str.erase(i, 1);
i--;
}
}
if (str.length() % 2 != 0)
str.insert(str.length(), "X");

cout << str << endl;
}

void Encode(char t[][N], string& mes){
remove_spaces(mes);

char arr[20][2];
int k = 0;
for (int i = 0; i < mes.length() / 2; i++) {
for (int j = 0; j < 2; j++) {
arr[j] = mes[k];
k++;
}
}

///?????
}


int main() {
setlocale(0, "RUS");
char table[N][M];
string keyword, message;
cout << "Ведите ключевое слово --> ";
cin >> keyword;
Createtable(table, keyword);
cout << "Введите слово/фразу, которое хотите зашифровать --> ";
getline(cin, message);
Encode(table, message);
return 0;
}
 

molokoedov89

New member
18.04.2023
1
0
BIT
0
#include <iostream>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

#define N 5
#define M 5
char alphabet[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

void Delsymb(char symb, char c[])
{
for (char* a = c, *b = alphabet; *a; ++a, ++b) {
while (*a == symb) ++a;
*b = *a;
}

}

void Createtable(char t[][N], string& keyword)
{
// Составляем таблицу
int cnt = 0;
string::iterator it = keyword.begin();
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
{
if (it != keyword.end())
{
t[j] = (*it);
Delsymb(*it, alphabet);
++it;
}
else
{
t[j] = alphabet[cnt];
cnt++;
}
}
cout << endl << "-----Матрица алфавита-----" << endl;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cout << t[j] << " ";
}
cout << endl;
}
}


void remove_spaces(string& str){
for (int i = 0; i < str.length(); i++) {
if (str == ' ') {
str.erase(i, 1);
i--;
}
}
if (str.length() % 2 != 0)
str.insert(str.length(), "X");


cout << str << endl;
}


void Encode(char t[][N], string& mes){
remove_spaces(mes);

char arr[20][2];
int k = 0;
for (int i = 0; i < mes.length() / 2; i++) {
for (int j = 0; j < 2; j++) {
arr[j] = mes[k];
k++;
}
}

///?????
}



int main() {
setlocale(0, "RUS");
char table[N][M];
string keyword, message;
cout << "Ведите ключевое слово --> ";
cin >> keyword;
Createtable(table, keyword);
cout << "Введите слово/фразу, которое хотите зашифровать --> ";
getline(cin, message);
Encode(table, message);
return 0;
}
чтот и я не справился)
 

Lunik

Green Team
14.08.2018
59
35
BIT
77
Что-то подобное может быть не уверен)

C:
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define N 5
#define M 5

void Delsymb(char symb, char c[], int length)
{
    int i, j;
    for (i = 0, j = 0; i < length; ++i) {
        if (c[i] != symb) {
            c[j++] = c[i];
        }
    }
    c[j] = '\0';
}

void CreateTable(char t[][N], char alphabet[], int length, char* keyword, int keywordLength)
{
    int i, j, k;
    int cnt = 0;
    char* it = keyword;

    for (i = 0; i < N; i++) {
        for (j = 0; j < M; j++) {
            if (it != keyword + keywordLength) {
                t[i][j] = *it;
                Delsymb(*it, alphabet, length);
                ++it;
            }
            else {
                t[i][j] = alphabet[cnt];
                cnt++;
            }
        }
    }

    printf("\n-----Матрица алфавита-----\n");
    for (i = 0; i < N; i++) {
        for (j = 0; j < M; j++) {
            printf("%c ", t[i][j]);
        }
        printf("\n");
    }
}

void RemoveSpaces(char* str, int length)
{
    int i;
    for (i = 0; i < length; i++) {
        if (str[i] == ' ') {
            memmove(&str[i], &str[i + 1], length - i);
            i--;
            length--;
        }
    }
    if (length % 2 != 0) {
        str[length] = 'X';
        str[length + 1] = '\0';
    }
}

void Encode(char t[][N], char* mes, int length)
{
    char arr[20][2];
    int k = 0, i, j;

    for (i = 0; i < length / 2; i++) {
        for (j = 0; j < 2; j++) {
            arr[i][j] = mes[k];
            k++;
        }
    }

    // TODO: Implement encoding
}

int main() {
    setbuf(stdout, NULL);
    char table[N][M], alphabet[] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
    char keyword[20], message[100];

    printf("Введите ключевое слово --> ");
    scanf("%s", keyword);

    CreateTable(table, alphabet, 26, keyword, strlen(keyword));

    printf("Введите слово/фразу, которое хотите зашифровать --> ");
    getchar(); // To consume the newline character after the previous input
    fgets(message, 100, stdin);
    RemoveSpaces(message, strlen(message));
    Encode(table, message, strlen(message));

    return 0;
}
 

Metra__15

Member
02.08.2022
5
0
BIT
0
Ты можешь использовать нейронку (ChatGPT) для таких задач. Она довольно качественно переводит код с одного языка на другой)
 
Мы в соцсетях:

Обучение наступательной кибербезопасности в игровой форме. Начать игру!