×
Reviews 4.9/5 Order Now

Program To Adjust Your Implementation of The Substitution in Python Assignment Solution

July 08, 2024
Isaac Connolly
Isaac Connolly
🇨🇦 Canada
Python
Isaac Connolly is an adept Python Assignment Expert with 12 years of experience, holding a prestigious Master's degree from a leading institution in Canada.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Always start SQL assignments by understanding the schema and relationships between tables. Use proper indentation and aliases for clarity, and test queries incrementally to catch errors early.
News
Owl Scientific Computing 1.2: Updated on December 24, 2024, Owl is a numerical programming library for the OCaml language, offering advanced features for scientific computing.

Instructions

Objective

Write a python assignment to adjust your implementation of the substitution.

Requirements and Specifications

Description of activity: In this exercise I would like you to adjust your implementation of the substitution (also known as mono-alphabetic) cipher.

Vigenere (also known as poly-alphabetic) cipher attempts to “smoothen out” the plaintext->ciphertext letter frequencies which occur in light of the one-to-one plaintext->ciphertext pairing embodied in the shift cipher.

Vigenere is explained in detail in the version 2 of the book on page 13. Your scheme should still implement all 3 algorithms namely key-generation, encryption, decryption. Ultimately you will use this programming exercise to play a mental game with yourself, where you play part of the sender (Alice), recipient (Bob) and malicious attacker (Eve). The outcome of this exercise is to see for yourself how the letter frequency cryptanalysis of the substitution cipher can be easily corrected via a poly-alphabetic method. Vigenere cipher is not a secure cipher, however in this exercise you do not need to worry and crypto analyse it, all you have to do is show me how the cryptanalysis of Substitution cipher is no longer possible here in the Vigenere cipher.

Source Code

SUBSTITUTION CIPHER def key_map(plaintext_key, encrypted_key): map = {} for i in range(len(plaintext_key)): map[plaintext_key[i]] = encrypted_key[i] return map def encipher(plaintext_key, encrypted_key, text): result = '' map = key_map(plaintext_key, encrypted_key) for c in text: lc = c.lower() if c in map: result += map[lc] return result def decipher(plaintext_key, encrypted_key, text): result = '' map = key_map(plaintext_key, encrypted_key) for c in text: lc = c.lower() for cc in map: if lc == map[cc]: result += cc break return result if __name__ == '__main__': plain_text = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] encrypted_text = ['b', 'e', 'c', 'd', 'f', 'g', 'h', 'z', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'a', 'i'] text = 'Once upon a time' print("Plain Text: ", text) print("Encrypted Text: ", encipher(plain_text, encrypted_text, text)) encrypted = 'jsfbmmampwfcssaqup' print("Plain Text: ", encrypted) print("Encrypted Text: ", decipher(plain_text, encrypted_text, encrypted)) VIGENERE CIPHER def encipher(key, text): result = '' n = len(key) i = 0 for c in text: if not c.isalpha(): result += c else: lc = c.lower() result += chr((ord(lc) + ord(key[i % n].lower()) - 2*ord('a')) % 26 + ord('a')) i += 1 return result def decipher(key, text): result = '' n = len(key) i = 0 for c in text: if not c.isalpha(): result += c else: lc = c.lower() result += chr((ord(lc) - ord(key[i % n].lower()) + 26) % 26 + ord('a')) i += 1 return result if __name__ == '__main__': key = 'cafe' text = 'tellhimaboutme' print("Plain Text: ", text) print("Encrypted Text: ", encipher(key, text)) print() encrypted = 'veqpjiredozxoe' print("Plain Text: ", encrypted) print("Encrypted Text: ", decipher(key, encrypted))

Related Samples

At ProgrammingHomeworkHelp.com, we specialize in offering comprehensive Python assignment support to students. Our platform features a variety of related samples to guide and inspire your own work, ensuring you grasp complex concepts with ease. Whether you're tackling basic syntax or advanced algorithms, our expert team is here to provide the assistance you need to excel. Explore our samples today and see why countless students trust us for their academic success. Visit ProgrammingHomeworkHelp.com for reliable, professional Python assignment help.