#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#pragma warning(disable: 4326 4996 6031)
void main()
{
char sMsg[80];
int nKey = 3, nMore = true;
while (nMore) {
printf("? ");
gets_s(sMsg);
if (sMsg[0] == 0)
break;
else if (sMsg[0] == '@') {
printf("Key ? ");
gets_s(sMsg);
nKey = atoi(sMsg);
}
else {
printf(" ");
char Encrypt(char chr, int nKey);
for (int i = 0; sMsg[i]; i++)
putchar(Encrypt(sMsg[i], nKey));
putchar('\n');
}
putchar('\n');
}
printf("Bye, ....\n");
}
char Encrypt(char chr, int nKey)
{
// 대소문자만 암호화
if (isalpha(chr)) {
/**
if (isupper(chr))
chr = (chr - 'A' + nKey + 26) % 26 + 'A';
else
chr = (chr - 'a' + nKey + 26) % 26 + 'a';
*/
char cBgn = isupper(chr) ? 'A' : 'a';
chr = (chr - cBgn + nKey + 26) % 26 + cBgn;
}
return chr;
}
/*****
? I Love You
L Oryh Brx
? @
Key ? -3
? L Oryh Brx
I Love You
?
Bye, ....
*****/
Created by 송바래
✉ gihun3645@naver.com
🚩경기도, 성남시