Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Cryptography is the science of making messages secure, of transforming readable

ID: 670989 • Letter: C

Question

Cryptography is the science of making messages secure, of transforming readable messages into unreadable messages and back again. Messages that are unreadable are called cipher-text. The process of turning plaintext into cipher-text is called encryption. The reverse process of turning cipher-text into plaintext is called decryption. One of the easiest ways to encrypt a message is to scramble the letters. For example the word "apple" could be randomly transformed to "lapep." In fact there are 120 different possible arrangements of the word "apple." However, if the encryption algorithm randomly scrambles the letters, the task of the decryption algorithm is pretty hard. Encryption and decryption algorithms must work together in some agreed upon way, with the encryption algorithm scrambling letters and the decryption algorithm unscrambling them. A transposition cipher is one way to scramble the letters of a message. The cipher separates the message into two groups of characters: the first group composed of the even-numbered characters and the second group composed of the oddnumbered characters. To produce the cipher-text, the cipher puts together both groups; placing the group of the even-numbered characters first, followed by the group of odd-numbered characters. This encryption results in a string with the characters shuffled to new positions.

a) Write a python program that takes as a parameter the message, encrypt the message as described above and returns the cipher-text. b) Write a python program that takes as a parameter the cipher-text, decrypt the cipher-text as described above and returns the message.

Explanation / Answer

Def scramble2encrpt(plaintext);

Evenchars="";oddchars=""; charcount=0;for ch in plaintext:

If evenchars%2==0

evenchars=evenchars+ch;else oddchars=oddchars+ch;charcount=charcount+1;chipertext=oddchars+evenchars;return chipertext.

B.def scrambledecrpyt(chipertext);halflenth=Len(chipertext)/2;oddchars=chipertext[:halflength];evenchars=chipertext[halflength:]; plaintext="";for I in range(halflength)

Plaintext=plaintext +Evenchars[I];Plaintext=plaintext+oddchars[I];

if Len(oddchars)<Len(evenchars)plaintext=plaintext-evenchars[1];return plaintext

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote