Search results for 'pythonchallenge'

  1. 2009.12.04 -- pythonchallenge level16
  2. 2009.10.16 -- pythonchallenge level7
  3. 2009.09.21 -- python challenge level6
  4. 2009.08.27 -- python challenge level5
  5. 2009.08.20 -- pythonchallenge level4
  6. 2009.08.19 -- pythonchallenge level3
  7. 2009.08.17 -- pythonchallenge level2
  8. 2009.08.17 -- pythonchallenge level1

pythonchallenge level16

2009. 12. 4. 08:09

http://www.pythonchallenge.com/pc/return/mozart.html

let me get this straight 라는 글귀와 그림 파일 하나가 덩그라니 있다.
이번엔 소스보기를 해도 별다른 힌트가 보이지 않는다.

어쩌라는 걸까 -_-

이젠 이미지를 보면 먼저 getpixel 로 비비게 된다.. 그런데 특이하게도 getpixel로 리턴되는 값이
RGB 형태가 아닌 그냥 숫자 하나 뿐이다. 왜 그런 것일까.

찾아보니 GIF 파일 포맷에서 사용하는 Indexed Color 때문이라는 것을 알 수 있었다.

장미님 블로그 Indexed Color에 대하여
http://blog.daum.net/ms1719/14382711
Indexed Color WIKIPEDIA http://en.wikipedia.org/wiki/Indexed_color

mozart.gif 파일을 크게 확대해보면 한 라인당 하나의 보라색 뭉텡이 들이 있는 것이 보인다.
getpixel 로 한줄 씩 읽어보니 각 라인마다 195라는 5개의 같은 값이 나타났다.

이 값들을 기준으로 정렬해보니 romance 라는 글자가 희미하게 보인다.
(나중에 안 사실이지만 좀 틀린 부분이 있었다-_-;;)

import Image

im =Image.open("mozart.gif")
im_new = Image.new('RGB',(640,480))

x = im.size[0]
y = im.size[1]

for j in range(y):
        for i in range(x):
                pix = im.getpixel((i,j))
                if pix == 195:
                        num = i
                        break
                
        for a in range(x):
                if num == x:
                        num = 0
                pix = im.getpixel((num,j))
                im_new.putpixel((a,j),pix)
                num += 1
        
im_new.save('result.gif')


http://www.pythonchallenge.com/pc/return/romance.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level 17  (1) 2010.10.27
pythonchallenge level 15  (0) 2009.12.03
pythonchallenge level14  (0) 2009.11.17
pythonchallenge level13  (0) 2009.10.22
pythonchallenge level12  (0) 2009.10.22
pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16

badcob War game/pythonchallenge

pythonchallenge level7

2009. 10. 16. 02:12

http://www.pythonchallenge.com/pc/def/hockey.html

문제의 링크에는  it's in the air. look at the letters. 라고 적혀있다.
공기중에 있는것. oxygen를 url로 입력해보았다.

http://www.pythonchallenge.com/pc/def/oxygen.html

가운데 회색 바가 수상해 보이는 그림 파일 하나가 나온다. Python Imaging Library (PIL)를 사용해
회색 바 부분만을 뽑아내 보자. getpixel method를 사용하면 픽셀별로 RGB값을 튜플로 얻어낼 수 있다.

