일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 파이썬 알고리즘
- 데이터베이스
- 자바 기초
- 오라클
- OS
- 백준
- 오라클DB
- 우분투
- 운영체제
- Reversing
- Python challenge
- 파이썬 챌린지
- 데이터 통신
- C
- 러스트 프로그래밍 공식 가이드
- 파이썬 첼린지
- Database
- java
- data communication
- 러스트
- Rust
- ubuntu
- 알고리즘
- 자바
- 파이썬
- 러스트 예제
- Operating System
- 백준 러스트
- 자바 개념
- Python
- Today
- Total
IT’s Portfolio
[Python Challenge] Level 3 풀이 본문

The Python Challenge
What people have said about us: "These sorts of things are in my opinion the best way to learn a language.", brberg at Media Cloisters "It's the best web site of the year so far.", Andy Todd at halfcooked "Addictive way to learn the ins and outs of Python.
www.pythonchallenge.com
Python Challenge Level 3 풀이이다.

"One small letter, surrounded by EXACTLY three big bodyguards on each of its sides."
=>
"그 양쪽에 정확히 세 명의 큰 경호원들이 둘러쌓인 작은 편지 한 통."
뭔 개소리지?
* 1개의 소문자 옆에 3개의 대문자가 있다는 뜻이라고 한다.
페이지 소스를 봐보자.

Level 2 문제에서 봤던 페이지 소스와 비슷하다.
페이지 소스를 텍스트 파일로 옮겨와 정규표현식으로 추출해보자.
import re
text = open('re.txt', 'r')
data = text.read()
check1 = re.findall("[A-Z]{3}[a-z]{1}", data)
check2 = re.findall("[a-z]{3}[A-Z]{1}", data)
check3 = re.findall("[A-Z]{3}[a-z]{1}[A-Z]{3}", data)
check4 = re.findall("[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}", data)
print(check1)
print(check2)
print(check3)
print(check4)
결과:

check4의 검색결과가 제일 신뢰성있는 것 같다.
check4에 있는 문자열을 추출해보자.
import re
text = open('re.txt', 'r')
data = text.read()
check = ""
check1 = re.findall("[A-Z]{3}[a-z]{1}", data)
check2 = re.findall("[a-z]{3}[A-Z]{1}", data)
check3 = re.findall("[A-Z]{3}[a-z]{1}[A-Z]{3}", data)
check4 = re.findall("[a-z]{1}[A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]{1}", data)
for i in range(0, len(check4)):
check = check + check4[i][4:5]
print(check)
결과:

URL 정답값: linkedlist
최신화
2022.10.20
'''
One small letter, surrounded by EXACTLY three big bodyguards on each of its sides.
'''
import re
from get_html_source import get_html
A = get_html(url="http://www.pythonchallenge.com/pc/def/equality.html")
with open('source.txt', 'wt') as f:
txt = A.get_req().replace('\n', '')
m = re.findall("<!--(.+?)-->", txt)
f.write(m[0])
with open('source.txt', 'rt') as f:
msg = f.read()
m2 = re.findall("[a-z]+[A-Z]{3}([a-z]{1})[A-Z]{3}[a-z]+", msg)
print(''.join(m2))
- for이 아닌 join 사용
- [A-Z]{3}[a-z]{1}[A-Z]{3}: 예시에 적합하지 않은 예외값이 포함되기에 이상한 정답이 나옴
Level 4로 갈 수 있는 URL = http://www.pythonchallenge.com/pc/def/linkedlist.html
'Security Study > Wargame Explanation' 카테고리의 다른 글
[Python Challenge] Level 5 풀이 (2) | 2019.11.24 |
---|---|
[Python Challenge] Level 4 풀이 (0) | 2019.11.24 |
[Python Challenge] Level 2 풀이 (0) | 2019.11.20 |
[Python Challenge] Level 1 풀이 (4) | 2019.11.19 |
[Python Challenge] Level 0 풀이(Warming UP) (0) | 2019.11.19 |