Aim: Implementing Transposition Cipher (Rail fence Technique)
Theory:
Rail fence Technique involves writing plain text as sequence of diagonals and then reading it row-by-row to produce cipher text.
Algorithm:
1) Write down the plain text message as a sequence of diagonals.
2) Read the plain text written in Step 1 as a sequence of rows.
Example:
Original plain text message : Come home tomorrow
- Arrange the plain text message as sequence of diagonals.
Source Code:
public class railfence {
public static void main(String args[])
{
String input = “inputstring”;
String output = “”;
int len = input.length(),flag = 0;
System.out.println(“Input String : ” + input);
for(int i=0;i<len;i+=2) {
output += input.charAt(i);
}
for(int i=1;i<len;i+=2) {
output += input.charAt(i);
}
System.out.println(“Ciphered Text : “+output);
}
}
Output: