This C program demonstrate how to encrypt data using Rail fence (complex) technique.
Assumptions:
1. 5 X 5 matrix is used.
2. Key = 21345
Sample Output:
RAIL FENCE ENCRYPTION
Input Data: A B C D E F G H I J K L M N O P Q R S T U V W X Y
Input data arranged in 5 X 5 matrix:
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
Key Used = 2 1 3 4 5
Ciphertext: B G L Q V A F K P U C H M R W D I N S X E J O T Y
/*Assumptions:
1. 5 X 5 matrix is used.
2. Key = 21345
Sample Output:
RAIL FENCE ENCRYPTION
Input Data: A B C D E F G H I J K L M N O P Q R S T U V W X Y
Input data arranged in 5 X 5 matrix:
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
Key Used = 2 1 3 4 5
Ciphertext: B G L Q V A F K P U C H M R W D I N S X E J O T Y
* * * * *
* * * * *
Definition: Write a C program to Encrypt given data using Rail fence (complex) technique.
Assumptions:
1. 5 X 5 matrix is used.
2. Key = 21345
*/
#include<stdio.h>
int main()
{
char str[5][5];
int i,j,k, key[5]={2,1,3,4,5}, cnt=65;
printf("RAIL FENCE ENCRYPTION\n\n");
printf("Input Data: A B C D E F G H I J K L M N O P Q R S T U V W X Y\n\n");
//Input data A to Y is stored in str[][] matrix.
printf("Input data arranged in 5 X 5 matrix:\n");
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
str[i][j]=cnt++;
}
//To print full matrix..
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
printf("%c ",str[i][j]);
printf(" \n");
}
printf(" \n");
printf("Key Used = 2 1 3 4 5 \n\n");
printf("Ciphertext: ");
for(j=0; j<5; j++)
{
k=key[j]-1;
for(i=0; i<5; i++)
printf("%c ",str[i][k]);
}
return 0;
}
//Data can be taken from input.txt data file.
//Ciphertext can be stored into output.txt using C file management.
Output of the program
RAIL FENCE ENCRYPTION
Input Data: A B C D E F G H I J K L M N O P Q R S T U V W X Y
Input data arranged in 5 X 5 matrix:
A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y
Key Used = 2 1 3 4 5
Ciphertext: B G L Q V A F K P U C H M R W D I N S X E J O T Y
* * * * *
No comments:
Post a Comment