Total members 11895 |It is currently Tue Dec 03, 2024 6:57 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Encryption and Decryption encryption Affine cipher code implementation
cpp code
#include<stdio.h>
#include<string.h>
void main()
{
int ch,a1,b1,a,b,c,d,d1[15],h,n,i=0;
char str1[80],ek[80];
printf("Enter the text \n");
gets(str1);
do
{
printf("Enter the key \na:");
scanf("%d",&a);
printf("\nb:");
scanf("%d",&b);
a1=a;
b1=b;
b=26;
d=1;
while(d!=0)
{


c=a/b;

d=a%b;
d1[i]=d;
a=b;
b=d;
i=i++;



}

n=i-1;





if(d1[n-1]==1)
{
printf("\nOi ariumoi einai prvtoi metaji tous\n\n");
ch=1;

}
else
{
printf("\nOi ariumoi den einai prvtoi metaji tous\n\n");
ch=0;
}
}
while(ch==0);
a=a1;
b=b1;
printf("\nTo kleidi einai (%d,%d):\n",a,b);

printf("\nTo keimeno einai %s to mikos toy %d \n",str1,strlen(str1));
n=strlen(str1);

ek[n]='\0';
h=strlen(ek);
for (i=0; i<h; i++)
{
str1[i]=str1[i]-97;
ek[i]=((a*str1[i]+b)%26)+97;
printf("%c -> %d to \n",str1[i]+97,str1[i]);
}

printf("\n\nTo kriptografhmeno keimeno einai:%s \n",ek);
for (i=0; i<h; i++)
{
printf("%c -> %d \n",ek[i],ek[i]-97);
}
printf("To kriptografhmeno keimeno einai:%s \n\n",ek);

}


decryption :
cpp code
#include<stdio.h>
#include<string.h>
void mul(int a1,int b1,int *d,int *x,int *y);
void main()
{
int ch,xx,a1,b1,a,b,c,d,d1[15],h,n,x,key,y,i=0;
char str1[80],dk[80];
printf("Enter the text \n");
gets(str1);
do
{

printf("Enter the key \na:");
scanf("%d",&a);
printf("\nb:");
scanf("%d",&b);

a1=a;
b1=b;
b=26;
mul(a,b,&d,&x,&y);
key=x;
if (key<0)
{
key=26+key;
}
printf("\n1/a:%d \n",key);

d=1;
while(d!=0)
{


c=a/b;

d=a%b;
d1[i]=d;
a=b;
b=d;
i=i++;



}

n=i-1;





if(d1[n-1]==1)
{
printf("\nOi ariumoi einai prvtoi metaji tous\n\n");
ch=1;

}
else
{
printf("\nOi ariumoi den einai prvtoi metaji tous\n\n");
ch=0;
}
}
while(ch==0);
a=a1;
b=b1;
printf("\nTo kleidi einai (%d,%d):\n",a,b);

printf("\nTo keimeno einai %s to mikos toy %d \n",str1,strlen(str1));
n=strlen(str1);

dk[n]='\0';
h=strlen(dk);
for (i=0; i<h; i++)
{
str1[i]=str1[i]-97;
xx=(str1[i]-b)%26;/*to kano se periptosi pou o b einai megalos*/
if (xx<0)
{
xx=26+xx;
}

dk[i]=((key*(xx))%26)+97;
printf("%c -> %d\n",str1[i]+97,str1[i]);
}
printf("\n\nTo kriptografhmeno keimeno einai:%s \n",dk);
for (i=0; i<h; i++)
{
printf("%c -> %d\n",dk[i],dk[i]-97);
}
printf("To kriptografhmeno keimeno einai:%s \n\n",dk);

}

void mul(int a1,int b1,int *d1,int *x1,int *y1)
{int c,d,x,y;
if(b1==0)
{
*d1=a1;
*x1=1;
*y1=0;


}
else{
d=*d1;
x=*x1;
y=*y1;



c=a1%b1;

mul(b1,c,&d,&x,&y);


*d1=d;
*x1=y;
*y1=x-(a1/b1)*(y);

}

}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Encryption and Decryption encryption Affine cipher code
 Ceasar encryption-decryption-cipher-decipher code     -  
 Row Transposition cipher - encryption-decryption Csharp(C#)     -  
 Row Transposition cipher - encryption-decryption java     -  
 RSA encryption decryption cipher algorithm java     -  
 encryption and decryption in c++     -  
 encryption/ decryption without key using C++     -  
 codes for encryption/decryption algorithms     -  
 Advanced Encryption Standard (AES)-Example-Cipher (Step1)     -  
 Encryption Algorithm{Data Encryption Standard}     -  
 Encryption decoding     -  



Topic Tags

C++ Algorithms
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com