#include <stdio.h>
#include <string.h>
#include <ctype.h>
void encrypt(char text[], int key) {
for (int i = 0; text[i] != '\0'; i++) {
char base
= islower(text
[i
]) ? 'a' : 'A'; text[i] = (text[i] - base + key) % 26 + base;
}
}
}
void decrypt(char text[], int key) {
for (int i = 0; text[i] != '\0'; i++) {
char base
= islower(text
[i
]) ? 'a' : 'A'; text[i] = (text[i] - base - key + 26) % 26 + base;
}
}
}
int main() {
char text[100];
int key;
int choice;
scanf(" %[^\n]s", text
); // 공백 포함 입력 받기 printf("키 값을 입력하세요 (1~25): ");
if (choice == 1) {
encrypt(text, key);
printf("암호화된 문장: %s\n", text
); } else if (choice == 2) {
decrypt(text, key);
printf("복호화된 문장: %s\n", text
); } else {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KI2luY2x1ZGUgPGN0eXBlLmg+Cgp2b2lkIGVuY3J5cHQoY2hhciB0ZXh0W10sIGludCBrZXkpIHsKICAgIGZvciAoaW50IGkgPSAwOyB0ZXh0W2ldICE9ICdcMCc7IGkrKykgewogICAgICAgIGlmIChpc2FscGhhKHRleHRbaV0pKSB7CiAgICAgICAgICAgIGNoYXIgYmFzZSA9IGlzbG93ZXIodGV4dFtpXSkgPyAnYScgOiAnQSc7CiAgICAgICAgICAgIHRleHRbaV0gPSAodGV4dFtpXSAtIGJhc2UgKyBrZXkpICUgMjYgKyBiYXNlOwogICAgICAgIH0KICAgIH0KfQoKdm9pZCBkZWNyeXB0KGNoYXIgdGV4dFtdLCBpbnQga2V5KSB7CiAgICBmb3IgKGludCBpID0gMDsgdGV4dFtpXSAhPSAnXDAnOyBpKyspIHsKICAgICAgICBpZiAoaXNhbHBoYSh0ZXh0W2ldKSkgewogICAgICAgICAgICBjaGFyIGJhc2UgPSBpc2xvd2VyKHRleHRbaV0pID8gJ2EnIDogJ0EnOwogICAgICAgICAgICB0ZXh0W2ldID0gKHRleHRbaV0gLSBiYXNlIC0ga2V5ICsgMjYpICUgMjYgKyBiYXNlOwogICAgICAgIH0KICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIHRleHRbMTAwXTsKICAgIGludCBrZXk7CiAgICBpbnQgY2hvaWNlOwoKICAgIHByaW50Zigi7Iuc7KCAIOyVlO2YuCDtlITroZzqt7jrnqhcbiIpOwogICAgcHJpbnRmKCIxLiDslZTtmLjtmZRcbiIpOwogICAgcHJpbnRmKCIyLiDrs7XtmLjtmZRcbiIpOwogICAgcHJpbnRmKCLshKDtg53tlZjshLjsmpQgKDEg65iQ64qUIDIpOiAiKTsKICAgIHNjYW5mKCIlZCIsICZjaG9pY2UpOwoKICAgIHByaW50Zigi66y47J6l7J2EIOyeheugpe2VmOyEuOyalDogIik7CiAgICBzY2FuZigiICVbXlxuXXMiLCB0ZXh0KTsgLy8g6rO167CxIO2PrO2VqCDsnoXroKUg67Cb6riwCiAgICBwcmludGYoIu2CpCDqsJLsnYQg7J6F66Cl7ZWY7IS47JqUICgxfjI1KTogIik7CiAgICBzY2FuZigiJWQiLCAma2V5KTsKCiAgICBpZiAoY2hvaWNlID09IDEpIHsKICAgICAgICBlbmNyeXB0KHRleHQsIGtleSk7CiAgICAgICAgcHJpbnRmKCLslZTtmLjtmZTrkJwg66y47J6lOiAlc1xuIiwgdGV4dCk7CiAgICB9IGVsc2UgaWYgKGNob2ljZSA9PSAyKSB7CiAgICAgICAgZGVjcnlwdCh0ZXh0LCBrZXkpOwogICAgICAgIHByaW50Zigi67O17Zi47ZmU65CcIOusuOyepTogJXNcbiIsIHRleHQpOwogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIuyemOuqu+uQnCDshKDtg53snoXri4jri6QuXG4iKTsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=