In: Computer Science
Answer I)
It is a technique used to avoid an unauthorized access of data.
It helps to provide accountability fairness and accuracy and also
provide confidentiality. Broadly, four different kinds of people
contributed their efforts in this technique and are: (i) Military,
(ii) The Diplomatic Corps, (iii) Diarists, and (iv) Communications
System. Cryptography involves two basic operations and is named as
encryption and key management. Information/data canbe encrypted
using a cryptographic algorithm by various keys. The security of
cryptographic system is not only
dependent on the encryption algorithm; it also depends upon the
keys used for the encryption. These keys area always kept secured
from the hacker and are known as secret key. Key plays an important
role in encryption process, which is a main part of cryptography .
Due to channel impairments sometimes the transmitted data and/or
key may get corrupted. If it is slightly changed or corrupted, the
data will not be recovered; therefore, key needs to be transported
over the secured channel. The frequency of use of a cryptographic
key always has a direct correlation to how often the key should be
changed. Encryption algorithms can be hacked by utilizing
supercomputer which provides fast speed and allows the hacker to
use more permutations and combinations in a specified time. Modern
era depends upon wireless communication and almost all the
electronic funds are being carried out online. In order to protect
the same and maintain the privacy of the users; cryptography is the
best solution due to their better response even in the presence of
advisory. For better security, either more number of keys is used
or the length of the existing keys is increased. In both the
approaches the overheads are increased, therefore, the best idea is
to use sub-keys. Sub-keys are used only for such nodes which are
attacked by the hacker. The sub keys are always derived from the
main key which helps in reducing the overheads. The basic
cryptographic model has been shown in figure 2.1. It involves
encryption and decryption section; initially, the data has been
encrypted by the help of key and further transmitted over the web.
Finally, it has been received and the encrypted data is decrypted
with the help of same or different key. The key is any value and/or
word and is used in both the sections for encryption and decryption
purpose.
Answer II)
# Python3 implementation of
# Columnar Transposition
import
math
key
=
"HACK"
# Encryption
def
encryptMessage(msg):
cipher
=
""
# track key
indices
k_indx
=
0
msg_len
=
float
(
len
(msg))
msg_lst
=
list
(msg)
key_lst
=
sorted
(
list
(key))
# calculate column of
the matrix
col
=
len
(key)
# calculate maximum
row of the matrix
row
=
int
(math.ceil(msg_len
/
col))
# add the padding
character '_' in empty
# the empty cell of
the matix
fill_null
=
int
((row
*
col)
-
msg_len)
msg_lst.extend(
'_'
*
fill_null)
# create Matrix and
insert message and
# padding characters
row-wise
matrix
=
[msg_lst[i: i
+
col]
for
i
in
range
(
0
,
len
(msg_lst), col)]
# read matrix
column-wise using key
for
_
in
range
(col):
curr_idx
=
key.index(key_lst[k_indx])
cipher
+
=
''.join([row[curr_idx]
for
row
in
matrix])
k_indx
+
=
1
return
cipher
# Decryption
def
decryptMessage(cipher):
msg
=
""
# track key
indices
k_indx
=
0
# track msg
indices
msg_indx
=
0
msg_len
=
float
(
len
(cipher))
msg_lst
=
list
(cipher)
# calculate column of
the matrix
col
=
len
(key)
# calculate maximum
row of the matrix
row
=
int
(math.ceil(msg_len
/
col))
# convert key into
list and sort
# alphabetically so
we can access
# each character by
its alphabetical position.
key_lst
=
sorted
(
list
(key))
# create an empty
matrix to
# store deciphered
message
dec_cipher
=
[]
for
_
in
range
(row):
dec_cipher
+
=
[[
None
]
*
col]
# Arrange the matrix
column wise according
# to permutation
order by adding into new matrix
for
_
in
range
(col):
curr_idx
=
key.index(key_lst[k_indx])
for
j
in
range
(row):
dec_cipher[j][curr_idx]
=
msg_lst[msg_indx]
msg_indx
+
=
1
k_indx
+
=
1
# convert decrypted
msg matrix into a string
try
:
msg
=
''.join(
sum
(dec_cipher,
[]))
except
TypeError:
raise
TypeError(
"This program
cannot"
,"handle repeating words.")
null_count
=
msg.count(
'_'
)
if
null_count >
0
:
return
msg[:
-
null_count]
return
msg
# Driver Code
msg
=
"Geeks for
Geeks"
cipher
=
encryptMessage(msg)
print
(
"Encrypted Message:
{}"
. format(cipher))
print
(
"Decryped Message:
{}"
. format(decryptMessage(cipher)))
Output:
Encrypted Message: e kefGsGsrekoe_ Decrypted Message: Geeks for Geeks
Note: Plzzz don' t give dislike.....Plzzz comment if u have any problem i will try to resolve it.......