C语言实现字符串加密:简单字符转换与循环移位
#include <stdio.h> #include <ctype.h>
int main() { char str[61]; fgets(str, 61, stdin); // 读入一行字符,最多不超过60个字符 int i = 0; while (str[i] != '\0') { // 遍历字符串 if (islower(str[i])) { // 如果是小写字母 str[i] = toupper(str[i]); // 转换为大写字母 } else if (isupper(str[i])) { // 如果是大写字母 str[i] = tolower(str[i]); // 转换为小写字母 } else if (isdigit(str[i])) { // 如果是数字字符 str[i] += 5; // 顺序后延5个符号 } if (isalpha(str[i])) { // 如果是字母字符 str[i] += 3; // 字母顺序后延3个字符 if (str[i] > 'Z') { // 如果超出了大写字母范围 str[i] -= 26; // 回到小写字母范围 } if (str[i] > 'z') { // 如果超出了小写字母范围 str[i] -= 26; // 回到大写字母范围 } if (str[i] == 'x') { // 如果是x str[i] = 'a'; // 转换为a } else if (str[i] == 'y') { // 如果是y str[i] = 'b'; // 转换为b } else if (str[i] == 'z') { // 如果是z str[i] = 'C'; // 转换为C } } i++; // 继续遍历下一个字符 } printf('%s', str); // 输出加密后的字符串 return 0; }
原文地址: https://www.cveoy.top/t/topic/jA9x 著作权归作者所有。请勿转载和采集!