Skip to main content

Columnar Transposition Cipher

Columnar Transposition Cipher

Introduction 

The columnar transposition cipher is a fairly simple, easy to implement cipher. It is a transposition cipher that follows a simple rule for mixing up the characters in the plaintext to form the ciphertext.
Although weak on its own, it can be combined with other ciphers, such as a substitution cipher, the combination of which can be more difficult to break than either cipher on it's own. The ADFGVX cipheruses a columnar transposition to greatly improve its security.
Image result for columnar transposition cipher

Example 

The key for the columnar transposition cipher is a keyword e.g. GERMAN. The row length that is used is the same as the length of the keyword. To encrypt a piece of text, e.g.
defend the east wall of the castle
we write it out in a special way in a number of rows (the keyword here is GERMAN):
G E R M A N
d e f e n d
t h e e a s
t w a l l o
f t h e c a
s t l e x x
In the above example, the plaintext has been padded so that it neatly fits in a rectangle. This is known as a regular columnar transposition. An irregular columnar transposition leaves these characters blank, though this makes decryption slightly more difficult. The columns are now reordered such that the letters in the key word are ordered alphabetically.
A E G M N R
n e d e d f
a h t e s e
l w t l o a
c t f e a h
x t s e x l
The ciphertext is read off along the columns:
nalcxehwttdttfseeleedsoaxfeahl
Plain Text:-attack at dawn
keyword = zebra              pad character = x
Chiphertext:-caxttxtanadxakw

Code:-

#python3 code for Columnar Cipher TransFormation made by Quid Zohar Morbiwala
key=input ('Enter a key ') 
userval=input ('Enter a value ')
col=len(key)
if((len(userval)%col)!=0):userval+="x"*(len(userval)%col)
userval=userval.replace(' ', '')#remove white spaces from key 
o=[]
for i in key:
 o.append(i)  #generating list for keys
h=[]
for i in range(col):
 h.append(userval[i:len(userval):col])#generating list for plaintext column wise 
dic=dict(zip(o,h))    #adding both lists
so=sorted(dic.keys())    #sorting alphabateically keys of cipher
print(''.join(dic[i]for i in so))#join func for displaaying in string format

Output:-

Enter a key GERMAN
Enter a value defend the east wall of the castle
nalcxehwttxdttfsxeeleedsoaxfeahl

Comments

Popular posts from this blog

A Case Study On End-to-End Encryption Used In Whatsapp

A Case Study On End-to-End Encryption Used In Whatsapp 1.Introduction to End-to-End Encryption WhatsApp's end-to-end encryption is available when you and the people you message use the latest versions of the app. WhatsApp's end-to-end encryption ensures only you and the person you're communicating with can read what is sent, and nobody in between, not even WhatsApp. This is because your messages are secured with a lock, and only the recipient and you have the special key needed to unlock and read them. For added protection, every message you send has its own unique lock and key. WhatsApp, since its inception six years ago, has quickly grown into a global phenomenon, becoming one of the most popular mobile based communications applications in the world today. With a user base that eclipsed one billion in February, WhatsApp provides a service that potentially endangers the privacy of over 10% of the entire human population. In order to address these security concern...

Study of Support Vector Machines

Introduction to support vectors In machine learning, support vector machines (SVMs, also support vector networks) are supervised learning models with associated learning algorithms that analyze data used for classification and regression analysis. What are support vectors Support vectors are the data points that lie closest to the decision surface (or hyperplane) • They are the data points most difficult to classify • They have direct bearing on the optimum location of the decision surface • We can show that the optimal hyperplane stems from the function class with the lowest “capacity”= # of independent features/parameters Theoretical concept SVMs maximize the margin (Winston terminology: the ‘street’) around the separating hyperplane.  • The decision function is fully specified by a (usually very small) subset of training samples, the support vectors.  • This becomes a Quadratic programming problem that is easy to solve by standard methods Separation by Hyperplanes • Assu...