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


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?



When we connect to the service we get the following:

laxa:Challenges:23:46:44$ nc 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:


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:
            return p
    return None

t = telnetlib.Telnet("", 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:

Leave a Reply

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