I took a quick stab at an encrypt and decrypt variation; not sure how many bugs exist or whether or not it will be of any use... added the space for entering phrases.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
static char* letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=[{]};:|,<.>?~` ";
static char* codes[] = {"duL","1TQ","YTp","IoU","1oM","goJ","ooQ","oof","got","kdo","toh","ko5","oJo","nCo","6Bo","BXo","loq","0oY","oG3","4x0","wF4","wkp","i6e","Z8Y","PKx","KZg","b5p","72Y","IX5","x6q","0IK","AiM","jCK","CBH","nGO","kvp","516","xsN","jKF","12S","iFc","7Sc","Yz2","n2b","xdJ","kGR","2Po","DlY","UYA","VR5","8RJ","6pB","FHi","LG6","ZNl","TWy","hqx","D1X","RNV","iY3","9Fq","JsW","p1U","uO0","i8j","CYX","WPl","OKu","ZeF","Nca","nz9","YM8","ijk","Rfx","KnD","2Um","jqT","CVx","dsE","YRz","5OD","L9Q","jaA","5RG","sv1","dlA","DRB","cZW","WYY","nS7", "XZ0" };
char *encode(const char *src) {
char *tmp = NULL;
if((tmp = malloc((strlen(src) * 3) + 1)) != NULL) {
strcpy(tmp, "");
while(*src) {
strcat(tmp, codes[strchr(letter, *src) - letter]);
++src;
}
}
return tmp;
}
char *decode(const char *src) {
int idx = 0, i, j=0;
char *tmp = NULL,
buf[4];
if((tmp = malloc((strlen(src) / 3) + 2)) != NULL) {
while(idx < strlen(src)) {
memset(buf, 0, sizeof buf);
strncpy(buf, (src + idx), 3);
for(i=0; i < sizeof(codes)/sizeof(codes[0]); ++i) {
if(strcmp(buf, codes[i]) == 0) {
*(tmp + j++) = letter[i];
break;
}
}
idx += 3;
}
}
*(tmp + j) = '\0';
return tmp;
}
int main(void) {
char *test = "a simple string to try out",
*encoded = encode(test),
*decoded = decode(encoded);
if(encoded && decoded) {
puts(encoded);
puts(decoded);
free(encoded);
free(decoded);
}
return 0;
}