test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:CTF 作者: calee0219 项目源码 文件源码
def checkFactorDB(n):
    """See if the modulus is already factored on factordb.com,
     and if so get the factors"""
    # Factordb gives id's of numbers, which act as links for full number
    # follow the id's and get the actual numbers

    r = requests.get('http://www.factordb.com/index.php?query=%s' % str(n))
    regex = re.compile("index\.php\?id\=([0-9]+)", re.IGNORECASE)
    ids = regex.findall(r.text)
    # These give you ID's to the actual number
    p_id = ids[1]
    q_id = ids[2]
    # follow ID's
    regex = re.compile("value=\"([0-9]+)\"", re.IGNORECASE)
    r_1 = requests.get('http://www.factordb.com/index.php?id=%s' % p_id)
    r_2 = requests.get('http://www.factordb.com/index.php?id=%s' % q_id)
    # Get numbers
    p = int(regex.findall(r_1.text)[0])
    print(p)
    ans = 1
    n = int(n)
    p = int(p)
    print(n)
    while n % p == 0:
        ans *= p
        n /= p
        print(ans,n, ans*n)
    return (ans, n)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号