Encryption/decryption of subject names and other identification information in string form.
More...
Go to the source code of this file.
Encryption/decryption of subject names and other identification information in string form.
- Author
- Calle Laakkonen
- Note
- Method is simple and not safe for data transfer over internet, but can be used to hide identification in blinded studies.
Definition in file idcrypt.c.
◆ id_crypt()
| int id_crypt |
( |
const char * | string, |
|
|
const char * | key, |
|
|
char * | out, |
|
|
int | decrypt ) |
Scramble characters in ASCII range 32-126 using the Vigenere Cipher. Other characters are discarded.
- Returns
- Returns 0 if successful
- Parameters
-
| string | Original string to be encrypted/decrypted |
| key | Keyword string |
| out | Encrypted/decrypted string |
| decrypt | Set to 1 when decrypting, or to 0 when encrypting |
Definition at line 23 of file idcrypt.c.
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}
◆ libpet_idcrypt_version()
| const char * libpet_idcrypt_version |
( |
void | | ) |
|
Return idcrypt module version info
Definition at line 15 of file idcrypt.c.
15 {
16 return "2004-12-14";
17}