1
04/29/2024
Eng. Mohamed Jaambiir
Computer System Security
COS-413
Lecture Four
Eng. Mohamed Jaambiir
2
Eng. Mohamed Jaambiir 04/29/2024
3
Eng. Mohamed Jaambiir 04/29/2024
4
Eng. Mohamed Jaambiir 04/29/2024
5
Eng. Mohamed Jaambiir 04/29/2024
6
Eng. Mohamed Jaambiir 04/29/2024
7
Eng. Mohamed Jaambiir 04/29/2024
8
Eng. Mohamed Jaambiir 04/29/2024
9
Eng. Mohamed Jaambiir 04/29/2024
10
Eng. Mohamed Jaambiir 04/29/2024
11
Eng. Mohamed Jaambiir 04/29/2024
12
Eng. Mohamed Jaambiir 04/29/2024
13
Eng. Mohamed Jaambiir 04/29/2024
14
Eng. Mohamed Jaambiir 04/29/2024
15
Eng. Mohamed Jaambiir 04/29/2024
16
Eng. Mohamed Jaambiir 04/29/2024
Rail Fence Cipher 17
Given a plain-text message and a numeric key, cipher/de-cipher the given text using
Rail Fence algorithm. The rail fence cipher (also called a zigzag cipher) is a form of
transposition cipher. It derives its name from the way in which it is encoded.
Eng. Mohamed Jaambiir 04/29/2024
18
In a transposition cipher, the order of the alphabets is re-arranged to obtain the cipher-
text.
In the rail fence cipher, the plain-text is written downwards and diagonally on
successive rails of an imaginary fence.
When we reach the bottom rail, we traverse upwards moving diagonally, after
reaching the top rail, the direction is changed again. Thus the alphabets of the
message are written in a zig-zag manner.
After each alphabet has been written, the individual rows are combined to obtain the
cipher-text.
Eng. Mohamed Jaambiir 04/29/2024
19
Rail Fence Encryption
For example, if the message is “GeeksforGeeks” and the number of rails = 3 then cipher is prepared as:
.’.Its encryption will be done row wise i.e. GSGSEKFREKEOE
Eng. Mohamed Jaambiir 04/29/2024
20
Rail Fence Decryption
As we’ve seen earlier, the number of columns in rail fence cipher remains equal to
the length of plain-text message. And the key corresponds to the number of rails.
Hence, rail matrix can be constructed accordingly. Once we’ve got the matrix we can
figure-out the spots where texts should be placed (using the same way of moving
diagonally up and down alternatively ).
Then, we fill the cipher-text row wise. After filling it, we traverse the matrix in zig-
zag manner to obtain the original text.
Eng. Mohamed Jaambiir 04/29/2024
21
Implementation
:Let cipher-text = “GsGsekfrekeoe” , and Key = 3
Number of columns in matrix = len(cipher-text) = 13
Number of rows = key = 3
Hence original matrix will be of 3*13 , now marking places with
text as ‘*’ we get
Eng. Mohamed Jaambiir 04/29/2024
Decryption 22
*___*___*___*
_*_*_*_*_*_*
__*___*___*_
“GsGsekfrekeoe”
Eng. Mohamed Jaambiir 04/29/2024
23
The End
Eng. Mohamed Jaambiir 04/29/2024