Question

In: Computer Science

Question The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and...

Question

The given plaintext is “Feistel cipher structure uses the same algorithm for both encryption and decryption”. Write Java or Python code to implement either Monoalphabetic cipher or Hill cipher or Transposition Cipher (Encryption and Decryption) and test your code on given plaintext. User may enter value of key at the command prompt, if required.

Solutions

Expert Solution

I have implemented the Monoalphabetic cipher using Caesar Cipher.

Code(Python 3.7.4)

#Program to implement Monoalphabetic cipher
import numpy as np

#each letter of a given word is replaced by a letter shifted n number of positions.
def cypher(ptext,n):
    ctext = ""
    for i in range(len(ptext)):
        char = ptext[i]
        if (char.isupper()):
            ctext += chr((ord(char) + n-65) % 26 + 65)
        else:
            ctext += chr((ord(char) + n - 97) % 26 + 97)

    return ctext

#using the cyclic property of modulo,instead of writing a seperate decrypt fuction we call
#the encrypt fuction with 26-n to decrypt the encypted text.
def decrypt(ctext,n):
    ptext = cypher(ctext,26-n)
    return ptext


text = "Feistel cipher structure uses the same algorithm for both encryption and decryption"

print ("The plain text is: " + text)

k = 7 #define a shift of 7 positions

#removing spaces and putting the words into an array
res = text.split()

#Encrypting each word in the array
mod26 = []
for word in res:
    temp = cypher(word, k)
    mod26.append(temp)

#print(mod26)

#Merging the encypted words back into a string
encrypted = ''
for word in mod26:
    encrypted = encrypted + word + ' '

print ("The encypted text is: " + encrypted)

#removing spaces and putting the encrypted words into an array
res = encrypted.split()

#decrypting each word in the array
plain = []
for word in res:
    temp = decrypt(word, k)
    plain.append(temp)

#print(plain)

#Converting the decrypted array back into a string
decrypted = ''
for word in plain:
    decrypted = decrypted + word + ' '

print ("The decrypted text is: " + decrypted)

Output:

python cypher.py
The plain text is: Feistel cipher structure uses the same algorithm for both encryption and decryption
The encypted text is: Mlpzals jpwoly zaybjabyl bzlz aol zhtl hsnvypaot mvy ivao lujyfwapvu huk kljyfwapvu
The decrypted text is: Feistel cipher structure uses the same algorithm for both encryption and decryption


Related Solutions

The Vigenère Cipher is an encryption algorithm that combines the use of a keyword with the...
The Vigenère Cipher is an encryption algorithm that combines the use of a keyword with the message to be encrypted. A tableau is provided that shows an encrypted character for each combination of characters in the message and the keyword. Using the Vigenère Tableau encryption scheme with a keyword of KEYWORD, encrypt the following message: IS INFORMATION SECURITY ESSENTIAL After encrypting the message, decrypt the following message, using KEYWORD as the keyword: YRJUW WWRIG JTFUW ERECE LCMKL CIWKR R For...
Modify the Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase...
Modify the Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9 to 8, 8 to...
Use Vigenère Cipher to decrypt the following plaintext with the given key key: deceptivedeceptivedeceptive plaintext: wearediscoveredsaveyourself
Use Vigenère Cipher to decrypt the following plaintext with the given key key: deceptivedeceptivedeceptive plaintext: wearediscoveredsaveyourself
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed...
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed respectively as: c=Ep, k=p+k%26                                                                                                                         (1) p=Dc,k=c-k%26                                                                                                                         (2) Please do the following: Write at least two paragraphs to explain the principle of operation of the algorithm. For a full credit, your explanation must show the architectural diagram of the encryption and decryption process. Write a program to implement the Caesar algorithm Code must have two functions; encryption and decryption Test your codes with p as...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm:...
Finish the following java question:  Modify a Encryption program so that it uses the following encryption algorithm: Every letter (both uppercase and lowercase) converted to its successor except z and Z, which are converted to 'a' and 'A' respectively (i.e., a to b, b to c, …, y to z, z to a, A to B, B to C, …, Y to Z, Z to A) Every digit converted to its predecessor except 0, which is converted to 9 (i.e., 9...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
Please compute AES128 encryption given by the following setting: (Note: Plaintext, Cipherkey and Ciphertext are Bytes)...
Please compute AES128 encryption given by the following setting: (Note: Plaintext, Cipherkey and Ciphertext are Bytes) Plaintext: 00……00 Cipherkey: 00……01 What is the ciphertext?
Write a Java program that uses the RC4 cipher algorithm to encrypt the following message using...
Write a Java program that uses the RC4 cipher algorithm to encrypt the following message using the word CODES as the key:   Cryptography is a method of protecting information and communications through the use of codes so that only those for whom the information is intended can read and process it. Instead of using stream length 256, we will use length 26. When encrypting, let A = 0 to Z = 25. Ignore spaces and punctuations and put the message...
This question is related to graph representation in Data Structure and Algorithm in Javascript. Question 1-...
This question is related to graph representation in Data Structure and Algorithm in Javascript. Question 1- Write a code in javascript in which you have to implement a function that converts adjacency matrix to adjacency list-store and it should have following signature function convertToAdjList( adjMatrix); You also have to include the functions that can demonstrate your implementation work with few inputs. Submit your javascript code with output as well. Question 2 Tell the runtime complexity of the conversion that implemented....
Question 7: Explain how public key encryption ensure both Confidentiality and Authentication.
Question 7: Explain how public key encryption ensure both Confidentiality and Authentication.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT