English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

char *encrypt_i(char* str, char* encrypted, int iLength) {
printf("Original string is: <<%s>>\n",str);
int i=0;
int j=iLength-1;
int k=0;

int length = iLength;

int temp;
for(temp = 0; temp < length/2; temp ++) {
encrypted[i] = str[j];
encrypted[i+1] = str[k];
i+=2;
k++;
j--;
}

if(length % 2 == 0) {
encrypted[length] = '\0';
} else {
encrypted[length-1] = '\0';
}
return encrypted;
}

int main(){
char* str="This is a test.";
char* encrypted = (char *)malloc( strlen(str));
int u=strlen(str);
printf("%d\n",u);
char* a = encrypt_i( str, encrypted, strlen(str));
printf("%s\n", a);
return 0;
}

2007-03-02 17:54:35 · 2 answers · asked by Craig P 2 in Computers & Internet Programming & Design

2 answers

I would have to touch up on my C syntax to give complete answer but here is a general algorithm that is non-programming language specific. What you will need to do is start off with your two base cases..

If iLength == 0;
return '\0';

else if iLength == 1
return str[0];

else
return str[iLength-1] + str[0] + encrypt_i( str[ 1 - (length - 2) ] ,(length - 2) )

Now program it in the C programming language. Also I don't know if your original code is correct, because if iLength is odd it will lose the middle letter (not sure if this is a mistake or if that is what you want). And you probably don't need to have encrypted as one of the parameters to the encrypt_i program, as it is unneccassary.

2007-03-03 19:21:29 · answer #1 · answered by ........ 5 · 0 0

That is computer language for a webpage.

2007-03-03 03:14:34 · answer #2 · answered by jracer524 5 · 0 3

fedest.com, questions and answers