⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example2.c

📁 加解密包
💻 C
字号:
/*      Time-stamp: <example2.c - Sun 8/17/2003 13:44:37 by tony>        Contact: Tony Song    revision : 1.3.0     This sample code works on Solaris 2.6 and above, Linux, Win32    Dependency: stringencrypt.h, lib_cstr_xxx.a        purpose:  explain the usage of the following functions:    int DJStrEncrypt(char *ClearText, char *EncryptedData)    int DJStrDecrypt(char *EncryptedData, char *ClearText)*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include "stringencrypt.h"void usage(void);/*******************  Perform encrypt operation *******************/int encrypt (char *clearText) {  int ret;  char EncryptedData[1024];  /* User program should calcuate the length     of input clear text to avoid buffer overflow;     for demo purpose only, we use fixed length*/  ret=DJStrEncrypt(clearText, EncryptedData);  if ( ret != 0) {/* failed */    printf("The string encrypt failed; Error #:[%d]!\n",ret);    return -1;  }    printf("the clear text is : %s\n",clearText);  printf("the cipher text length is %d\n",strlen(EncryptedData));  printf("the cipher text is : %s\n",EncryptedData);  return 0;}/*******************  Perform decrypt operation *******************/int decrypt (char *str) {  char detext[1024];  int ret;  ret = DJStrDecrypt(str,detext);  printf("return value=%d\n", ret);  if ( ret != 0 ) {/* failed */    printf("The string decrypt failed!\n");    return -1;  }  printf("clear text is : %s\n",detext);  printf("the length of clear text is %d\n",strlen(detext));  return 0;}int main(int argc, char *argv[]){  if ( argc < 2 ) {    usage();    exit(0);  }    if (strcmp(argv[1], "E") == 0) {    return encrypt(argv[2]);   } else if (strcmp(argv[1], "D") == 0) {    return decrypt(argv[2]);  }
  return 0;}void usage(void){  printf(" Usage:\n\n");  printf(" example E string   ;encrypt the clear string.\n");  printf(" example D string   ;decrypt the encrypted string.\n");    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -