4 from szyfrow
.pocket_enigma
import *
5 from szyfrow
.support
.utilities
import *
9 return PocketEnigma(1, 'a')
12 assert pe
.wheel_map
== [25, 4, 23, 10, 1, 7, 9, 5, 12, 6, 3, 17, 8, 14, 13, 21, 19, 11, 20, 16, 18, 15, 24, 2, 22, 0]
13 assert pe
.position
== 0
15 def test_wheel_map(pe
):
16 assert pe
.make_wheel_map(pe
.wheel2
) == [2, 3, 0, 1, 22, 8, 15, 12, 5, 10, 9, 13, 7, 11, 16, 6, 14, 25, 20, 21, 18, 19, 4, 24, 23, 17]
18 def test_validate_wheel_map(pe
):
19 pe
.validate_wheel_spec(pe
.wheel2
) == True
21 with pytest
.raises(ValueError):
22 pe
.validate_wheel_spec([])
23 with pytest
.raises(ValueError):
24 pe
.validate_wheel_spec([('a', 'b', 'c')]*13)
25 with pytest
.raises(ValueError):
26 pe
.validate_wheel_spec([('a', 'b')]*13)
28 def test_encipher_letter(pe
):
30 assert pe
.encipher_letter('k') == 'h'
31 assert pe
.position
== 6
35 assert cat([pe
.lookup(l
) for l
in string
.ascii_lowercase
]) == 'udhbfejcpgmokrliwntsayqzvx'
36 assert pe
.lookup('A') == ''
40 assert pe
.position
== 5
42 assert pe
.position
== 6
45 assert pe
.position
== 24
47 assert pe
.position
== 25
49 assert pe
.position
== 0
51 def test_encipher(pe
):
53 assert pe
.encipher('helloworld') == 'kjsglcjoqc'
56 assert pe
.encipher('kjsglcjoqc') == 'helloworld'
58 assert pe
.encipher('helloworld', starting_position
= 'x') == 'egrekthnnf'
60 def test_set_position(pe
):
61 assert pe
.set_position('a') == 0
62 assert pe
.set_position('m') == 12
63 assert pe
.set_position('z') == 25
66 assert pocket_enigma_break_by_crib('kzpjlzmoga', 1, 'h', 0) == ['a', 'f', 'q']
67 assert pocket_enigma_break_by_crib('kzpjlzmoga', 1, 'he', 0) == ['a']
68 assert pocket_enigma_break_by_crib('kzpjlzmoga', 1, 'll', 2) == ['a']
69 assert pocket_enigma_break_by_crib('kzpjlzmoga', 1, 'l', 2) == ['a']
70 assert pocket_enigma_break_by_crib('kzpjlzmoga', 1, 'l', 3) == ['a', 'j', 'n']
71 assert pocket_enigma_break_by_crib('aaaaa', 1, 'l', 3) == []