Directions:
# Caesar Cipher Implementation
Your task in this homework is to construct a class to implement Caesar Cipher
## Specification
### __init__() method
Define attributes that may be used in the following methods, such as key.
### Encrypt Message
The objective of the `encrypt()` method is to encrypt a message using Caesar Cipher. The
method should return the encrypted message.
Started function:
```python
def encrypt(self, plaintext):
'''
Task 1: encrypt plaintext using caesar cipher
'''
return True
```
### Decript Message
The objective of the `decrypt()` method is to decrypt a encrypted message using Caesar Cipher.
The method should return the decrypted message.
Started function:
```python
def decrypt(self, ciphertext):
'''
Task 2: decrypt ciphertext using caesar cipher
'''
return True
```
### Encrypt a File
The objective of the `encrypt_file()` method is to encrypt the content in a file using Caesar
Cipher and then write the encrypted content in another file.
Started function:
```python
def encrypt_file(self, input_filename, output_filename):
'''
Task 3: encrypt the content in a file (input_filename) using caesar cipher
and store the ciphertext in another file (output_filename)
'''
pass
```
### Decrypt a file
The objective of the `decrypt_file()` method is to decrypt the content in a file using Caesar
Cipher and then write the decrypted content in another file.
Starter function:
```python
def decrypt_file(self, input_filename, output_filename):
'''
Task 4: decrypt the content in a file (input_filename) using caesar cipher
and store the decrypted text in another file (output_filename)
'''
pass
```
Task:
caesar_cipher.py file
from pathlib import Path
class CaesarCipher:
def __init__(self, key=3):
pass
def encrypt(self, plaintext):
'''
Task 1: encrypt plaintext using caesar cipher
'''
return True
def decrypt(self, ciphertext):
'''
Task 2: decrypt ciphertext using caesar cipher
'''
return True
def encrypt_file(self, input_filename, output_filename):
'''
Task 3: encrypt the content in a file (input_filename) using caesar cipher
and store the ciphertext in another file (output_filename)
'''
pass
def decrypt_file(self, input_filename, output_filename):
'''
Task 4: decrypt the content in a file (input_filename) using caesar cipher
and store the decrypted text in another file (output_filename)
'''
pass
if __name__ == "__main__":
caesar_cipher = CaesarCipher()
print(caesar_cipher.encrypt('This is a secret message! My password is XYZ.'))
print(caesar_cipher.decrypt('Hello ABC!'))
caesar_cipher.encrypt_file('secret_message.txt', 'encrypted_secret_message.txt')
caesar_cipher.decrypt_file('encrypted_secret_message.txt', 'decrypted_text.txt')
decrypted_text.txt file
Hello, this is a secret message!
Your password is NDSCsx&s091TSxsa^
encrypted_secret_message.txt
Khoor, wklv lv d vhfuhw phvvdjh!
Brxu sdvvzrug lv QGVFva&v091WVavd^
test_caesar_cipher.py
import pytest
from pathlib import Path
from caesar_cipher import CaesarCipher
def test_caesar_cipher_1():
cipher = CaesarCipher()
assert cipher.encrypt('Hi, my name is Weiping.') == 'KL, PB QDPH LV ZHLSLQJ.'
assert cipher.decrypt('WKLV LV D VHFUHW PHVVDJH! PB SDVVZRUG LV ABC.') ==
'THIS IS A SECRET MESSAGE! MY PASSWORD IS XYZ.'
def test_caesar_cipher_2():
cipher = CaesarCipher()
cipher.encrypt_file('secret_message.txt', 'encrypted_secret_message.txt')
path = Path('encrypted_secret_message.txt')
assert path.read_text() == 'KHOOR, WKLV LV D VHFUHW PHVVDJH!nBRXU
SDVVZRUG LV QGVFVA&V091WVAVD^n'
cipher.decrypt_file('encrypted_secret_message.txt', 'decrypted_secret_message.txt')
path = Path('decrypted_secret_message.txt')
assert path.read_text() == 'HELLO, THIS IS A SECRET MESSAGE!nYOUR PASSWORD
IS NDSCSX&S091TSXSA^n'

