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
|
def divide_char(char): num = ord(char) - 0xac00 if num<0: return None cho = num / (21*28) jung = (num % (21*28))/28 jong = num % 28 return cho, jung, jong
def join_char(cho,jung,jong): num = 0xac00 + cho*21*28 + jung *28 + jong return unichr(num)
unicoder = lambda x:unicode(x.decode('utf-8'))
original = [map(unicoder, ["ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ","ㅎ"]), map(unicoder, ["ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ","ㅣ"]), map(unicoder, [" ", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ","ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"])]
replace = [map(unicoder, ["ㅊ", "ㅆ", "ㄴ", "ㄹ", "ㄸ", "ㅍ", "ㅎ", "ㄱ", "ㅃ", "ㄴ", "ㅆ", "ㄷ", "ㄹ", "ㅉ", "ㅁ", "ㅂ", "ㅅ", "ㅇ","ㅈ"]), map(unicoder, ["ㅏ", "ㅐ", "ㅗ", "ㅒ", "ㅔ", "ㅝ", "ㅓ", "ㅑ", "ㅣ", "ㅕ", "ㅙ", "ㅜ", "ㅡ", "ㅜ", "ㅝ", "ㅞ", "ㅏ", "ㅟ", "ㅐ", "ㅢ","ㅘ"]), map(unicoder, [" ", "ㅊ", "ㅆ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄹ", "ㅍ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅎ", "ㄱ", "ㅄ", "ㄴ","ㅆ", "ㄷ", "ㄹ", "ㅁ", "ㅂ", "ㅅ", "ㅇ", "ㅈ"])]
text = "쉬쥩췾뀌초 퓌무피 뷛퓌 쵯쮜피쟈 텨죠 튀츁오 퓌소뮞끄 포졋 홧귀쟈 퓌퍄켸뷔 소죠뱌화 먖 크 포톼야 취귗스 허 뚀욪 토져 롸오 챹뮞 샤초 뮈소쥐 스 포쥦 퓨뮈폐 펴퐡코 셔봐 트쟈 룆즈뵈죶 츺뷔샤소 룆즈뵈숏 퓌퍄켸뷰퐈페 포보퍼 튀쥧취위 슂쟈 꾀처 뽯퓟너 뮈쇼소쥐"
unicoded = unicoder(encrypted) decrypted = u""
stat = {'cho':{}, 'jung' : {},'jong' :{}, 'char' :{} } for i in unicoded: ret = divide_char(i) if not ret: decrypted+=i continue
if i in stat['char']: stat['char'][i]=stat['char'][i]+1 else: stat['char'][i]=1
cho = original_table[0][ret[0]] jung = original_table[1][ret[1]] jong = original_table[2][ret[2]]
if cho in stat['cho']: stat['cho'][cho]=stat['cho'][cho]+1 else: stat['cho'][cho]=1
if jung in stat['jung']: stat['jung'][jung]=stat['jung'][jung]+1 else: stat['jung'][jung]=1
if jong in stat['jong']: stat['jong'][jong]=stat['jong'][jong]+1 else: stat['jong'][jong]=1
new_ret=list() for i in range(3): new_item = replace_table[i][ret[i]] new_ret.append(original_table[i].index(new_item))
decrypted+=join_char(new_ret[0],new_ret[1],new_ret[2])
print decrypted
|