-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPolluxCipher.py
54 lines (45 loc) · 1.53 KB
/
PolluxCipher.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
42
43
44
45
46
47
48
49
50
51
52
53
54
## Module Imports
import random
from MorseConverter import MorseConverter
class PolluxCipher:
## Pollux Cipher Key
POLLUX_KEY = 'x.--.x.-x.'
## Pollux Cipher Position
POLLUX_POS = [1,2,3,4,5,6,7,8,9,0]
## Empty Pollux Cipher Dictionary, Basis for Cipher
POLLUX_KEY_DICT = {}
## Initializes and Maps Pollux Cipher Dictionary
for char, pos in zip(POLLUX_KEY, POLLUX_POS):
if char not in POLLUX_KEY_DICT:
POLLUX_KEY_DICT[char] = []
POLLUX_KEY_DICT[char].append(pos)
## Translates Morse Code to Pollux Cipher
@staticmethod # Converts Function to a Static Method
def pollux_encode(morse_value):
result = ''
for code in morse_value:
for key, value in PolluxCipher.POLLUX_KEY_DICT.items():
if code == key:
result += random.choice(value).__str__() + ''
return result
## Translates Pollux Cipher to Plain Text
@staticmethod # Converts Function to a Static Method
def pollux_decode(pollux_value, pollux_key_dict):
morse_value = ''
for num in pollux_value:
for key, value in pollux_key_dict.items():
if int(num) in value:
morse_value += key
return MorseConverter.morse_to_text(morse_value)
## Groups Encoded Pollux Cipher by Five
@staticmethod # Converts Function to a Static Method
def group_by_five(pollux_value):
result = ''
count = 0
for code in pollux_value:
if count == 5:
result += ' '
count = 0
result += code + ''
count += 1
return result