📄 example.c
字号:
/* Time-stamp: <example1.c - Sun 8/17/2003 13:38:57 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 strEncrypt(char *passwd, char *clearText, char *encryptedData) int strDecrypt(char *passwd, char *cipherText, char *decryptedData)*/#include <stdlib.h>#include <stdio.h>#include <string.h>#include "stringencrypt.h"void usage(void);/******************* Perform encrypt operation *******************/int encrypt (char *passwd, char *ClearText) { char EncryptedData[1024]; int ret; /* User program should calcuate the length of input clear text to avoid buffer overflow; for demo purpose only, we use fixed length*/ ret = strEncrypt(passwd,ClearText,EncryptedData); if ( ret != 0 ) {/* failed */ printf("The string encrypt failed; Error #:[%d]!\n",ret); return -1; } printf("the cipher text length is %d\n",strlen(EncryptedData)); printf(">>>: [%s] | [%s] | [%s]\n",passwd, ClearText, EncryptedData); return 0;}/******************* Perform decrypt operation *******************/int decrypt (char *passwd, char *EncryptedData) { char clearText[1024]; int ret; ret = strDecrypt(passwd,EncryptedData,clearText); printf("return value=%d\n", ret); if ( ret != 0 ) {/* failed */ printf("The string decrypt failed!\n"); return -1; } printf("the length of clear text is %d\n",strlen(clearText)); printf(">>>: [%s] | [%s] | [%s]\n",passwd, clearText, EncryptedData); return 0;}int main(int argc, char *argv[]){ if ( argc < 4 ) { usage(); exit(0); } if (strcmp(argv[1], "E") == 0) { printf("This is the passwd:[%s]\n",argv[2]); return encrypt(argv[2], argv[3]); } else if (strcmp(argv[1], "D") == 0) { return decrypt(argv[2], argv[3]); } else { usage(); } return 0;} void usage(void){ printf(" Usage:\n\n"); printf(" example E passwd string ;Encrypt the clear text.\n"); printf(" example D passwd string ;Decrypt the cipher text.\n"); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -