Character encryption

Encryption characters: the preparation of an encryption function: int code (int * c), the decryption function: int decode (int * c), the main function enter some pure characters, these characters call encryption algorithm to encrypt, encryption mode: each character code +13 value, and then call the function to decrypt the encrypted characters sequentially output.

#include <stdio.h>

/* 加密算法 */
int code(int *c) {
    *c = *c + 13;
    return *c;
}

/* 解密算法 */
int decode(int *c) {
    *c = *c - 13;
    return *c;
}

void main() {
    int c[100], i;
    i = 0;
    while ((c[i] = getchar()) != '\n') {
        putchar(code(&c[i]));
        i++;
    }
    printf("\n");
    i = 0;
    while (c[i] != '\n') {
        putchar(decode(&c[i]));
        i++;
    }
    printf("\n");
}
Published 139 original articles · won praise 3 · Views 930,000 +

Guess you like

Origin blog.csdn.net/qq_38490457/article/details/104828702