English [Internetwache CTF 2016] [Code 60 – It’s Prime Time] Write Up

Description

It’s Prime Time!
(code60, solved by 388)

Description: We all know that prime numbers are quite important in cryptography. Can you help me to find some?

Service: 188.166.133.53:11059

Resolution

When we connect to the service we get the following:

laxa:Challenges:23:46:44$ nc 188.166.133.53 11059
Hi, you know that prime numbers are important, don't you? Help me calculating the next prime!
Level 1.: Find the next prime number after 4:

So we make the following script:

#!/usr/bin/python

import telnetlib

def find_next_prime(n):
    return find_prime_in_range(n, 2*n)

def find_prime_in_range(a, b):
    for p in range(a, b):
        for i in range(2, p):
            if p % i == 0:
                break
        else:
            return p
    return None

t = telnetlib.Telnet("188.166.133.53", 11059)
print t.read_until('\n'),

while True:
    a = t.read_until('\n')
    print a,
    data = a.split(' ')
    prime = int(data[8].strip()[:-1])
    nprime = find_next_prime(prime + 1)
    t.write(str(nprime) + '\n')
    a = t.read_until('\n')
    print a,

After solving 100 equations we get the flag:
IW{Pr1m3s_4r3_!mp0rt4nt}

Leave a Reply

Your email address will not be published. Required fields are marked *