#include #include void railfence_encipher(int key, const char *plaintext, char *ciphertext); void railfence_decipher(int key, const char *ciphertext, char *plaintext); int main(int argc, char *argv[]){ /* the string to encipher / decipher */ char *plaintext = "defendtheeastwallofthecastle"; /* allocate some space for results of enciphering/deciphering */ char *ciphertext = malloc(strlen(plaintext)+1); char *result = malloc(strlen(plaintext)+1); /* the following lines do all the enciphering and deciphering */ railfence_encipher(3, plaintext,ciphertext); railfence_decipher(3, ciphertext,result); /* print our results */ printf("-->original: %s\n-->ciphertext: %s\n-->plaintext: %s\n", plaintext,ciphertext,result); free(ciphertext); free(result); system("PAUSE"); return 0; } /******************************************************************* void railfence_encipher(int key, const char *plaintext, char *ciphertext) - Uses railfence transposition cipher to encipher some text. - takes a key, string of plaintext, result returned in ciphertext. - ciphertext should be an array the same size as plaintext. - The key is the number of rails to use *******************************************************************/ void railfence_encipher(int key, const char *plaintext, char *ciphertext){ int line, i, skip, length = strlen(plaintext), j=0,k=0; for(line = 0; line < key-1; line++){ skip = 2*(key - line - 1); k=0; for(i = line; i < length;){ ciphertext[j] = plaintext[i]; if((line==0) || (k%2 == 0)) i+=skip; else i+=2*(key-1) - skip; j++; k++; } } for(i=line; i