python challenge 7

进入页面,得到线索:

it's in the air. look at the letters.

看字母,O2氧气的英文是oxygen,进入页面

import urllib.request
file = open('oxygen.png', 'wb')  
im_data = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/oxygen.png')
file.write(im_data.read())  
file.close() 
 
  

得到图片 “oxygen.png”

很显然,图片中间的灰色区域藏了下一关的线索,百度python图像处理,知道可以使用PIL库

from PIL import Image

image = Image.open('oxygen.png')
使用size获得图片的尺寸
>>> image.size
 
  
(629, 95)
>>> image.mode
'RGBA'
然后就需要检查图像的像素的信息了,对于‘RGB’颜色而言,有三个参数分别代表三种颜色各自的值

使用getpixel(xy)方法得到坐标(x,y)处的像素信息,目的是获得中间条形区域范围

首先检查纵坐标范围,再检查横坐标范围

for i in range(95):
    print(image.getpixel((0,i)),i)
    
(79, 92, 23, 255) 0
(60, 72, 8, 255) 1
(68, 79, 21, 255) 2
(104, 111, 59, 255) 3
(39, 32, 0, 255) 4
(57, 44, 2, 255) 5
(67, 54, 12, 255) 6
(141, 130, 85, 255) 7
(107, 104, 51, 255) 8
(119, 120, 63, 255) 9
(125, 125, 71, 255) 10
(118, 118, 64, 255) 11
(118, 119, 62, 255) 12
(137, 136, 82, 255) 13
(135, 133, 82, 255) 14
(164, 153, 107, 255) 15
(206, 181, 140, 255) 16
(213, 181, 140, 255) 17
(206, 173, 132, 255) 18
(214, 179, 139, 255) 19
(221, 187, 149, 255) 20
(218, 184, 146, 255) 21
(219, 185, 148, 255) 22
(222, 188, 150, 255) 23
(203, 168, 128, 255) 24
(199, 162, 120, 255) 25
(194, 155, 112, 255) 26
(180, 142, 97, 255) 27
(189, 151, 106, 255) 28
(192, 155, 110, 255) 29
(179, 143, 93, 255) 30
(161, 139, 82, 255) 31
(124, 124, 60, 255) 32
(110, 125, 58, 255) 33
(116, 132, 67, 255) 34
(113, 132, 66, 255) 35
(106, 127, 62, 255) 36
(111, 132, 65, 255) 37
(112, 129, 61, 255) 38
(121, 136, 67, 255) 39
(129, 145, 74, 255) 40
(121, 137, 66, 255) 41
(124, 135, 67, 255) 42
(115, 115, 115, 255) 43
(115, 115, 115, 255) 44
(115, 115, 115, 255) 45
(115, 115, 115, 255) 46
(115, 115, 115, 255) 47
(115, 115, 115, 255) 48
(115, 115, 115, 255) 49
(115, 115, 115, 255) 50
(115, 115, 115, 255) 51
(98, 127, 47, 255) 52
(105, 134, 54, 255) 53
(96, 123, 44, 255) 54
(104, 131, 52, 255) 55
(102, 129, 50, 255) 56
(111, 135, 57, 255) 57
(111, 134, 54, 255) 58
(114, 135, 56, 255) 59
(109, 132, 50, 255) 60
(98, 126, 42, 255) 61
(89, 123, 36, 255) 62
(79, 115, 27, 255) 63
(70, 108, 23, 255) 64
(96, 131, 49, 255) 65
(110, 138, 61, 255) 66
(97, 125, 50, 255) 67
(92, 122, 48, 255) 68
(93, 125, 52, 255) 69
(99, 129, 57, 255) 70
(104, 131, 60, 255) 71
(105, 131, 60, 255) 72
(118, 141, 69, 255) 73
(109, 136, 59, 255) 74
(101, 128, 51, 255) 75
(106, 132, 58, 255) 76
(111, 137, 63, 255) 77
(99, 126, 45, 255) 78
(95, 123, 39, 255) 79
(92, 120, 36, 255) 80
(98, 125, 44, 255) 81
(94, 123, 41, 255) 82
(89, 118, 38, 255) 83
(89, 117, 40, 255) 84
(90, 118, 41, 255) 85
(97, 128, 48, 255) 86
(88, 120, 37, 255) 87
(89, 121, 36, 255) 88
(81, 114, 27, 255) 89
(89, 121, 36, 255) 90
(90, 124, 37, 255) 91
(78, 113, 21, 255) 92
(80, 115, 25, 255) 93
(93, 127, 43, 255) 94


 
  可以知道灰色区域的纵坐标范围为43-51,再确定43行来检测横坐标范围: 
  

