-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge.txt
97 lines (74 loc) · 4.21 KB
/
challenge.txt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Beaufort Cipher
Introduction:
The Beaufort cipher, created by Sir Francis Beaufort, is a polyalphabetic substitution cipher
that is similar to the Vigenère cipher, except that it enciphers characters in a slightly
different manner.
The Algorithm:
The 'key' for a beaufort cipher is a key word. e.g. 'MONTY_PYTHON'
The beaufort cipher uses the following tableau (the 'tabula recta') to encipher the plaintext:
EDIT: tableu modified to add '_' for spacing
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 _
-----------------------------------------------------
A 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 _
B 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 _ A
C C D E F G H I J K L M N O P Q R S T U V W X Y Z _ A B
D D E F G H I J K L M N O P Q R S T U V W X Y Z _ A B C
E E F G H I J K L M N O P Q R S T U V W X Y Z _ A B C D
F F G H I J K L M N O P Q R S T U V W X Y Z _ A B C D E
G G H I J K L M N O P Q R S T U V W X Y Z _ A B C D E F
H H I J K L M N O P Q R S T U V W X Y Z _ A B C D E F G
I I J K L M N O P Q R S T U V W X Y Z _ A B C D E F G H
J J K L M N O P Q R S T U V W X Y Z _ A B C D E F G H I
K K L M N O P Q R S T U V W X Y Z _ A B C D E F G H I J
L L M N O P Q R S T U V W X Y Z _ A B C D E F G H I J K
M M N O P Q R S T U V W X Y Z _ A B C D E F G H I J K L
N N O P Q R S T U V W X Y Z _ A B C D E F G H I J K L M
O O P Q R S T U V W X Y Z _ A B C D E F G H I J K L M N
P P Q R S T U V W X Y Z _ A B C D E F G H I J K L M N O
Q Q R S T U V W X Y Z _ A B C D E F G H I J K L M N O P
R R S T U V W X Y Z _ A B C D E F G H I J K L M N O P Q
S S T U V W X Y Z _ A B C D E F G H I J K L M N O P Q R
T T U V W X Y Z _ A B C D E F G H I J K L M N O P Q R S
U U V W X Y Z _ A B C D E F G H I J K L M N O P Q R S T
V V W X Y Z _ A B C D E F G H I J K L M N O P Q R S T U
W W X Y Z _ A B C D E F G H I J K L M N O P Q R S T U V
X X Y Z _ A B C D E F G H I J K L M N O P Q R S T U V W
Y Y Z _ A B C D E F G H I J K L M N O P Q R S T U V W X
Z Z _ 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
_ _ 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
To encipher a message, repeat the keyword above the plaintext:
MONTY_PYTHONMONTY_PYTHONMONTY_PYTHONMONT
HES_NOT_A_MESSIAH_HES_A_VERY_NAUGHTY_BOY
(The following assumes we are enciphering the plaintext letter H with the key letter M)
Now we take the letter we will be encoding, and find the column on the tableau, in this case the 'H'
column. Then, we move down the 'H' column of the tableau until we come to the key letter, in this case
'M'. Our ciphertext character is then read from the far left of the row our key character was in, i.e.
with 'H' plaintext and 'M' key, our ciphertext character is 'F'.
So, the ciphertext for the above plaintext is:
MONTY_PYTHONMONTY_PYTHONMONTY_PYTHONMONT
HES_NOT_A_MESSIAH_HES_A_VERY_NAUGHTY_BOY
FKWULMXZTICJVXFTRAIUBIOOSKXWZNPENAWQNN_W
Deciphering is performed in an identical fashion, i.e. encryption and decryption using the beaufort cipher uses same algorithm.
Python CHALLENGE:
create a function that will take 2 string arguments - encrypted message and a key, eg:
def beaufort_cipher(message, key):
and return a decrypted message in a string format.
couple of things to note:
1. only capital letters of english alphabet and '_' to define 'space' will be used
2. it is possible that in some scenarios key is longer than the message
for added fun of it will also rate your solution by lenght of your code based on this formula:
1-3 lines A+
4-7 lines A
8-12 lines B
13-16 lines C
17-20 lines D
20+ lines F
notes:
- only lines between (def "your_function_name") and (return answer) will be counted
hovewer, it will still count towards the score if "return" line is longer than 72 chars ... cheaters ;)
- lines beginning with '#' will be ignored
- blank lines will be ignored
- 1 char lines will be ignored.. e.g. to account for closing/opening brackets or parenthesises
- lines longer than 72 characters will add up as up-rounded multiples of that number to the rating score.. 'cause PEP8
test harness can be found in main repository as 'beaufort_cipher_test_harness.py'.
good luck and good code!