APUE Learning Example Source Code
guowenxue
2020-01-01 5c07107b73c234ef1f80a92abe795bf3f5c7050f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*********************************************************************************
 *      Copyright:  (C) 2018 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  crypto.c
 *    Description:  This file is LingYun crypto library 
 *                 
 *        Version:  1.0.0(2018年12月20日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2018年12月20日 11时56分04秒"
 *                 
 ********************************************************************************/
#include <string.h>
 
int encrypt(char *plaintext, char *ciphertext, int size)
{
    int       i;
 
    if( size < strlen(plaintext) )
    {
        return -1;
    }
 
    for(i=0; i<strlen(plaintext); i++)
    {
        ciphertext[i] = plaintext[i]+3;
    }
 
    return 0;
}
 
int decrypt(char *ciphertext, char *plaintext, int size)
{
    int      i;
 
    if( size < strlen(ciphertext) )
    {
        return -1;
    }
 
    for(i=0; i<strlen(ciphertext); i++)
    {
        plaintext[i] = ciphertext[i]-3;
    }
 
    return 0;
}