Created
August 30, 2014 12:59
-
-
Save Ranjan13/56a55a0c39d00d16b143 to your computer and use it in GitHub Desktop.
Encryption of Affine Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include<stdio.h> | |
#include<string.h> | |
# define MAX_EL 100 | |
char ostr[MAX_EL]={0}; | |
int main() | |
{ | |
int x,a,b,i; | |
char c[MAX_EL]={0}; | |
printf("Enter a,b values\n"); | |
scanf("%d%d",&a,&b); | |
//check for gcd(a,b); | |
printf("Enter a string\n"); | |
if (getchar()) | |
{gets(c);} | |
printf("The String is:%s\n",c); | |
for(i=0;i<strlen(c);i++) | |
{ | |
{int x=c[i]; | |
if(x>=97 && x<=123) | |
{ | |
printf("ascii val:%d\n",x); | |
calc(x,a,b,i); | |
} | |
else | |
{ | |
ostr[i]=c[i]; | |
} | |
} | |
} | |
puts(ostr); | |
} | |
int calc(int x, int a, int b,int i) | |
{ | |
int cipher; | |
cipher=((a*x)+b) % 26; | |
printf("Calculated value is:%d\n",cipher); | |
if(cipher<97) | |
{ | |
cipher=cipher+96; | |
} | |
printf("The values are:%d %d %d\n",a,x,b); | |
printf("The encrpted output is:%d %c\n",cipher,cipher); | |
ostr[i]=cipher; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment