Question

In: Computer Science

python and mathematical solution Assume that you design a new affine cipher, where you encrypt three...

python and mathematical solution

Assume that you design a new affine cipher, where you encrypt three letters at a time, where your alphabet is

{'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 'I':8, 'J':9, 'K':10, 'L':11, 'M':12, 'N':13, 'O':14, 'P':15, 'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23, 'Y':24, 'Z':25,     ' ':26, '.':27, ',': 28, '!': 29, '?':30}.

In other words, you group your plaintext message in trigrams (i.e., three-character words) and encrypt each trigram of the plaintext separately using this affine cipher. For example, if the first three letters of a plaintext is “THE” then it will be encoded as follows

THE -> 19×31×31 + 7×31 + 4 = 18480.

If the number of letters in the plaintext is not a multiple of three, you pad it with the letter “X” at the end. Determine the modulus and the size of the key space.

Solutions

Expert Solution

Source Code:

affine={'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,
'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25,' ':26,'.':27,',': 28,'!': 29,'?':30}

plaintext=input("Enter the plaintext(In UPPER CASE): ")
if(len(plaintext)%3!=0):
mul=len(plaintext)%3
plaintext=plaintext+('X'*(3-mul))

lst=[]
for i in range(0,len(plaintext),3):
lst.append(plaintext[i:i+3])

cipher=[]
for trigram in lst:
val=affine[trigram[0]]*31*31 + affine[trigram[1]]*31 + affine[trigram[2]]
cipher.append(val)

print(cipher)

SAmple input and output:


Related Solutions

Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to...
Use the Affine cipher algorithm with k1=7,k2=11 to encrypt the following message : I want to get a hundred in this test
Part 1: Design a Cipher allow user to use a “key” to encrypt and decrypt the...
Part 1: Design a Cipher allow user to use a “key” to encrypt and decrypt the message. Use at least two ciphers combined to design your own cipher Specify the min. and max. length of the message user can enter to encrypt Specify the length of the “key” user can enter to encrypt and decrypt the message Part 2: Programme the cipher and make it available to validate. Cleartext for the original programming scripts has to submitted. A frontend webpage...
I need the code in python where I can encrypt and decrypt any plaintext. For example,...
I need the code in python where I can encrypt and decrypt any plaintext. For example, the plaintext "hello" from each of these Block Cipher modes of Operation. Electronic Code Block Mode (ECB) Cipher block Mode (CBC) Cipher Feedback Mode (CFB) Output feedback Mode (OFB) Counter Mode (CTR) Here is an example, Affine cipher expressed in C. Encryption: char cipher(unsigned char block, char key) { return (key+11*block) } Decryption: char invcipher(unsigned char block, char key) { return (163*(block-key+256)) }
1)Design the sample space for an experiment where you will flip three coins into the air,...
1)Design the sample space for an experiment where you will flip three coins into the air, first one, then the second, and finally the third to examine the faces landing upwards. Use the sample space to answer the questions that follow. Probabilities should be expressed as decimals. A) Please identify the sample space for this experiment. B) What is the probability of at least one head showing? C) What is the probability of exactly one tail showing? D) What is...
Assume you are a nurse manager on a unit where a new nursing documentation system is...
Assume you are a nurse manager on a unit where a new nursing documentation system is to be implemented. You want to ensure that the system will be usable and acceptable for the nurses impacted. You realize a nurse leader must be on the implementation team. The role description should be based on the SDLC stages and tasks and should clearly define how this individual will participate in and impact each of the following steps: Planning and requirements definition Analysis...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three years ago has a current value of $1,500. You have narrowed the choice down to a used 2016 Jeep Cherokee with a blue book value of $8,500 and a new Hyundai Elantra with a sticker price of $20,380. You plan to drive either vehicle for at least five more years. REQUIRED: 1. Based on the following steps in the decision-making process, briefly describe the...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three years ago has a current value of $1,500. You have narrowed the choice down to a used 2016 Jeep Cherokee with a blue book value of $8,500 and a new Hyundai Elantra with a sticker price of $20,380. You plan to drive either vehicle for at least five more years. REQUIRED: Based on the following steps in the decision-making process, briefly describe the key...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three...
Assume you need to buy a new vehicle. The junker that you paid $6,000 for three years ago has a current value of $1,500. You have narrowed the choice down to a used 2016 Jeep Cherokee with a blue book value of $8,500 and a new Hyundai Elantra with a sticker price of $20,380. You plan to drive either vehicle for at least five more years. REQUIRED: Based on the following steps in the decision-making process, briefly describe the key...
Assume that you have just been promoted to a new position where you have leadership responsibility....
Assume that you have just been promoted to a new position where you have leadership responsibility. You have never had formal leadership responsibilities before, and you wish to maximize the possibility that you will be successful with this new responsibility. Reflect upon the major leadership theories and models that we have learned about in this unit. Develop a Pro and Con list involving at least three of these theories/models. Reflect on each theory and discuss how the theory fits with...
When starting a new design, where can you find the default origin folder? a. Taskbar b....
When starting a new design, where can you find the default origin folder? a. Taskbar b. Timeline c. Canvas d. Browser If you want to add an equal constraint between two lines, where would you look? a. Sketch Palette b. File>Constraints c. Sketch>Constraints d. Create>Constraints What are the names of the 3 default planes in the browser? a. Top,Front, Side b. YX,ZX,ZY c. XY,XZ,YZ d. Top Front,Right
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT