-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_enigma_simple.py
More file actions
62 lines (50 loc) · 1.33 KB
/
test_enigma_simple.py
File metadata and controls
62 lines (50 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
"""
Create and test an Enigma machine encryption and decoding machine
This code is based on the implementation of the Enigma machine in Python
called pyEnigma by Christophe Goessen (initial author) and Cédric Bonhomme
https://github.com/cedricbonhomme/pyEnigma
Created on Tue Feb 5 12:17:02 2019
@author: uqscha22
"""
import enigma
import rotor
# Part A
# Encrypt
engine = enigma.Enigma(
rotor.ROTOR_Reflector_A,
rotor.ROTOR_I,
rotor.ROTOR_II,
rotor.ROTOR_III,
key="ABC",
plugs="AA BB CC DD EE",
)
message = input("Enter a message: ")
print("Message:", message)
secret = engine.encipher(message)
print("Encoded Message:", secret)
# Decrypt
engine = enigma.Enigma(
rotor.ROTOR_Reflector_A,
rotor.ROTOR_I,
rotor.ROTOR_II,
rotor.ROTOR_III,
key="ABC",
plugs="AA BB CC DD EE",
)
decrypted = engine.encipher(secret)
print("Decoded Message:", decrypted)
# Part B
shakesEngine = enigma.Enigma(
rotor.ROTOR_Reflector_A,
rotor.ROTOR_I,
rotor.ROTOR_II,
rotor.ROTOR_III,
key="SSC",
plugs="AA BB CC DD EE",
)
ShakesHorribleMessage = (
"Vxye ajgh D yf? Ptn uluo yjgco L ws nznde czidn. Bsj ccj qdbk qjph wpw ypxvu!"
)
decryptedHorribleMessage = shakesEngine.encipher(ShakesHorribleMessage)
print("Shakes' decrypted message:", decryptedHorribleMessage)