for i in range(629):
    print(image.getpixel((i,43)),i)


最后面的几行是这样的:

(49, 49, 49, 255) 585
(50, 50, 50, 255) 586
(50, 50, 50, 255) 587
(50, 50, 50, 255) 588
(50, 50, 50, 255) 589
(50, 50, 50, 255) 590
(50, 50, 50, 255) 591
(50, 50, 50, 255) 592
(49, 49, 49, 255) 593
(49, 49, 49, 255) 594
(49, 49, 49, 255) 595
(49, 49, 49, 255) 596
(49, 49, 49, 255) 597
(49, 49, 49, 255) 598
(49, 49, 49, 255) 599
(93, 93, 93, 255) 600
(93, 93, 93, 255) 601
(93, 93, 93, 255) 602
(93, 93, 93, 255) 603
(93, 93, 93, 255) 604
(93, 93, 93, 255) 605
(93, 93, 93, 255) 606
(93, 93, 93, 255) 607
(65, 47, 1, 255) 608
(117, 99, 49, 255) 609
(132, 116, 65, 255) 610
(110, 93, 47, 255) 611
(129, 116, 71, 255) 612
(112, 105, 53, 255) 613
(113, 106, 54, 255) 614
(161, 145, 96, 255) 615
(148, 126, 79, 255) 616
(147, 118, 74, 255) 617
(166, 137, 97, 255) 618
(143, 118, 88, 255) 619
(85, 61, 33, 255) 620
(83, 59, 25, 255) 621
(97, 71, 34, 255) 622
(107, 79, 42, 255) 623
(106, 78, 41, 255) 624
(109, 84, 44, 255) 625
(98, 73, 32, 255) 626
(103, 74, 32, 255) 627
(94, 62, 21, 255) 628

get到横坐标变化规律,从0到607,每7位重复一次,然后把不同的像素信息提取出来:

message = []  
for i in range(0,608,7):  
        message.append(list(image.getpixel((i,43)))[0])

得到:

print(message)
[115, 109, 97, 114, 116, 32, 103, 117, 121, 44, 32, 121, 111, 117, 32, 109, 97, 100, 101, 32, 105, 116, 46, 32, 116, 104, 101, 32, 110, 101, 120, 116, 32, 108, 101, 118, 101, 108, 32, 105, 115, 32, 91, 49, 48, 53, 44, 32, 49, 49, 48, 44, 32, 49, 49, 54, 44, 32, 49, 48, 49, 44, 32, 49, 48, 51, 44, 32, 49, 49, 52, 44, 32, 49, 48, 53, 44, 32, 49, 49, 54, 44, 32, 49, 50, 49, 93]

怀疑是 ASCII码,翻译一下:

answer = ''
for i in message:
    answer += chr(i)
print(answer)
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

又得到了一个数组,再翻译一下:

m = [105, 110, 116, 101, 103, 114, 105, 116, 121]
n = ''
for i in m:
    n += chr(i)
print(n)
integrity

得到答案 integrity

百度翻译:n. 完整;正直,诚实; [计算机]保存;健全


完整代码:

import urllib.request
from PIL import Image

file = open('oxygen.png', 'wb')  
im_data = urllib.request.urlopen('http://www.pythonchallenge.com/pc/def/oxygen.png')
file.write(im_data.read())  
file.close()  

image = Image.open('oxygen.png') 
 
message = []  
for i in range(0,608,7):  
        message.append(list(image.getpixel((i,43)))[0])

answer = ''
for i in message:
    answer += chr(i)
print(answer)



 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(python)