Professional Documents
Culture Documents
int posisi, nilai_dari_plain; cout << "\nMasukan plainteks tanpa spasi [KAPITAL]:
";
int index_huruf;
cin >> this->plainteks;
int r_satu, r_dua, r_tiga;
cout << "Masukan Kunci [hanya 3 huruf] : ";
~Enigma();
Enigma::~Enigma(){
void rotor_satu(string);
ofstream ofile;
void rotor_dua(string);
ofile.open("enigma.txt", ios::app);
ofile << "Plainteksnya : " << this->plainteks << endl;
ofile << "Kuncinya : " << this->kunci << endl; void Enigma::reflektor(){
ofile << "Hasil Enkripsi : " << this->cipherteks << endl; string abjad = "ABCDEFGDIJKGMKMIEBFTCVVJAT";
cout << "\nHasil Enkripsinya : " << this->cipherteks << if (huruf == abjad[i] && i != this->index_huruf){
endl;
this->index_huruf = i;}}}
cout << "Program selesai" << endl;}
rotor_dua("kembali"); this->index_huruf = i;
rotor_tiga("kembali"); break;}}}
input_output("kembali"); else{
this->nilai_dari_plain = (int)this->plainteks[this-
>posisi] % 65; void Enigma::rotor_dua(string aksi){
break;}}
//ENKRIPSI TO DEKRIPSI
#include <iostream>
#include <cstring>
if (this->r_dua == 26){ using namespace std;
#include <cmath>
ENIGMA DEKRIP
int indexof (char* array, int find) } while(choice.length() > 1 || choice != "e" && choice
{return strchr(array, find) - array;} != "d");
string crypt (const char *ct)
{int L = li(kunci[0]);
int M = li(kunci[1]);
int R = li(kunci[2]); std::cout << "\nMasukkan Plainteks: ";
string output;
for ( int x = 0; x < strlen(ct) ; x++ ) std::string input;
{
int ct_letter = li(ct[x]); std::getline(std::cin, input);
R = mod26(R + 1);
char a = rotor[2][mod26(R + ct_letter)];
char b = rotor[1][mod26(M + li(a) - R)];
char c = rotor[0][mod26(L + li(b) - M)]; int a, b;
char ref = reflector[mod26(li(c) - L)];
int d = mod26(indexof(rotor[0], do{
alpa[mod26(li(ref) + L)]) - L);
int e = mod26(indexof(rotor[1], std::cout << "\nm (biulangan relatif prima) and b
alpa[mod26(d + M)]) - M); (pergeseran) \nm = ";
char f = alpa[mod26(indexof(rotor[2],
alpa[mod26(e + R)]) - R)]; std::cin >> a;
output += f;}
return output;} std::cout << "b = ";
int main () std::cin >> b;
{// for ( int i = 0; i < 1000000; i++) {
//inputan enkripsi } while(std::cin.fail() || gcd(a,b) != 1);
cout<<"Kata Dekripsi :
THESIMPLESUBSTITUTIONCIPHERISACIPHER"<<e std::cout << '\n';
ndl;
if(choice == "e"){ #include<math.h>
} else if(input[i] >= 'A' && input[i] <= 'Z'){ float Enkrip[3][1], Dekrip[3][1], a[3][3], b[3][3],
mes[3][1], c[3][3];
std::cout << (char)((a * (input[i] - 'A') + b) % 26 + 'A');
void Enkripsi(); //mengenkripsi pesan
} else{
void Deskripsi();//mendeskripsi pesan
std::cout << input[i];
void getKeyMessage(); //mendapat kunci dan pesan
}}} else{
dari pengguna
for(int i = 0; i < input.length(); ++i){
void invers(); //menemukan kebalikan dari
if(input[i] >= 'a' && input[i] <= 'z'){ matriks kunci
return x1;}
void Deskripsi() {
int i, j, k;
HILL CIPHER
invers();
#include<iostream>
for(i = 0; i < 3; i++)
for(j = 0; j < 1; j++) b[i][j]=0;}
cout<<"\n";} if(i != k) {
int result = a % b;
void invers() { if (result < 0){
int i, j, k; result += b;}
float p, q; return result;}
for(i = 0; i < 3; i++)
cout << "Enter 4 letter key string: "; for (int i = 0; i < 2; i++){
// untuk mengubah huruf kecil ke huruf besar pada for (int i=0; i<2;i++){
kunci
for(int j =0; j <2; j++){
for (int i = 0; i < key.length(); i++){
key2D[i][j] = moduloFunc(key2D[i][j], 26);}}
key[i] = toupper(key[i]);}
// chiperteks ke plainteks
{cout << "WELCOME TO PROGRAM HILL CHIPER" << {key[i][j] = 'x' - 'a' + 1;
endl; }else{
cout << "1. Encryption\n2. Decryption" << endl; key[i][j] = k[l]-'a' + 1;}
cout << "Silahkan Pilih METODE : " ; cout<<key[i][j]<<" ";
int choice; l++;}
cin >> choice; cout<<endl;}
cin.ignore(); cout<<endl;
if (choice == 1){ while(msg.size()%3!=0)
cout << endl << "---Encryption---" << endl; {msg = msg + 'x';}
cipherEncryption(); cout<<"Extended Message : ";
} else if (choice == 2){ cout<<msg<<endl;
cout << endl << "---Decryption---" << endl; enc = new int[msg.size()];
cipherDecryption(); }void encrypt(){
} else { int i,j,l,m;
cout << endl << "PILIHAN SALAH" << endl; for(l=0;l<msg.size();)
}return 0;} {m = l;
for(i=0;i<3;i++)
{enc[l] = (key[i][0]*(msg[m]-'a' + 1) +
key[i][1]*(msg[m+1]-'a' + 1) +key[i][2]*(msg[m+2]-'a' +
1))%26 + 'a'-1;
cout<<(char)enc[l];
l++;}}}};
int main()
{string s,k;
cout<<"Masukkan Plainteks"<<endl;
fflush(stdin);
getline(cin,s);
cout<<"Masukkan Kunci"<<endl;
fflush(stdin);
getline(cin,k);
hill h(s,k);
cout<<endl;
cout<<"Enkripsi : ";
h.encrypt();
cout<<endl;
return 0;