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