게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
C언어: 기본적인 문장 암호화
게시물ID : computer_48840짧은주소 복사하기
작성자 : Clinkz
추천 : 0
조회수 : 708회
댓글수 : 4개
등록시간 : 2012/06/02 23:12:00
영어로 문장을쓰면 그 문장이 암호화되서 나옴 ㅋ 
예를 들어서 "Hello World!" 를 입력하면 "Uryyb Jbeyq!"가 나옴 ㅋ 
지금 씨를 배우고 있는중이라 아직은 이런 기본밖에 할줄 몰르네요 ㅋㅋ avr도 막 입문한 상태라 ㅋㅋ

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>

#define MAX_PHRASE_LENGTH 100

void EncodePhrase(char *original, char *encoded);
char EncodeCharacter(char c);

int main(void)
{
char phrase[MAX_PHRASE_LENGTH];
char encoded[MAX_PHRASE_LENGTH];

printf("Enter phrase to encode: ");
gets(phrase);

EncodePhrase(phrase, encoded);

printf("Encoded: %s\n\n", encoded);

return 0;
}

void EncodePhrase(char *original, char *encoded)
{
char c;
int i = 0;

/* use while loop to read through the original string and store the converted character into encoded array */
while (original[i] != '\0'){
c = original[i];
encoded[i] = EncodeCharacter(c);
i++;
/* add a NULL pointer at the end of the encoded string */
encoded[i] = '\0';
}
}


char EncodeCharacter(char c)
{
char character;
int value;

/* convert character into ascii code */
value = (int)c;

/* only change ascii value if it is alphabet */
if ((value >= 97) && (value <= 109)){
value+=13;
} else if ((value >= 110) && (value <= 122)){
value-=13;
} else if ((value >= 65) && (value <= 77)){
value+=13;
} else if ((value >= 78) && (value <= 90)){
value-=13;
}

/* convert ascii code into character */
character = (char)value;

/* return the encoded character */
return character;
}
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호