Home > Tips > Encryption and Decryption > Transposition Encryption
Transposition Encryption
Encryption and Decryption, Transposition Encryption, Geometrical Pattern Encoding, .NET Security Code, Download .NET Encryption Source Code
What is Transposition Encryption?
Transposition ciphers are based on the rearrangement of each character in the plain text message to produce a cipher text, These encryption technique include reversing the entire message, reforming the message into a geometrical shape, rearranging the plain text by scrambling a sequence of columns, and periodically permuting the character of the plain text.
Message Reversal
Encryption using message reversal means that the plain text is written backwards to producer a ciphertext, If the plain text message is.
WELCOME TO MY WEB SITE
Then the encrypted message reads as
ETIS BEW YM OT EMOCLEW
This is one of the simplest encryption technique, obviously it
is not very secure, since the cracker it one merely reads
cipher text in reverse
Here we are creating a function named MessageReversal which
takes one argument StrDataIn, it iterate each character from
reverse of the supplied string and concatenate output in
StrOut variable, after completing the loop it return the
reverse string.
Private Function MessageReversal(ByVal
StrDataIn As String)
Dim
StrOut As String
StrOut = ""
Dim
I As Integer
For
I = Len(StrDataIn) To 1 Step
-1
StrOut
&= Mid(StrDataIn, I, 1)
Next
MessageReversal = StrOut
End
Function
If we call function
MessageReversal("ATANU MAITY") then it returns
cipher text "YTIAM UNATA", same way if we call
MessageReversal("YTIAM UNATA") then it returns plain
text "ATANU MAITY".
Geometrical Pattern Encoding
In geometrical
pattern encoding the message is rearranged with the aid of
some type of geometric figure, a typical example being a two -
dimensional array or a matrix, First plain text message is
written into the figure according to a particular matrix, the
cipher text then created by taking the letters off the matrix
according to a different path, for example suppose the plain
text word,
MESSAGEREVERSAL is written into a 3*5 matrix
Column Number |
1 |
2 |
3 |
4 |
5 |
Cipher Text |
M |
S |
E |
V |
S |
|
E |
A |
R |
E |
A |
|
S |
G |
E |
R |
L |
If the letters are taken off by columns in the order
4,3,5,1,2 other than 1,2,3,4,5 then resulting cipher text will
be VEREREEALMESSAG.
You can rearranged the cipher text almost Factorial of number
of column way, for example if you have 5 column then you can
rearrange cipher text in 5!=120 different way, You can also
rearrange cipher text by rows also or both row and column
also. For a long message the actual encrypted message would be
sent as a continuous stream of characters to hide the
encryption periodicity.
Here we are creating one function called MessageTransposition
it takes two argument, one is input text and second one is a Boolean
switch which determine whether this function is perform
encryption or decryption. It first convert supplied string
into 2*3 matrix and rearrange the text with 2,0,1 column
order. and for decryption it reverse the order.
Private Function MessageTransposition(ByVal
StrDataIn As String,
_
ByVal ED As
Boolean)
Dim
DataArray(2, 3) As String
' 2*3 matrix
Dim
i As Integer
Dim
r, c As Integer
Dim
StrOut As String
StrOut = ""
r = 0 'row
index
c = 0 'column
index
For
i = 1 To Len(StrDataIn)
DataArray(r,
c) = Mid(StrDataIn, i, 1)
r
= r + 1 'increment column index
If
r > 1 Then
r = 0
c = c + 1 'increment row
index
End
If
If
c >= 3 Or i = Len(StrDataIn)
Then
r = 0
c = 0
'its time to send data to
strout
Dim
k, l As Integer
If ED = True
Then
'encrypt order 2,0,1
k = 2 'change the column
position
For l = 0 To
1
StrOut = StrOut & DataArray(l, k)
Next
k = 0 'change the column
position
For l = 0 To
1
StrOut = StrOut & DataArray(l, k)
Next
k = 1 'change the column
position
For
l = 0 To 1
StrOut = StrOut & DataArray(l, k)
Next
Else
'decrypt order 1,2,0
k = 1 'change the column
position
For l = 0 To
1
StrOut = StrOut & DataArray(l, k)
Next
k = 2 'change the column
position
For l = 0 To
1
StrOut = StrOut & DataArray(l, k)
Next
k = 0 'change the column
position
For l = 0 To
1
StrOut = StrOut & DataArray(l, k)
Next
'clear the fill character
StrOut
= Replace(StrOut, Chr(1), "")
End If
'clear the array
For k = 0 To
2
For l = 0 To
1
DataArray(l, k) = Chr(1)
Next
Next
End
If
Next
MessageTransposition =
StrOut
End Function
For example if we
call the function MessageTransposition("MICROSOFT VISUAL STUDIO DOT NET",True)
then it will encrypt the text at returns output like "OSMICRVIOFT SSUALO TUDINEDOT T".
and for decryption if you call the function MessageTransposition("OSMICRVIOFT SSUALO TUDINEDOT T",False)
then it decrypt the text and return plain text "MICROSOFT VISUAL STUDIO DOT NET"
For completing listing of the code and sample Visual Basic
/ C# .NET
project for Transposition Encryption can be found in Sample Code
section.
Home > Tips > Encryption and Decryption > Transposition Encryption