Buenas ! Para la facultad tuve que hacer el cifrado Atbash, y la verdad es que no quiero dejarlo "juntando polvo" en el ordenador, sabiendo que a alguien le puede servir...
EL CÓDIGO DE ABAJO TIENE MODIFICACIONES CON RESPECTO AL ORIGINAL, SI QUIEREN VER EL ORIGINAL, VOY A DEJARLO EN LOS COMENTARIOS.
Así que, sin más ni menos, el código:
#include <iostream>
#include <string.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
string texto;
string encriptado;
string alfabeto_normal = "abcdefghijklmnopqrstuvwxyz";
string alfabeto_invertido = "zyxwvutsrqponmlkjihgfedcba";
string alfabeto_mayusculas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alfabeto_invertido_mayusculas = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
void encriptar_desencriptar (string & texto, string & alfabeto_normal, string & alfabeto_invertido, string & alfabeto_mayusculas, string & alfabeto_invertido_mayusculas, string & encriptado){
for (int posicion_texto=0; posicion_texto < texto.length(); posicion_texto++){
for (int posicion=0; posicion < alfabeto_normal.length(); posicion++){
if (texto[posicion_texto] >= 'a' && texto[posicion_texto] <= 'z'){
if (texto[posicion_texto] == alfabeto_normal[posicion])
{encriptado += alfabeto_invertido[posicion];} }
if (texto[posicion_texto] >= 'A' && texto[posicion_texto] <= 'Z'){
if (texto[posicion_texto] == alfabeto_mayusculas[posicion])
{encriptado += alfabeto_invertido_mayusculas[posicion];} }
}
if (texto[posicion_texto] == ' '){encriptado += ' ';}
if (texto[posicion_texto] == ','){encriptado += ',';}
if (texto[posicion_texto] == '.'){encriptado += '.';}}
}
int main(){
system("title Cifrado Atbash");
system("cls");
int eleccion_inicio;
cout << " ____________________________________________ "<<endl;
cout << "| |"<<endl;
cout << "| Cifrado Atbash |"<<endl;
cout << "|____________________________________________|"<<endl;
cout << "| |"<<endl;
cout << "| 1. Encriptar/Desencriptar Texto |"<<endl;
cout << "| 2. Salir |"<<endl;
cout << "|____________________________________________|"<<endl;
cin >>eleccion_inicio;
cin.sync();
if (eleccion_inicio == 2){return 0;}
if (eleccion_inicio == 1){
system("cls");
cout << " ____________________________________________ "<<endl;
cout << "| |"<<endl;
cout << "| Cifrado Atbash |"<<endl;
cout << "|____________________________________________|"<<endl;
cout << "| |"<<endl;
cout << "| Ingrese el texto a encriptar-desencriptar |"<<endl;
cout << "| |"<<endl;
cout << "|____________________________________________|"<<endl;
cout << " "<<endl;
getline(cin, texto);
encriptar_desencriptar (texto, alfabeto_normal, alfabeto_invertido, alfabeto_mayusculas, alfabeto_invertido_mayusculas, encriptado);
system("cls");
cout << " "<<endl;
cout << "Texto original:"<<endl;
cout << " "<<endl;
cout << texto << endl;
cout << " "<<endl;
cout << " --------------------------------------------- "<<endl;
cout << " --------------------------------------------- "<<endl;
cout << " "<<endl;
cout << "Texto encriptado:"<<endl;
cout << " "<<endl;
cout << encriptado << endl;
cout << " "<<endl;
cout << " "<<endl;
cout << " ________________________________________ "<<endl;
cout << " | Presione una tecla para continuar... |"<<endl;
cout << " |________________________________________|"<<endl;
getch();
main();
};
}
Espero que sirva de aporte, saludos