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,990 questions

51,935 answers

573 users

How to decrypt a string from numbers to characters in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char convert_to_char_code(char str[]) {
    int num = (int)strtol(str, (char**)NULL, 10);

    return num + 96;
}

void decrypt(char s[], char result[]) {
    int i = 0, j = 0;

    while (i < strlen(s)) {
        char ch, buffer[3] = "";

        if (s[i + 2] == '#') {
            memcpy(buffer, &s[i], 2);
            ch = (char)convert_to_char_code(buffer);
            i += 2;
        }
        else {
            memcpy(buffer, &s[i], 1);
            ch = (char)convert_to_char_code(buffer);
        }

        i++;

        result[j++] = ch;
    }
}

int main()
{
    char result[128] = "";

    decrypt("10#1426#25#524#", result);

    puts(result);

    return 0;
}




/*
run:

jadzyex

*/

 



answered Jul 15, 2023 by avibootz
...