int fence_cipher(unsigned char* data, int data_length, int n)
{
unsigned char* ret;
int i, j, k = 0;
if (data_length
return 2;
}
if ( n = data_length ) {
return 1;
ret = (unsigned char*)calloc(1, data_length + 1);
if (ret == NULL) {
return 3;
for (i = 0; i
for (j = 0; j * (n + 1)
if (j * (n + 1) - i >= 0) {
ret[k++] = data[j * (n + 1) - i];
if (i != 0 && i != n - 1 && j * (n + 1) + i
ret[k++] = data[j * (n + 1) + i];
ret[k] = "\0";
strncpy((char *)data, (char *)ret, data_length);
free(ret);
return 0;
int fence_cipher(unsigned char* data, int data_length, int n)
{
unsigned char* ret;
int i, j, k = 0;
if (data_length
return 2;
}
if ( n = data_length ) {
return 1;
}
ret = (unsigned char*)calloc(1, data_length + 1);
if (ret == NULL) {
return 3;
}
for (i = 0; i
{
for (j = 0; j * (n + 1)
{
if (j * (n + 1) - i >= 0) {
ret[k++] = data[j * (n + 1) - i];
}
if (i != 0 && i != n - 1 && j * (n + 1) + i
ret[k++] = data[j * (n + 1) + i];
}
}
}
ret[k] = "\0";
strncpy((char *)data, (char *)ret, data_length);
free(ret);
return 0;
}