×
Samples Blogs Make Payment About Us 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
Use modular coding in Verilog assignments by breaking the design into smaller modules. This improves readability, simplifies debugging, and allows for easier testing and reuse of code components in larger designs.
News
In 2024, Visual Studio Code now offers enhanced GitHub Copilot integration for faster, while PyCharm has improved debugging and testing tools, making it ideal for Python students​

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.