//功能:乘数加密 K=3 5 7 9 11 15 17 19 21 23 25
#include <stdio.h>
int str_len(char *str)//求字符串的长度 { int len = 0; while(*(str++)) len++; return len; } int main(int argc, char *argv[]) { char a[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char b[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; char str[50]; int k; printf("Please input the words(必须是小写可以用函数改变) :"); gets(str); printf("Please input the following number[3][5][9][11][15][17][19][21][23]:");//可以求逆元的数 scanf("%d",&k); int len = str_len(str); for(int i = 0;i<len;i++) for(int j = 0;j<26;j++) { if(str[i]==a[j]) str[i] = b[(k*j)%26]//换 else str[i] = str[i];//将空格等符号落下来 } printf("%s\n",str);//打印 return 0; }//解密
#include <stdio.h>
求字符串长度
int str_len(char *str) { int len = 0; while(*(str++)) len++; return len; }//求逆元
int mulny(int k) { int t; for(int i = 0;i<26;i++) { t=k*i; if(t%26==1) return i; } }int main(int argc, char *argv[])
{ char a[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; char b[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; char str[50]; int k; printf("Please input the words :"); gets(str); printf("Please input the following number[3][5][9][11][15][17][19][21][23]:");//26以内有逆元的数字 scanf("%d",&k); int p = mulny(k); int len = str_len(str); for(int i = 0;i<len;i++) for(int j = 0;j<26;j++) { if(str[i]==a[j]) str[i] = b[(p*j)%26]; else str[i] = str[i]; } printf("%s\n",str); return 0; }/*
会凯撒加密的这个应该没啥大问题,但是刚刚玩,我调试还是调试了一会的,我记得昨天都调好了,今天加密找不到了,存储代码的时候没规律。哎哎,又改的幸好不费劲。也许有错的地方希望提出改正,我想进步哦!谢谢大家。
*/