Write-up

[Python Challenge] level 1

ch4rli3kop 2019. 4. 13. 21:58
반응형

python challenge 1

>>> ord('k')
107
>>> ord('m')
109
>>> ord('o')
111
>>> ord('q')
113
>>> ord('e')
101
>>> ord('g')
103

확인해보면 2씩 증가시킨 것을 알 수 있다. 결국, 2씩 증가시킨 ascii 값으로 치환시키라는 뜻인데,

>>> a = '''g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. '''
>>> b = ''
>>> for i in a :
...     if 'a' <= i <= 'z' :
...             c = ord(i) + 2
...             if c > ord('z') :
...                     c -= 26
...             b += chr(c)
...     else :
...             b += i
...
>>> b
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url. "

이렇게 할 수도 있고,

>>> a = '''g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. '''
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> table = string.maketrans('abcdefghijklmnopqrstuvwxyz','cdefghijklmnopqrstuvwxyzab')
>>> d = a.translate(table)
>>> d
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url. "

string.maketrans()을 사용해서 할 수도 있다.

url에 적용하라고 했으니, map을 2씩 치환시키면 된다.

>>> 'map'.translate(table)
'ocr'

table을 계속 사용할 때, 편하긴 함.

next : http://www.pythonchallenge.com/pc/def/orc.html solution : http://www.pythonchallenge.com/pcc/def/ocr.html


반응형

'Write-up' 카테고리의 다른 글

[Python Challenge] level 3  (0) 2019.04.13
[Python Challenge] level 2  (0) 2019.04.13
[Python Challenge] level 0  (0) 2019.04.13
[SuNiNaTas] level 23  (0) 2019.04.13
[SuNiNaTas] level 22  (0) 2019.04.13