当前位置: 首页 > news >正文

Flow Over Astronomy (Coding, Math) 答案

问题

题目每次随机生成字串和等式,求解等式并按要求生成结果

解决

Python2

import urllib2
import math

def baseconvert(number, fromdigits, todigits):
    if str(number)[0] == '-':
        number = str(number)[1:]
        neg = 1
    else:
        neg = 0
    # make an integer out of the number
    x = long(0)
    for digit in str(number):
        x = x*len(fromdigits) + fromdigits.index(digit)

    # create the result in base 'len(todigits)'
    res = ""
    while x > 0:
        digit = x % len(todigits)
        res = todigits[digit] + res
        x /= len(todigits)
    if neg:
        res = "-"+res
    return res


req = urllib2.Request('http://www.wechall.net/challenge/anto/FlowOverAstronomy/index.php')
req.add_header('Cookie', 'WC=11892678-47832-mNZZCRgxzLvJx66g')
r = urllib2.urlopen(req)
data = r.read()
##########################################
idx = data.index('Charset: ')
charset = ''
if idx != 0:
    idx += len('Charset: ')
    charset = data[idx:idx+69]
    # print "charset : " + charset
##########################################
idx = data.index('Input Base: ')
InputBase = 0
if idx != 0:
    idx += len('Input Base: ')
    InputBase = int(data[idx:idx+2])
    # print "Input Base : ",InputBase
###########################################
idx = data.index('Solution Base: ')
SolutionBase = 0
if idx != 0:
    idx += len('Solution Base: ')
    SolutionBase = int(data[idx:idx+2])
    # print "Solution Base : ",SolutionBase
###########################################
Equation = ''
idx = data.index('Equation')
# print idx
if idx != 0:
    #attention 0A 09 newline,tab
    idxStart = idx + data[idx:].index('">') + 2
    idxEnd = idxStart + data[idxStart:].index('/div') - 1
    Equation = data[idxStart:idxEnd]
    Equation = Equation.replace('<br/>', '')
    # print Equation
###########################################
CalcCharset = charset[0:InputBase]
# print "Calc charset = " + CalcCharset
###########################################
ResultCharset = charset[0:SolutionBase]
# print "Solution charset = " + ResultCharset
BASE10 = "0123456789"
OldIdx = 0
# print(Equation)
NewIdx = Equation.find(' ')
# print(NewIdx)
inst = ''
opcode = ' '
operand1 = 0
operand2 = 0
result = 0
while OldIdx != NewIdx + 1:
    inst = Equation[OldIdx: NewIdx]
    if inst == '*' or inst == '+':
        opcode = inst
        # print opcode,
    else:
        if result == 0:
            operand1 = int(baseconvert(
                Equation[OldIdx: NewIdx], CalcCharset, BASE10))
            result = operand1
            # print operand1,
        else:
            operand2 = int(baseconvert(
                Equation[OldIdx: NewIdx], CalcCharset, BASE10))
            # print operand2,
            if opcode == '*':
                result *= operand2
            elif opcode == '+':
                result += operand2
            inst = ''
            opcode = ''
            operand1 = 0
            operand2 = 0

    OldIdx = NewIdx + 1
    #in final loop, NewIdx equal the last space, OldIdx equal first letter of the end word
    NewIdx = OldIdx + Equation[OldIdx:].find(' ')

#deal with the last operand
NewIdx = Equation.rfind(' ') + 1
operand2 = int(baseconvert(Equation[NewIdx:], CalcCharset, BASE10))
# print operand2
result += operand2
FinalResult = baseconvert(str(result), BASE10, ResultCharset)
submiturl = 'http://www.wechall.net/challenge/anto/FlowOverAstronomy/index.php?answer=' + FinalResult + '&action=Submit'
req2 = urllib2.Request(submiturl)
req2.add_header('Cookie', 'WC=11892678-47832-mNZZCRgxzLvJx66g')
r2 = urllib2.urlopen(req2)
data2 = r2.read()
print data2
# print FinalResult, result

