Showing posts with label cipher. Show all posts
Showing posts with label cipher. Show all posts

Tuesday, 27 November 2012

Multiplicative Cipher (C++)

Multiplicative Cipher : Encryption

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
class MulCiph
{
  public:
  char str[100];
  int key;
  void getkey();
  void gettext();
  void convert();
};
void MulCiph :: gettext()
{
  cout<<"\nEnter the string: ";
  cin>>str;
}
void MulCiph :: getkey()
{
  cout<<"\nEnter the multiplicative cipher key: ";
  cin>>key;
}
void MulCiph :: convert()
{
  int h=strlen(str);
  for(int i=0;i<h;i++)
  {
    char c=(((toascii(str[i])-97)*key)%26)+97;
    cout<<str[i]<<"\t"<<((toascii(str[i])-97)*key)%26<<"\t"<<c<<endl;
  }
}
void main()
{
  clrscr();
  MulCiph a;
  a.gettext();
  a.getkey();
  a.convert();
  getch();
}

Download the code from here

Additive Cipher (C++)


Encryption using Additive Cipher in C++


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
class AddCiph
{
  public:
  char str[100];
  int key;
  void getkey();
  void gettext();
  void convert();
};
void AddCiph :: gettext()
{
  cout<<"\nEnter the plain string: ";
  cin>>str;
}
void AddCiph :: getkey()
{
  cout<<"\nEnter the additive cipher key: ";
  cin>>key;
}
void AddCiph :: convert()
{
  int h=strlen(str);
  for(int i=0;i<h;i++)
  {
    char c=(((toascii(str[i])-97)+key)%26)+97;
    cout<<str[i]<<"\t"<<((toascii(str[i])-97)+key)%26<<"\t"<<c<<endl;
  }
}
void main()
{
  clrscr();
  AddCiph a;
  a.gettext();
  a.getkey();
  a.convert();
  getch();
}

Download code from here