Sabtu, 05 April 2014

Program Enkripsi Kata dengan C++


monggo dicoba,
#include <cstdlib>
#include <iostream.h>
#include <string.h>
#define maks 500 //---------------------> [1]
using namespace std;

class Enkripsi{
public:
Enkripsi(); //---------------------> [2]
void enkripsi();
void deskripsi();
void output();
private:
char chiper[maks];
int key;
char plain[maks];
};

Enkripsi::Enkripsi(){
cout<<"Masukkan kata : ";
cin.getline(chiper,sizeof(chiper)); //---------------------> [3]   
cout<<"Masukkan key  : ";
cin>>key;
cout<<endl;
}

void Enkripsi::enkripsi(){
for(int i=0;i<strlen(chiper);i+=1){
cout<<chiper[i]<<"("<<int(chiper[i])<<") ";
chiper[i] = (chiper[i]+key)%128;    //---------------------> [4]
}
}

void Enkripsi::deskripsi(){
for(int i=0;i<strlen(chiper);i+=1){
plain[i] = (chiper[i]-key)%128; //---------------------> [5]
chiper[i] = plain[i];
}
}

void Enkripsi::output(){
for(int i=0;i<strlen(chiper);i+=1){
cout<<chiper[i];
}
}

int main(int argc, char *argv[])
{
Enkripsi Deskripsi;
Deskripsi.enkripsi();
cout<<"\n\nSetelah diEnkripsi : ";
Deskripsi.output();
Deskripsi.deskripsi();
cout<<"\n\nKembali diDeskripsi : ";
Deskripsi.output();

cout<<endl<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}


Reaksi:

0 komentar:

Posting Komentar

Baca artikel lainnya juga ya.. Kalau Sempat, tinggalkan komentar .

Popular Posts

Sahabat Blogger