-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecrypt.py
41 lines (31 loc) · 1.11 KB
/
decrypt.py
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
>>> from Crypto.Cipher import DES
>>> obj=DES.new('abcdefgh', DES.MODE_ECB)
>>> plain="Guido van Rossum is a space alien."
>>> len(plain)
34
>>> obj.encrypt(plain)
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: Strings for DES must be a multiple of 8 in length
>>> ciph=obj.encrypt(plain+'XXXXXX')
>>> ciph
'\021,\343Nq\214DY\337T\342pA\372\255\311s\210\363,\300j\330\250\312\347\342I\3215w\03561\303dgb/\006'
>>> obj.decrypt(ciph)
'Guido van Rossum is a space alien.XXXXXX'
------------------------
from enigma.machine import EnigmaMachine
# setup machine according to specs from a daily key sheet:
machine = EnigmaMachine.from_key_sheet(
rotors='II IV V',
reflector='B',
ring_settings=[1, 20, 11],
plugboard_settings='AV BS CG DL FU HZ IN KM OW RX')
# set machine initial starting position
machine.set_display('WXC')
# decrypt the message key
msg_key = machine.process_text('KCH')
# decrypt the cipher text with the unencrypted message key
machine.set_display(msg_key)
ciphertext = 'NIBLFMYMLLUFWCASCSSNVHAZ'
plaintext = machine.process_text(ciphertext)
print(plaintext)