# idx = data2.find('would have been ') + len('would have been ')
# RealResult = data2[idx: idx + data2[idx:].find('.<')]
# print RealResult, baseconvert(RealResult, ResultCharset, BASE10)

代码的内容很长,但实际上什么都没有。
访问部分HTML页面,读取Charset,input base,solution base,equation,
将读取值转换为十进制数并计算,再转换为Solution Base并提交。

ps:时间有限,暂时不打算将代码转成python3.

注意:网络问题可能会出现超时,多试几次即可。


转载:
http://m.blog.naver.com/dual5651/60131982546

相关文章:

  • Impossible n‘est pas français (Exploit) 答案
  • WeChall htmlspecialchars (Exploit, PHP, XSS)
  • 注意最后一行程序中既有单引号又有双引号.....
  • Python2/3 字符串转16进制 16进制转字符串
  • XSS攻击 eval(location.hash.substr(1)); 笔记
  • Unable to find the wrapper “https“ 解决方法
  • WeChall Towers of Hanoi (Java, Crac... 答案
  • XSS攻击 header(‘Location: ‘.$_GET[‘x‘]); 笔记
  • urllib2.URLError: <urlopen error [Errno 111
  • Stegano Woman (Stegano)答案 Write Up
  • Wechall AUTH me (HTTP, Training)的答案
  • Photoshop cs8 颜色 查看调出 hsb模式滑块
  • Ubuntu18.04 火狐浏览器 一条命令安装flash
  • WeChall Training: Programming 1 WriteUp
  • maven编译后将resources目录写出到主输出目录
  • [NodeJS] 关于Buffer
  • 《网管员必读——网络组建》(第2版)电子课件下载
  • 【mysql】环境安装、服务启动、密码设置
  • Android 初级面试者拾遗(前台界面篇)之 Activity 和 Fragment
  • ES6简单总结(搭配简单的讲解和小案例)
  • Fundebug计费标准解释:事件数是如何定义的?
  • Java 23种设计模式 之单例模式 7种实现方式
  • Objective-C 中关联引用的概念
  • Traffic-Sign Detection and Classification in the Wild 论文笔记
  • TypeScript迭代器
  • 用简单代码看卷积组块发展
  • Salesforce和SAP Netweaver里数据库表的元数据设计
  • 不要一棍子打翻所有黑盒模型,其实可以让它们发挥作用 ...
  • 如何正确理解,内页权重高于首页?
  • # C++之functional库用法整理
  • #FPGA(基础知识)
  • #绘制圆心_R语言——绘制一个诚意满满的圆 祝你2021圆圆满满
  • (8)STL算法之替换
  • (floyd+补集) poj 3275
  • (编程语言界的丐帮 C#).NET MD5 HASH 哈希 加密 与JAVA 互通
  • (六)Hibernate的二级缓存
  • (删)Java线程同步实现一:synchronzied和wait()/notify()
  • (心得)获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列。
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • .NET/C# 使用反射调用含 ref 或 out 参数的方法
  • .NetCore实践篇:分布式监控Zipkin持久化之殇
  • .NET框架设计—常被忽视的C#设计技巧
  • .NET中的Event与Delegates,从Publisher到Subscriber的衔接!
  • ::
  • [ 渗透测试面试篇 ] 渗透测试面试题大集合(详解)(十)RCE (远程代码/命令执行漏洞)相关面试题
  • [ 渗透工具篇 ] 一篇文章让你掌握神奇的shuize -- 信息收集自动化工具
  • [2544]最短路 (两种算法)(HDU)
  • [3D游戏开发实践] Cocos Cyberpunk 源码解读-高中低端机性能适配策略
  • [c#基础]值类型和引用类型的Equals,==的区别
  • [GYCTF2020]Ez_Express
  • [js]- 两个对象的合并(Object.assign)
  • [LeetCode] Max Points on a Line
  • [LeetCode]--61. Rotate List
  • [Node + Docker] 聊聊怎么把 nodeclub 构建成 Docker 镜像