먼저 내가 이런 종류의 질문을 요청할 수 있습니다 아무도 내가 아주 이러한 코드 2 개 라인을 얻을 수없는 나에게Vigenere 암호 - 수식 설명 모든
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, string argv[]) {
string key = argv[1];
int l = strlen(argv[1]);
if (argc != 2) {
return 0;
}
for (int i = 0, n = strlen(key); i < n; i++) {
if (!isalpha(key[i])) {
return 0;
}
key[i] = tolower(key[i]);
key[i] = key[i] - 97;
}
string txt = GetString();
for (int k = 0, p = strlen(txt); k < p; k++) {
if (isalpha(txt[k])) {
if (isupper(txt[k])) {
printf("%c", (((txt[k] - 65) + (key[k % l])) % 26 + 65));
}
if (islower(txt[k])) {
printf("%c", (((txt[k] - 97) + (key[k % l])) % 26 + 97));
}
} else
if (!isalpha(txt[k])) {
printf("%c", txt[k]);
}
}
printf("\n");
return 0;
}
을 용서하지하시기 바랍니다있다
key[i] = key[i] - 97;
printf("%c", (((txt[k] - 97) + (key[k % l])) % 26 + 97));
우리는 왜 처음을 사용했고 두 번째가 어떻게 작동하는지에 대한 쉬운 설명이 있습니까?
당신은 확인 [아스키 코드 97 (할 수 있습니다 http://www.theasciicode.com.ar/ascii-printable-characters/lowercase- : 여기
프로그램의 수정 된 버전입니다 letter-a-minuscule-ascii-code-97.html)이''a ''인 것으로 보인다. 그리고 26은 알파벳의 문자 수와 관련이 있습니다. –