Plainteks -> Enkripsi -> Chiperteks -> Deskripsi -> Plainteks awal
contoh plainteks : uang disimpan di balik buku
contoh chiperteks : jdke aldjfdaj oe qtwey cvbn
Jadi Chiper adalah teknik substitusi setiap karakter dengan karakter lain dalam alphabet.
contoh :
contoh :
C = chiperteks
P = plainteks
K = key
P = plainteks
K = key
P : A B C D . . . . Z
C : D E F G . . . . C (digeser 3)
jadi
P : rahasia
C : udkdvld (k = 3)
Algoritma.C : D E F G . . . . C (digeser 3)
jadi
P : rahasia
C : udkdvld (k = 3)
- Enkripsi
Algoritma Mencetak enkripsi
Deklarasi :
plain, chiper : string
key,i : Integer
Deskripsi :
read ( key, plain)
for i=0 to strlen(plain) dochiper[i] <= (plain[i]+key) mod 128;end forwrite (chiper) - Deskripsi
Algoritma Mencetak deskripsi
Deklarasi :
chiper, teks : string
key,i : Integer
Deskripsi :
read ( key, chiper)
for i=0 to strlen(chiper) doteks[i] <= (chiper[i] - key) mod 128;end forwrite (teks)contoh program enkripsi deskripsi01
#include <cstdlib>
02
#include <iostream>
03
#include <string.h>
04
#define maks 500
05
06
using
namespace
std;
07
class
Enkripsi{
08
public
:
09
Enkripsi();
10
void
enkripsi();
11
void
deskripsi();
12
void
output();
13
private
:
14
char
chiper[maks];
15
int
key;
16
char
plain[maks];
17
18
};
19
20
Enkripsi::Enkripsi(){
21
cout<<
"Masukkan kata : "
;
22
cin.getline(chiper,
sizeof
(chiper));
23
cout<<
"Masukkan key : "
;
24
cin>>key;
25
cout<<endl;
26
}
27
28
void
Enkripsi::enkripsi(){
29
for
(
int
i=0;i<
strlen
(chiper);i+=1){
30
cout<<chiper[i]<<
"("
<<
int
(chiper[i])<<
") "
;
31
chiper[i] = (chiper[i]+key)%128;
32
}
33
}
34
35
void
Enkripsi::deskripsi(){
36
for
(
int
i=0;i<
strlen
(chiper);i+=1){
37
plain[i] = (chiper[i]-key)%128;
38
chiper[i] = plain[i];
39
}
40
}
41
42
void
Enkripsi::output(){
43
for
(
int
i=0;i<
strlen
(chiper);i+=1){
44
cout<<chiper[i];
45
}
46
}
47
48
int
main(
int
argc,
char
*argv[])
49
{
50
Enkripsi Deskripsi;
51
Deskripsi.enkripsi();
52
cout<<
"\n\nSetelah diEnkripsi : "
;
53
Deskripsi.output();
54
Deskripsi.deskripsi();
55
cout<<
"\n\nKembali diDeskripsi : "
;
56
Deskripsi.output();
57
58
cout<<endl<<endl;
59
system
(
"PAUSE"
);
60
return
EXIT_SUCCESS;
61
}
Tidak ada komentar:
Posting Komentar