Directions# Caesar Cipher ImplementationYour task in this homew.pdf

  • 1.
    Directions: # Caesar CipherImplementation Your task in this homework is to construct a class to implement Caesar Cipher ## Specification ### __init__() method Define attributes that may be used in the following methods, such as key. ### Encrypt Message The objective of the `encrypt()` method is to encrypt a message using Caesar Cipher. The method should return the encrypted message. Started function: ```python def encrypt(self, plaintext): ''' Task 1: encrypt plaintext using caesar cipher ''' return True ``` ### Decript Message The objective of the `decrypt()` method is to decrypt a encrypted message using Caesar Cipher. The method should return the decrypted message. Started function:
  • 2.
    ```python def decrypt(self, ciphertext): ''' Task2: decrypt ciphertext using caesar cipher ''' return True ``` ### Encrypt a File The objective of the `encrypt_file()` method is to encrypt the content in a file using Caesar Cipher and then write the encrypted content in another file. Started function: ```python def encrypt_file(self, input_filename, output_filename): ''' Task 3: encrypt the content in a file (input_filename) using caesar cipher and store the ciphertext in another file (output_filename) ''' pass ``` ### Decrypt a file
  • 3.
    The objective ofthe `decrypt_file()` method is to decrypt the content in a file using Caesar Cipher and then write the decrypted content in another file. Starter function: ```python def decrypt_file(self, input_filename, output_filename): ''' Task 4: decrypt the content in a file (input_filename) using caesar cipher and store the decrypted text in another file (output_filename) ''' pass ``` Task: caesar_cipher.py file from pathlib import Path class CaesarCipher: def __init__(self, key=3): pass def encrypt(self, plaintext): ''' Task 1: encrypt plaintext using caesar cipher '''
  • 4.
    return True def decrypt(self,ciphertext): ''' Task 2: decrypt ciphertext using caesar cipher ''' return True def encrypt_file(self, input_filename, output_filename): ''' Task 3: encrypt the content in a file (input_filename) using caesar cipher and store the ciphertext in another file (output_filename) ''' pass def decrypt_file(self, input_filename, output_filename): ''' Task 4: decrypt the content in a file (input_filename) using caesar cipher and store the decrypted text in another file (output_filename) ''' pass
  • 5.
    if __name__ =="__main__": caesar_cipher = CaesarCipher() print(caesar_cipher.encrypt('This is a secret message! My password is XYZ.')) print(caesar_cipher.decrypt('Hello ABC!')) caesar_cipher.encrypt_file('secret_message.txt', 'encrypted_secret_message.txt') caesar_cipher.decrypt_file('encrypted_secret_message.txt', 'decrypted_text.txt') decrypted_text.txt file Hello, this is a secret message! Your password is NDSCsx&s091TSxsa^ encrypted_secret_message.txt Khoor, wklv lv d vhfuhw phvvdjh! Brxu sdvvzrug lv QGVFva&v091WVavd^ test_caesar_cipher.py import pytest from pathlib import Path from caesar_cipher import CaesarCipher def test_caesar_cipher_1(): cipher = CaesarCipher() assert cipher.encrypt('Hi, my name is Weiping.') == 'KL, PB QDPH LV ZHLSLQJ.' assert cipher.decrypt('WKLV LV D VHFUHW PHVVDJH! PB SDVVZRUG LV ABC.') == 'THIS IS A SECRET MESSAGE! MY PASSWORD IS XYZ.' def test_caesar_cipher_2(): cipher = CaesarCipher() cipher.encrypt_file('secret_message.txt', 'encrypted_secret_message.txt') path = Path('encrypted_secret_message.txt') assert path.read_text() == 'KHOOR, WKLV LV D VHFUHW PHVVDJH!nBRXU SDVVZRUG LV QGVFVA&V091WVAVD^n' cipher.decrypt_file('encrypted_secret_message.txt', 'decrypted_secret_message.txt') path = Path('decrypted_secret_message.txt')
  • 6.
    assert path.read_text() =='HELLO, THIS IS A SECRET MESSAGE!nYOUR PASSWORD IS NDSCSX&S091TSXSA^n'