#include <stdio.h>

int main() {
    char str[100];
    printf("请输入字符串:");
    scanf("%[^
]", str); // 输入字符串,以回车符结束,使用%[^
]格式字符串读取
    getchar(); // 读取回车符

    for (int i = 0; str[i] != '\0'; i++) {
        if (str[i] >= 'a' && str[i] <= 'z') { // 处理小写字母
            str[i] = (str[i] - 'a' + 3) % 26 + 'a'; // 移位加密
        } else if (str[i] >= 'A' && str[i] <= 'Z') { // 处理大写字母
            str[i] = (str[i] - 'A' + 3) % 26 + 'A'; // 移位加密
        }
        printf("%c", str[i]); // 输出加密后的字符
    }

    return 0;
}
C语言字符串移位加密实现:字母移位3位加密

原文地址: https://www.cveoy.top/t/topic/oJUT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录