-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptography.py
More file actions
63 lines (49 loc) · 2.31 KB
/
cryptography.py
File metadata and controls
63 lines (49 loc) · 2.31 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
63
class Cryptography:
crypto = {
"_|": "ㄱ", "|_|": "ㅂ", "|_": "ㄹ",
"=|": "ㅅ", "|=|": "ㄴ", "|=": "ㅈ",
"-|": "ㅁ", "|-|": "ㅇ", "|-": "ㄷ",
"•_|": "ㅊ", "|_•|": " ", "|_•": "ㅍ",
"•=|": "?", "|=•|": "ㅋ", "|=•": "ㅣ",
"•-|": "ㅎ", "|-•|": "!", "|-•": "ㅌ",
":_|": "ㅏ", "|_:|": "ㅛ", "|_:": "ㅕ",
":=|": "ㅜ", "|=:|": "ㅑ", "|=:": "ㅡ",
":-|": "ㅗ", "|-:|": "ㅠ", "|-:": "ㅓ",
'ㄱ': '_|', 'ㅂ': '|_|', 'ㄹ': '|_',
'ㅅ': '=|', 'ㄴ': '|=|', 'ㅈ': '|=',
'ㅁ': '-|', 'ㅇ': '|-|', 'ㄷ': '|-',
'ㅊ': '•_|', ' ': '|_•|', 'ㅍ': '|_•',
'?': '•=|', 'ㅋ': '|=•|', 'ㅣ': '|=•',
'ㅎ': '•-|', '!': '|-•|', 'ㅌ': '|-•',
'ㅏ': ':_|', 'ㅛ': '|_:|', 'ㅕ': '|_:',
'ㅜ': ':=|', 'ㅑ': '|=:|', 'ㅡ': '|=:',
'ㅗ': ':-|', 'ㅠ': '|-:|', 'ㅓ': '|-:'
}
def __init__(self, sentence: str):
self.s = sentence
if self.__is_korean():
self.__separate_sentence()
def __separate_sentence(self):
chosungs = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
jungsungs = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ', 'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ']
jongsungs = ['', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ',
'ㅆ', 'ㅇ', 'ㅈ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
result = []
for char in self.s:
if '가' <= char <= '힣':
code = ord(char) - 44032
jong = code % 28
jung = ((code - jong) // 28) % 21
cho = (((code - jong) // 28) - jung) // 21
result.append(chosungs[cho])
result.append(jungsungs[jung])
result.append(jongsungs[jong])
else:
result.append(char)
return result
# 한글인지 아닌지 판별
def __is_korean(self):
for char in self.s:
if '가' <= char <= '힣':
return True
return False