Algoritma dan Program Enkripsi dan Deskripsi

Algoritma Enkripsi :

Deklarasi :
plain, chiper        : string
key,i                   : Integer
Deskripsi :
read ( key, plain)

for i=0 to strlen(plain) do
             chiper[i] <= (plain[i]+key) mod 128;
             end for
write (chiper)

 

Algoritma  Deskripsi:

Deklarasi :
chiper, teks             : string
key,i                        : Integer
Deskripsi :
read ( key, chiper)

for i=0 to strlen(chiper) do
             teks[i] <= (chiper[i] – key) mod 128;
             end for
write (teks)

Program Ekripsi dan Deskripsi


#include <cstdlib>
#include <iostream>
#include <string.h>
#define maks 500

using namespace std;
class Enkripsi{
public:
Enkripsi();
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));
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;
}
}

void Enkripsi::deskripsi(){
for(int i=0;i<strlen(chiper);i+=1){
plain[i] = (chiper[i]-key)%128;
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;
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s