C언어 질문있습니다

익명 사용자의 이미지

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char text[100];
 
 
int main()
 
 
 
{
 
	int rail, mode, menu;
 
 
	{
 
		printf("\n =================MENU=================\n");
		printf("\n 1. Encoding // 2. Decoding // 3. Exit\n");
		printf("\n >> Select a mode: ");
		scanf("%d", &mode);
 
		if (mode == 1)
		{
			printf("\n ============ENCODING MODE=============\n");
 
			printf("\n >> Enter the text: ");
			scanf("%s", &text);
 
			printf("\n >> Enter the value of rail: ");
			scanf("%d", &rail);
 
			printf("\n >> Encrypted text: ");
 
			encrypt(rail, text);
		}
 
		else if (mode == 2)
		{
			printf("\n ============DECODING MODE=============\n");
 
			printf("\n >> Enter the text: ");
			scanf("%s", &text);
 
			printf("\n >> Enter the value of rail: ");
			scanf("%d", &rail);
 
			decrypt(rail, text);
		}
 
		else if (mode == 3)
		{
			return 0;
		}
 
		else
			return main();
 
	}
 
	printf("\n\n Return to main menu? (0. No // 1. Yes)");
	printf("\n Your choice: ");
	scanf("%d", &menu);
 
	if (menu == 1)
		return main();
 
	else
		printf("THE END!\n\n");
	return 0;
 
}
 
void encrypt(int rail, char *plain)
{
 
	char railfence[rail][100], buf[2];
	int i;
	int number = 0, increment = 1;
	buf[1] = '\0';
 
	for (i = 0; i<rail; i++)
		railfence[i][0] = '\0';
 
	for (i = 0; i<strlen(plain); i++)
	{
 
		if (number + increment == rail)
			increment = -1;
 
		else if (number + increment == -1)
			increment = 1;
 
		buf[0] = plain[i];
		strcat(railfence[number], buf);
		number += increment;
 
	}
 
	for (i = 0; i<rail; i++)
		printf("%s", railfence[i]);
 
}
 
void decrypt(int rail, char *cipher)
{
	int cipherlength = strlen(cipher);
	int j, counter = 0, number = 0, increment = 1, railfence[rail][100], i, count[100];
 
 
 
	for (i = 0; i<cipherlength; i++)
		count[i] = 0;
 
	for (i = 0; i<cipherlength; i++)
	{
 
		if (number + increment == rail)
			increment = -1;
 
		else if (number + increment == -1)
			increment = 1;
 
		railfence[number][count[number]] = i;
		++count[number];
		number += increment;
 
	}
 
	char buffer[1000];
 
	for (i = 0; i<rail; i++)
		for (j = 0; j<count[i]; j++)
		{
 
			buffer[railfence[i][j]] = cipher[counter];
			++counter;
 
		}
 
	buffer[cipherlength] = '\0';
	printf("\n >> Decrypted text: %s\n", buffer);
 
}

gcc론 잘됩니다. vs론 오류나구요 도와주세여 ㅠㅠㅠ

echo_의 이미지

제가 사용중인 vc++2010버전은 다음과 같이 추가햐여야 합니다.
/*include 아래다 써주세요.*/
/*함수의 원형을 선언하는것*/
void encrypt(int rail, char *plain);
void decrypt(int rail, char *cipher);

vc++2010에선
char railfence[rail][100]
상수의 값이 아닌 변수로 배열을 선언 할 수 없습니다.

ASD의 이미지

void decrypt(int rail, char *cipher) 함수에서

char buffer[1000];

선언을 상단부로 옮겨주세요.

shint의 이미지


각 함수에 인자값. 리턴값. 오류값'을 출력해서 확인해 봅니다.

자세한건 컴파일과 실행 잘되는. 책 예제소스 참고 해보세요. ㅇ_ㅇ;;
http://www.codeproject.com 코드 프로젝트 추천
http://book.naver.com 네이버 책
http://www.kangcom.com/ 강컴 닷컴
한빛 미디어. 영풍 문고. 교보 문고 등등...

http://olc.kr/main/index.jsp OLC Center 무료 강의

학원. 직업학교. C 프로그래밍 책.

Rail Fence Cipher Program in C and C++[Encryption & Decryption]
https://www.thecrazyprogrammer.com/2017/09/rail-fence-cipher-program-in-c.html

http://codepad.org/VuSECBmA

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
char text[100];
 
#define DF_RAIL 100
 
void encrypt(int rail, char *plain);
void decrypt(int rail, char *cipher);
 
