仿射函数加密解密算法.docx
仿射函数加密解密算法/*加密函数y=11x+6mod26 解密函数x=19y+16mod26*/#include<stdio.h>#include<stdlib.h>#include<string.h>int transform(char s,int n);int endecryp(int input,int a,int b,int output);int m;int mainchar s100;int n100,d100;transform(s,n);/*加密*/int x,y,z,l;printf("输入加密参数;x=");scanf("%d",&x);printf("输入加密参数;y=");scanf("%d",&y);endecryp(n,x,y,d);printf("输入解密参数;z=");scanf("%d",&z);printf("输入解密参数;l=");scanf("%d",&l);/*解密*/endecryp(d,z,l,n);int transform(char s,int n)int i;printf("输入连续的小写或大写字母:");gets(s);m=strlen(s);for(i=0;i<m;i+)if (si>='a'&&si<='z')ni=si-'a'else if (si>='A'&&si<'Z')ni=si-'A'elseprintf("输入有误");exit(1);printf("%4d",ni);printf("n");int endecryp(int input,int a,int b,int output)int i;for(i=0;i<m;i+)outputi=(a*inputi+b)%26;printf("%4d",outputi);printf("n");