TPCCLIB
Loading...
Searching...
No Matches
idcrypt.c
Go to the documentation of this file.
1
8/*****************************************************************************/
9#include "libtpcmisc.h"
10/*****************************************************************************/
11
12/*****************************************************************************/
13
15const char *libpet_idcrypt_version(void) {
16 return "2004-12-14";
17}
18
25 const char *string,
27 const char *key,
29 char *out,
31 int decrypt
32) {
33 char *keystr;
34 unsigned int len, r;
35
36 len=strlen(string);
37 if(len==0) return 0;
38
39 keystr = malloc(len);
40 if(!keystr) return 1;
41
42 if(len>strlen(key)) {
43 for(r=0;r<len;r++) {
44 keystr[r]=key[r%strlen(key)]-32;
45 if(keystr[r]>94) keystr[r]=94;
46 }
47 } else {
48 for(r=0;r<len;r++) {
49 keystr[r]=key[r]-32;
50 if(keystr[r]>94) keystr[r]=94;
51 }
52 }
53
54 for(r=0;r<len;r++) {
55 int c=(unsigned char)string[r]-32;
56 if(c>94) c=94;
57 if(decrypt) {
58 c=c-keystr[r];
59 if(c<0) c=(95-(-c)%95);
60 } else {
61 c=(c+keystr[r])%95;
62 }
63 out[r]=c+32;
64 }
65 out[r]=0;
66 free(keystr);
67 return 0;
68}
69
int id_crypt(const char *string, const char *key, char *out, int decrypt)
Definition idcrypt.c:23
const char * libpet_idcrypt_version(void)
Definition idcrypt.c:15
Header file for libtpcmisc.