void encryptMsg(char msg[], int key);
void decryptMsg(char enMsg[], int key);
 
 
int main()
{
 
	int rail = 0;
        int mode = 0;
        int menu = 0;
 
        rail = 10;
        strcpy(text, "test");
 
	encrypt(rail, text);
	decrypt(rail, text);
 
        encryptMsg(text, rail);
        decryptMsg(text, rail);
 
        return 0;
 
	{
 
		printf("\n =================MENU=================\n");
		printf("\n 1. Encoding // 2. Decoding // 3. Exit\n");
		printf("\n >> Select a mode: ");
//		scanf("%d", &mode);
 
		if (mode == 1)
		{
			printf("\n ============ENCODING MODE=============\n");
 
			printf("\n >> Enter the text: ");
//			scanf("%s", &text);
 
			printf("\n >> Enter the value of rail: ");
//			scanf("%d", &rail);
 
			printf("\n >> Encrypted text: ");
 
			encrypt(rail, text);
		}
 
		else if (mode == 2)
		{
			printf("\n ============DECODING MODE=============\n");
 
			printf("\n >> Enter the text: ");
//			scanf("%s", &text);
 
			printf("\n >> Enter the value of rail: ");
//			scanf("%d", &rail);
 
			decrypt(rail, text);
		}
 
		else if (mode == 3)
		{
			return 0;
		}
 
		else
			return 1; //main();
 
	}
 
	printf("\n\n Return to main menu? (0. No // 1. Yes)");
	printf("\n Your choice: ");
//	scanf("%d", &menu);
 
	if (menu == 1)
		return 1; //main();
 
	else
		printf("THE END!\n\n");
	return 0;
 
}
 
void encryptMsg(char msg[], int key)
{
    int msgLen = strlen(msg), i, j, k = -1, row = 0, col = 0;
    char railMatrix[DF_RAIL][100];
 
    for(i = 0; i < key; ++i)
        for(j = 0; j < msgLen; ++j)
            railMatrix[i][j] = '\n';
 
    for(i = 0; i < msgLen; ++i){
        railMatrix[row][col++] = msg[i];
 
        if(row == 0 || row == key-1)
            k= k * (-1);
 
        row = row + k;
    }
 
    cout<<"\nEncrypted Message: ";
 
    for(i = 0; i < key; ++i)
        for(j = 0; j < msgLen; ++j)
            if(railMatrix[i][j] != '\n')
                cout<<railMatrix[i][j];
}
 
 
void encrypt(int rail, char *plain)
{
 
	char railfence[DF_RAIL ][100], buf[2];
	int i;
        int max;
	int number = 0, increment = 1;
	buf[1] = '\0';
 
	for (i = 0; i<rail; i++)
		railfence[i][0] = '\0';
 
        max = strlen(plain);
	for (i = 0; i<max; i++)
	{
 
		if (number + increment == rail)
			increment = -1;
 
		else if (number + increment == -1)
			increment = 1;
 
		buf[0] = plain[i];
		strcat(railfence[number], buf);
		number += increment;
 
	}
 
	for (i = 0; i<rail; i++)
		printf("%s", railfence[i]);
 
}
 
void decryptMsg(char enMsg[], int key)
{
    int msgLen = strlen(enMsg), i, j, k = -1, row = 0, col = 0, m = 0;
    char railMatrix[DF_RAIL][100];
 
    for(i = 0; i < key; ++i)
        for(j = 0; j < msgLen; ++j)
            railMatrix[i][j] = '\n';
 
    for(i = 0; i < msgLen; ++i){
        railMatrix[row][col++] = '*';
 
        if(row == 0 || row == key-1)
            k= k * (-1);
 
        row = row + k;
    }
 
    for(i = 0; i < key; ++i)
        for(j = 0; j < msgLen; ++j)
            if(railMatrix[i][j] == '*')
                railMatrix[i][j] = enMsg[m++];
 
    row = col = 0;
    k = -1;
 
    cout<<"\nDecrypted Message: ";
 
    for(i = 0; i < msgLen; ++i){
        cout<<railMatrix[row][col++];
 
        if(row == 0 || row == key-1)
            k= k * (-1);
 
        row = row + k;
    }
}
 
 
void decrypt(int rail, char *cipher)
{
	int cipherlength = strlen(cipher);
	int j;
	int counter = 0;
	int number = 0;
	int increment = 1;
	int railfence[DF_RAIL][100];
	int i;
	int count[100];
 
 
 
	for (i = 0; i<cipherlength; i++)
		count[i] = 0;
 
	for (i = 0; i<cipherlength; i++)
	{
 
		if (number + increment == rail)
			increment = -1;
 
		else if (number + increment == -1)
			increment = 1;
 
		railfence[number][count[number]] = i;
		++count[number];
		number += increment;
 
	}
 
	char buffer[1000];
        memset(buffer, 0x00, 1000);
 
	for (i = 0; i<rail; i++)
		for (j = 0; j<count[i]; j++)
		{
 
			buffer[railfence[i][j]] = cipher[counter];
			++counter;
 
		}
 
	buffer[cipherlength] = '\0';
	printf("\n >> Decrypted text: %s\n", buffer);
 
}

JavaScript Encryption and Decryption
http://blog.naver.com/usofine/40010559385

JavaScrypt Encryption and Decryption
http://www.fourmilab.ch/javascrypt/javascrypt.html

[VC++ Registry] Registry Value Encryption and Decryption
http://chomorungma.blog.me/60019561462

openssl rsa encryption/decryption porting python to ruby
http://gin1231.me/22

상관 없지만.
CUDA 상수 메모리 사용 관련 질문
http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=926321&ref=926321

SQL 함수 만들기
http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=38&MAEULNo=16&no=75063&ref=75057

상수(const)의 정의가 궁금합니다...
https://kldp.org/node/144933

기능과 원리로 배우는 프로그래밍 - 데이터 - 포인터 / 이중배열
https://drive.google.com/drive/folders/0B_788O9A9oekR1NzVWZ0b0p4YTg?usp=sharing

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.