Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BASIC PSEUDOCODE # Given the plaintext, alphabet, cipher # Create a string that will hold the ciphertext # Loop through the plaintext # For every

BASIC PSEUDOCODE # Given the plaintext, alphabet, cipher # Create a string that will hold the ciphertext # Loop through the plaintext # For every character in plaintext # Find its position/index in the alphabet # Get the character at the same index in cipher # Add the cipher-char to the ciphertext string # Return the resulting ciphertext 

You can now update the above pseudocode with the additional checks that are listed in the docstring of the simpleEncode function.

def simpleEncode(plaintext, alphabet, cipher): """ Given plaintext to encode, an alphabet and a cipher alphabet, return the encoded ciphertext. If the lengths of the alphabet and cipher are not the same, return -1. If a character from plaintext is not found in the alphabet, return None. """ return "stub"

I tried to write the code, but it fails to pass the pytest:

def simpleEncode(plaintext, alphabet, cipher): """ Given plaintext to encode, an alphabet and a cipher, return the encoded ciphertext. If the lengths of the alphabet and cipher are not the same, return -1. If a character from plaintext is not found in the alphabet, return None. """ if len(alphabet)!=len(cipher): return -1 ciphertext = "" for char in plaintext: if char not in alphabet: return None for i in range(0,len(alphabet)): if char == alphabet[i]: return ciphertext

Pytest:

def test_simpleEncode_1(): assert simpleEncode('beep beep boop', createAlphabet(), createCipher(createAlphabet())) == '~,,Qf~,,Qf~RRQ' def test_simpleEncode_2(): assert simpleEncode('only these characters have to be in alphabet', 'pq', 'st' ) == None

def test_simpleEncode_3(): assert simpleEncode('only these characters have to be in alphabet', 'onlythescarvbip ', 'pasdfghjklzxcvbn' ) == 'pasdnfghjhnkglzlkfhzjnglxhnfpnchnvanlsbglchf'

def test_simpleEncode_4(): assert simpleEncode('thisIsMyPlainText', 'someAlphabet','wrongLength') == -1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago

Question

Explain the alkaline nature of aqueous solution of making soda.

Answered: 1 week ago

Question

Comment on the pH value of lattice solutions of salts.

Answered: 1 week ago

Question

=+impact member states and MNEs?

Answered: 1 week ago