t H e — C o M p L e T e — I n F o


      

crypto programs

RSA cryptography program

#include<iostream.h>#include<conio.h>#include<math.h>void main(){clrscr();double p,q,n,fn,e,d,pt,ct;cin>>p>>q;n=p*q;fn=(p-1)*(q-1);cin>>e;for(d=0;d<100;d++){if( (fmod((d*e),fn))==1 ){break;}}cin>>pt;ct=fmod(pow(pt,e),n);cout<<ct<<endl;pt=fmod(pow(ct,d),n);cout<<pt;getch();}

Poly alphabetic

#include<iostream.h>#include<conio.h>#include<string.h>void main(){clrscr();int i,t;char msg[30],key[10];cout<<“enter your msg”;cin>>msg;cout<<“enter your key”;cin>>key;int j=0;for(i=0;i<strlen(msg);i++){t=((msg[i]-97)+(key[j]-97)%26);j++;if(j==strlen(key)){j=0;}cout<<char(t+97);}getch();}

One time pad cipher

#include<iostream.h>#include<conio.h>#include<string.h> void main(){clrscr();char msg[50],key[50];cout<<“enter the msg”;cin>>msg;cout<<“enter the key of length”<<strlen(msg);cin>>key;for(int i=0;i<strlen(msg);i++){int t=(((msg[i]-97)+(key[i]-97))%26);cout<<char(t+97);}getch();}

Mono Alphabetic Cipher

#include<iostream.h>#include<conio.h>#include<string.h> void main(){clrscr();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]={‘z’,’y’,’x’,’w’,’v’,’u’,’t’,’s’,’r’,’q’,’p’,’o’,’n’,’m’,’l’,’k’,’j’,’i’,’h’,’g’,’f’,’e’,’d’,’c’,’b’,’a’};char msg[30];cout<<“enter your msg”;cin>>msg; for(int i=0;i<strlen(msg);i++){for(int j=0;j<26;j++){if(a[j]==msg[i]){cout<<b[j];}}getch();}}

Hill Cipher

#include<iostream.h>#include<conio.h> void main(){clrscr();int i,j,t1,t2;char key[2][2],msg[2];for(i=0;i<2;i++){for(j=0;j<2;j++){cin>>key[i][j];}}cout<<“enter the msg”;for(i=0;i<2;i++){cin>>msg[i];}t1=(((key[0][0]-97)*(msg[0]-97))+((key[0][1]-97)*(msg[1]-97)))%26;t2=(((key[1][0]-97)*(msg[0]-97))+((key[1][1]-97)*(msg[1]-97)))%26;cout<<“t1=”<<char(t1+97);cout<<“t2=”<<(char)(t2+97);getch();}

Caesar Cipher Program

#include<iostream.h>#include<conio.h>#include<string.h>void main(){int k,i,t;char msg[30],cip[30];cout<<“enter your msg”;cin>>msg;cout<<“enter your key”;cin>>k;for(i=0;i<strlen(msg);i++){t=(((msg[i]-97)+k)%26);cip[i]=t+97;cout<<cip[i];}getch();}