Source Caesar Cipher dengan C++
19.05 Diposting oleh are_tech
/*
* Program Simpel caesar cipher
*/
#include
std::string CaesarCipher(std::string str, int alphabet)
{
// untuk case sensitive (upper/lower)
char kecil = 'z' - alphabet;
char besar = 'Z' - alphabet;
for (unsigned int i = 0; i < str.length(); i++)
{
// memasukan alphabet ke dalam original karakter
if ((str[i] >= 'a' && str[i] <= kecil) || (str[i] >= 'A' && str[i] <= besar))
str[i] += alphabet; // add it on (simple ASCII math)
// untuk alphabet kecil
else if (str[i] >= kecil && str[i] <= 'z')
str[i] = 'a' + str[i]-kecil-1;
// untuk alphabet besar
else if (str[i] >= besar && str[i] <= 'Z')
str[i] = 'A' + str[i]-besar-1;
}
//mengembalikan string enkripsi
return str;
}
#include
using namespace std;
int main ()
{
int alphabet = 4;
string encrypted = CaesarCipher("gabehabe is T3H R0XX0R!", alphabet);
string decrypted = CaesarCipher(encrypted, 26-alphabet); // bagaimana mendekripsi
cout << encrypted << endl << decrypted;
cin.get(); // pause
return EXIT_SUCCESS;
}
source ini kalau di windows dapat dirun dengan menggunakan Dev C++
semoga bermanfaat

.jpg)

17 Maret 2009 pukul 02.17
om2 koq banyak yg salah yah??
18 Maret 2009 pukul 02.55
masa mas?? saya dah coba emm mas pakenya pa turbo atau dev??