Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,989 questions

51,934 answers

573 users

How to decrypt a string from numbers to characters in C++

1 Answer

0 votes
#include <iostream>
#include <sstream>

char convert_to_char_code(std::string str) {
    std::stringstream ss(str);
    int num;
    
    ss >> num;
    
    return num + 96;
}

std::string decrypt(std::string s) {
    std::stringstream ss;
    int i = 0;
        
    while (i < s.length()) {
        char ch;
            
        if (s[i + 2] == '#') {
            ch = (char)convert_to_char_code(s.substr(i, 2) );
            i += 2;
        } else {
            ch = (char)convert_to_char_code(s.substr(i, 1));
        }
        
        i++;
        
        ss << ch;
    }

    return ss.str();
}
    
int main()
{
    std::cout << decrypt("10#1426#25#524#");
}




/*
run:

jadzyex

*/

 



answered Jul 15, 2023 by avibootz
edited Jul 15, 2023 by avibootz

Related questions

...