The Other RGB Color Chart (http://www.tayloredmktg.com/rgb/)에 보면 Gray의 RGB 코드는
190-190-190 이다. 먼저 그림의 세로 픽셀을 조사해서 190-190-190이 나오는 부분을 찾은 뒤에
가로 픽셀을 조사해서 RGB 코드가 다른 값이 나오는 부분까지 구한다. 그렇게 구한 회색바 픽셀들의
RGB 값을 chr 함수로 캐릭터로 바꾸면 읽을 수 있는 문자열들이 보인다.

사용한 코드는 아래와 같다.

import Image
im = Image.open("oxygen.png")
print im.size
x = im.size[0]
y = im.size[1]
print x,y

i=0
j=0
while i < y:
      pix1 = im.getpixel((0,i))
      if pix1[0] == pix1[1] == pix1[2]:
          break
      i += 1

while j < x:
    pix2 = im.getpixel((j,i))
    if not pix2[0] == pix2[1] == pix2[2]:
        break
    j += 1
    
print j,i

temp = ''
result = ''

for a in range(0,j,7):
  pixel = im.getpixel((a,i))
  temp = chr(pixel[1])
  result +=temp
print result



위의 코드를 실행하면 반복된 문자열들이 나타난다.

sssssmmmmmmmaaaaaaarrrrrrrttttttt       ggggggguuuuuuuyyyyyyy,,,,,,,      
yyyyyyyooooooouuuuuuu       mmmmmmmaaaaaaadddddddeeeeeee       iiiiiiittttttt.......      
ttttttthhhhhhheeeeeee       nnnnnnneeeeeeexxxxxxxttttttt       llllllleeeeeeevvvvvvveeeeeeelllllll   
   
이것은 for문에서 range(0,j,7) 이렇게 바꿔서 깔끔하게 볼 수 있었다.

smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

숫자들을 캐릭터로 바꿔보면 integrity 임을 알 수 있다.

http://www.pythonchallenge.com/pc/def/integrity.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level12  (0) 2009.10.22
pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17

badcob War game/pythonchallenge

python challenge level6

2009. 9. 21. 01:25

 http://www.pythonchallenge.com/pc/def/channel.html

지퍼가 반집 열려있는 사진 한장을 달랑 볼 수 있다. 소스를 보니 zip 이라는 단어가 적혀 있었다.
혹시나 해서 아래의 url 을 입력해 보았다.
http://www.pythonchallenge.com/pc/def/zip.html

yes. find the zip.  

zip 파일을 찾으란다. 몇번의 삽질 끝에

http://www.pythonchallenge.com/pc/def/
channel.zip 에서 파일을 받을 수 있었다.

이 압축파일안에는 텍스트 파일들이 들어있는데 그안에는 숫자들이 적혀있다.
Readme 파일을 읽어보면 앞서 풀었던 문제와 거의 유사한 형태임을 알 수 있다.
90052부터 순서대로 파일을 읽어나가던 중 한가지 문제에 봉착했다.

숫자 대신에 Collect the comments 라는 글귀가 적혀있는 것이다. 한참 골머리를 앓다가
빵집으로 열어서 봤더니 설명 탭에 한글자씩 적혀있는것이 보인다.  아 이게 comment 구나 싶어
한글자씩 모아서 합쳐보았더니 hockey 라는 단어가 화면에 크게 출력되었다.

import zipfile
import re

def get_comment(file_name):
    tmp = file.getinfo(file_name)
    return tmp.comment
    
try:
    file = zipfile.ZipFile("channel.zip","r")
    nothing = '90052'
    txt = '.txt'
    result = ''

    while 1:
        name = nothing + txt
        data = file.read(name)
        temp = re.findall("[0-9]+",data)
        nothing = temp[0]
        result += get_comment(name)
    
except:
    print ''
    print result
 


포인트는 zipfile 인스턴스를 만든후 getinfo method로 comment attributes를 뽑아내면 된다. 

http://www.pythonchallenge.com/pc/def/hockey.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

python challenge level5

2009. 8. 27. 00:20

http://www.pythonchallenge.com/pc/def/peak.html

pronounce it 이라고 적혀진 페이지가 있다.

소스를 보면 아래의 내용을 볼 수 있다.

<peakhell src="banner.p"/>
<!-- peak hell sounds familiar ? -->

banner.p
파일을 다운받아서 보았지만 별다른 힌트는 없어보였다
peakhell 이 도대체 뭘까.. 이리저리 고민하다가 forum의 hint 페이지를 찾아보았다.
(http://www.pythonchallenge.com/forums/)

힌트 없냐는 말에 누군가가 "Try browsing "Global Modules Index" 라는 코멘트를 달아놓았다.

Global Module 중에 peakhell과 비슷한 발음이 나는 녀석을 찾다보니 PICKLE 이라는 녀석이 있었다.

PICKLE 에 대한 설명은 http://docs.python.org/library/pickle.html 에서 볼 수 있다.
간략히 말하면 pickle module은 python object serialization 으로 파이썬 객체를  바이트 스트림으로 바꿀 수 있다. (unplckling 이라 하면 이 반대의 과정을 의미한다)

이점에 착안해서 banner.p를 읽어와서 이를 unpickling 해보았다.


import pickle

f = open("banner.p",'rb')
result = pickle.load(f)
list_length = len(result)
i=0
temp = ()
while i < list_length:
	tuple_length  = len(result[i])
	j = 0
	word = ''
	while j < tuple_length: 
		temp = result[i][j]
		j+=1
		k = 0
		while k < temp[1]:
			if temp[0] ==' ':
				word += ' ' 				
			else:
				word += temp[0]
			k+=1
	print word
	i+=1


코드를 수행하면 banner command를 실행한 것처럼 channel 이라고 크게 찍히는 문자열을 볼 수 있다.

http://www.pythonchallenge.com/pc/def/channel.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level4

2009. 8. 20. 02:01

http://www.pythonchallenge.com/pc/def/linkedlist.php

소스 보기를 하면 level4의 힌트가 적혀있다

urllib may help. DON'T TRY ALL NOTHINGS, since it will never end.
400 times is more than enough.


화면에 있는 그림을 클릭했더니 get 메소드로 nothing 이라는 값에12345를 넘겨주며 (<a href="linkedlist.php?nothing=12345">) nothing의 다음 값을 알려준다.

and the next nothing is 92512

이처럼 페이지에 나온 문자열을 정규표현식으로 파싱해서 nothing에 집어넣은후 계속 쿼리를 날려보았다.
중간 중간에 나오는 트릭에 대한 처리를 하면서  peak.html 이라고 나오는 것을 확인하였다.

http://www.pythonchallenge.com/pc/def/peak.html


import urllib
import re

def get_page(number):
	while 1:
		i = 0
	 	url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s" % number
	 	f = urllib.urlopen(url)
		print url
		file = f.read()
		print file
		text = re.findall("next nothing is \d+",file)
		if text:
			text_last = text[0]
			number_list = re.findall("[0-9]+",text_last)
			number = ''
			while 1:
				number += number_list[i]
				i +=1
				if i == len(number_list): break
		else:
			text = re.findall("Yes", file)
			if text:
				number = 92118/2
			else:
				break
				
num = 12345
get_page(num) 




'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level3

2009. 8. 19. 20:22

http://www.pythonchallenge.com/pc/def/equality.html

3번문제의 힌트는 아래와 같다. 소스를 살펴보면 level2 와 비슷하게 매우 긴 문자열을 볼 수 있다.

One small letter, surrounded by EXACTLY three big bodyguards on each of its sides

글자 그대로 해석하면 원하는 문자열은 XXXxXXX 형태일 것이다.  Forum에 올라온 힌트는 정규식을 이용
하라고 나와있다. 가깝고도 먼 그대.. 정규표현식T_T

[A-Z]{3}[a-z][A-Z]{3} 요런식으로 만들어서 매칭시켜보니 무려 477개나 되는 문자가
발견되었다. 힌트를 곰곰히 읽어보니 Exactly 가 유독 대문자로 써 있다. 이말은 대문자의 갯수가 정확히
3개 여야 한다는 뜻이다. 따라서 xXXXxXXXx 요런 형태로 다시 찾아보았다.

import re

str = """ ......................."""

keyword = re.findall("[a-z][A-Z]{3}[a-z][A-Z]{3}[a-z]",str)

i = 0
word = ''
temp = ''
length = len(keyword)
while 1:
         temp = keyword[i]
	word += temp[4]
	i+=1
	if i == length: break

print word


위의 코드를 실행하면 최종 문자열로 linkedlist 가 찍힌다.

http://www.pythonchallenge.com/pc/def/linkedlist.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level2  (0) 2009.08.17
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level2

2009. 8. 17. 20:34

level 2 : http://www.pythonchallenge.com/pc/def/ocr.html
--------------------------------------------------------------------------
Hint :
recognize the characters. maybe they are in the book,
but MAYBE they are in the page source.

--------------------------------------------------------------------------
웹페이지의 소스를 보니  특수문자들로 보이는 엄청 긴 문자열이 있고

<!--
find rare characters in the mess below:
-->

라는 주석을 볼 수 있다.

특수 문자들 사이에 있는 알파릭 문자들을 뽑아내 보았다.


str = """%%$@_$^__#)^....."""

answer = ''i=0
while 1:
 if ord(str[i]) > 96 and ord(str[i]) < 123: answer += str[i]
 i+=1
 if i == len(str): break
print answer 


숨어있는 문자들은 equality

http://www.pythonchallenge.com/pc/def/equality.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level1  (0) 2009.08.17

badcob War game/pythonchallenge

pythonchallenge level1

2009. 8. 17. 18:26

사이트 url은 이곳이며 level1은 여기를 클릭.

everybody thinks twice before solving this.

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.

위와 같은 글귀와

K -> M
O -> Q
E -> G

라고 적혀진 노트를 볼 수 있다. 아스키 코드를 2씩 증가시키므로 

......
    word += chr(ord(txt[i])+ 2)
  i+=1
  if i == length : break
 return word

이런식으로 만들어서 디코딩을 해봤더니 아래와 같은 문장을 볼 수 있었다.
-----------------------------------------------------------------------------------------------
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.maketr
ans() is recommended. now apply on the url
------------------------------------------------------------------------------------------------
그냥 끝내기가 멋적어서 string.maketrans를 써서 다시 만든 코드.


import string

def decode_str(txt):
 word = ''
 firstchar = string.uppercase + string.lowercase
 secondchar = '{'+'}'
 move_str1 = string.maketrans(firstchar, "CDEFGHIJKLMNOPQRSTUVWXYZ[\cdefghijklmnopqrstuvwxyz{}") 
 move_str2 = string.maketrans(secondchar,"ab")
 word = txt.translate(move_str1) 
 return word.translate(move_str2)

str = "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"
#str = "http://www.pythonchallenge.com/pc/def/map.html"

answer = ''
answer = decode_str(str)
print answer


힌트를 따라서 url에 적용한뒤 주소창에 입력. (map.html)
http://www.pythonchallenge.com/pc/def/ocr.jvon

Have you ever heard of jvon files !?

jvon 확장자라..들어본적 없다. 구글링을 해봐도 나오지 않았다;
혹시나해서 ocr.html로 입력했더니 level2 페이지를 볼 수 있었다.
http://www.pythonchallenge.com/pc/def/ocr.html

'War game > pythonchallenge' 카테고리의 다른 글

pythonchallenge level11  (0) 2009.10.22
pythonchallenge level10  (0) 2009.10.20
pythonchallenge level9  (0) 2009.10.16
pythonchallenge level8  (0) 2009.10.16
pythonchallenge level7  (0) 2009.10.16
python challenge level6  (0) 2009.09.21
python challenge level5  (0) 2009.08.27
pythonchallenge level4  (0) 2009.08.20
pythonchallenge level3  (0) 2009.08.19
pythonchallenge level2  (0) 2009.08.17

badcob War game/pythonchallenge