Código:
#include <iostream>
using namespace std;
string EncryptAnscii(int key,string cadena);
string DesencryptAnscii(int key,string code);
int main(){
string cadena ="elhacker.net";
string code = EncryptAnscii(10,cadena);
cout << "code--> "<<code << endl;
cout << "decode-->"<<DesencryptAnscii(10,code);
return 0;
}
string EncryptAnscii(int key,string cadena){
string code = "";
for(int i = 0;i<cadena.length();i++){
if(cadena[i] == char(164)){
code+=char(253);
}else{
if(cadena[i] == char(165)){
code+=char(252);
}else{
if(int((cadena[i])+key-i) > 126){
code += char(((int(cadena[i])+key-i)-126)+32);
}else{
code+=char(int(cadena[i])+key-i);
}
}
}
}
return code;
}
string DesencryptAnscii(int key,string code){
string cadena = "";
for(int i = 0;i<code.length();i++){
if(code[i] == char(253)){
cadena+=char(164);
}else{
if(code[i] == char(252) ){
cadena+=char(165);
}else{
if(int((code[i])-key+i) < 32){
cadena += char(126-(32+(int(code[i])-key+i)));
}else{
cadena+=char(int(code[i])-key+i);
}
}
}
}
return cadena;
}