0% found this document useful (0 votes)
17 views

Melakukan Enkripsi Dan Dekripsi: Dida Prasetyo Rahmat 05311940000019 Teknologi Informasi

This document describes a C++ program for encrypting and decrypting text using the Caesar cipher. The program prompts the user to enter a message and a key for encryption or decryption. It then performs the encryption or decryption on the message based on the key and displays the resulting encrypted or decrypted message. The user is given a menu to choose between encryption, decryption, entering a new message or exiting the program.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Melakukan Enkripsi Dan Dekripsi: Dida Prasetyo Rahmat 05311940000019 Teknologi Informasi

This document describes a C++ program for encrypting and decrypting text using the Caesar cipher. The program prompts the user to enter a message and a key for encryption or decryption. It then performs the encryption or decryption on the message based on the key and displays the resulting encrypted or decrypted message. The user is given a menu to choose between encryption, decryption, entering a new message or exiting the program.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Dida Prasetyo Rahmat

05311940000019
Teknologi Informasi

Melakukan Enkripsi dan Dekripsi


Menggunakan Bahasa pemrograman C++, saya menemukan program untuk melakukan
enkripsi dan dekripsi Caesar cipher. Dengan memasukkan kata yang ingin di
dekripsi/enkripsi

Code
#include<iostream>
#include<string.h>
using namespace std;

int main() {
a:
cout<<"Enter the message:\n";
char msg[100];
cin >> msg;
int i, j, length,choice,key;
cout << "Enter key: ";
cin >> key; //take the key as input
length = strlen(msg);
b:
cout<<"\nMenu \n1. Encryption \n2. Decryption \n3. Masukkan kata lain \n4. Keluar
\nMasukkan pilihan anda : ";
cin>>choice;
if (choice==1){
char ch;
for(int i = 0; msg[i] != '\0'; ++i) {
ch = msg[i];
//encrypt for lowercase letter
if (ch >= 'a' && ch <= 'z'){
ch = ch + key;
if (ch > 'z') {
ch = ch - 'z' + 'a' - 1;
}
msg[i] = ch;
}
//encrypt for uppercase letter
else if (ch >= 'A' && ch <= 'Z'){
ch = ch + key;
if (ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}
msg[i] = ch;
}
}
printf("\n\nEncrypted message: %s\n", msg);
goto b;
}
else if (choice == 2) { //for decryption
char ch;
for(int i = 0; msg[i] != '\0'; ++i) {
ch = msg[i];
//decrypt for lowercase letter
if(ch >= 'a' && ch <= 'z') {
ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
msg[i] = ch;
}
//decrypt for uppercase letter
else if(ch >= 'A' && ch <= 'Z') {
ch = ch - key;
if(ch < 'A') {
ch = ch + 'Z' - 'A' + 1;
}
msg[i] = ch;
}
}
cout << "\n\nDecrypted message: " << msg << "\n";
goto b;
}
else if (choice == 3){
system("cls");
goto a;
}
else if (choice == 4){
return 0;
}
}

You might also like