Description:
We all know that prime numbers are quite important in cryptography. Can you help me to find some?Solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Author: Kitwipat Towattana (@icheernoom) | |
# Thank: https://gist.github.com/ldong/808d5403c5e3b19f2f05 | |
from pwn import * | |
import re, sys | |
def find(n): | |
return find_next_prime(n+1) | |
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 | |
r = remote('188.166.133.53', 11059) | |
while True: | |
try: | |
result = r.recvline() | |
log.success(result) | |
problem = r.recvline() | |
log.info(problem) | |
prime = int(re.findall("after (.+):", problem)[0]) | |
ans = find(prime) | |
log.info("{0}".format(ans)) | |
r.send("{0}\r\n".format(ans)) | |
except IndexError: | |
log.success("{0}".format(problem)) | |
sys.exit() | |
''' | |
root@kali:~/Desktop# python code60.py | |
[+] Opening connection to 188.166.133.53 on port 11059: Done | |
[+] 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 5: | |
[*] 7 | |
[+] Yay, that's right! | |
[*] Level 2.: Find the next prime number after 18: | |
[*] 19 | |
[+] Yay, that's right! | |
[*] Level 3.: Find the next prime number after 4: | |
[*] 5 | |
[+] Yay, that's right! | |
...[snip]... | |
[*] Level 98.: Find the next prime number after 793: | |
[*] 797 | |
[+] Yay, that's right! | |
[*] Level 99.: Find the next prime number after 125: | |
[*] 127 | |
[+] Yay, that's right! | |
[*] Level 100.: Find the next prime number after 429: | |
[*] 431 | |
[+] Yay, that's right! | |
[*] IW{Pr1m3s_4r3_!mp0rt4nt} | |
[+] IW{Pr1m3s_4r3_!mp0rt4nt} | |
[*] Closed connection to 188.166.133.53 port 11059 | |
''' |
Flag: IW{Pr1m3s_4r3_!mp0rt4nt}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น