CSAWCTF 2021
#Gotta Decrypt Them All
n = 122210677556715920469489888641269363693199366599255488173988172826554505844409054840356782750585839204246353553753879699378163362496336196111317791953233652238169552637885906298695803346642204941338769369532424723845873686548090743865592912214627795469389269724971994692308036391920187126382118274444019137473
e = 3
c = 152167424273977436702890273274501734012765882487008338973232502170356375148818609621863975256from pwn import *
from Crypto.Util.number import *
import codecs
import base64
p= remote("crypto.chal.csaw.io", 5001)
# Dictionary representing the morse code chart
MORSE_CODE_DICT = { 'A':'.-', 'B':'-...',
'C':'-.-.', 'D':'-..', 'E':'.',
'F':'..-.', 'G':'--.', 'H':'....',
'I':'..', 'J':'.---', 'K':'-.-',
'L':'.-..', 'M':'--', 'N':'-.',
'O':'---', 'P':'.--.', 'Q':'--.-',
'R':'.-.', 'S':'...', 'T':'-',
'U':'..-', 'V':'...-', 'W':'.--',
'X':'-..-', 'Y':'-.--', 'Z':'--..',
'1':'.----', '2':'..---', '3':'...--',
'4':'....-', '5':'.....', '6':'-....',
'7':'--...', '8':'---..', '9':'----.',
'0':'-----', ', ':'--..--', '.':'.-.-.-',
'?':'..--..', '/':'-..-.', '-':'-....-',
'(':'-.--.', ')':'-.--.-'}
# Function to encrypt the string
# according to the morse code chart
def encrypt(message):
cipher = ''
for letter in message:
if letter != ' ':
# Looks up the dictionary and adds the
# correspponding morse code
# along with a space to separate
# morse codes for different characters
cipher += MORSE_CODE_DICT[letter] + ' '
else:
# 1 space indicates different characters
# and 2 indicates different words
cipher += ' '
return cipher
# Function to decrypt the string
# from morse to english
def decrypt(message):
# extra space added at the end to access the
# last morse code
message += ' '
decipher = ''
citext = ''
for letter in message:
# checks for space
if (letter != ' '):
# counter to keep track of space
i = 0
# storing morse code of a single character
citext += letter
else:
i += 1
if i == 2 :
decipher += ' '
else:
decipher += list(MORSE_CODE_DICT.keys())[list(MORSE_CODE_DICT
.values()).index(citext)]
citext = ''
return decipher
def find_invpow(x,n):
high = 1
while high ** n < x:
high *= 2
low = high//2
while low < high:
mid = (low + high) // 2
if low < mid and mid**n < x:
low = mid
elif high > mid and mid**n > x:
high = mid
else:
return mid
return mid + 1
p.recvuntil("Can you decrypt them all to prove yourself?\r\n\r\nWhat does this mean?\r\n")
message = p.recvuntil("\r\n>>",drop= True).decode("utf-8")
message = message.replace('/',' ')
result = decrypt(message)
p.sendline('Pokemon Names')
for i in range(0,5):
p.recvuntil("What does this mean?\r\n")
message2 = p.recvuntil("\r\n>>",drop= True).decode("utf-8")
message2 = message2.replace('/',' ')
result2 = decrypt(message2)
result2 = result2.split(' ')
result2 = result2[:-1]
num1 = list(map(int, result2))
lst = []
for i in num1:
lst.append(chr(i))
mystring = "".join(lst)
vitri = base64.b64decode(mystring)
vitri = vitri .decode("utf-8")
n = vitri .find("c")
vitri = vitri [n+3:]
vitri = int(vitri )
key = codecs.encode(str(long_to_bytes(find_invpow(vitri ,3))), 'rot_13')
key = key [2:-1]
print(key)
p.sendline(key)
p.interactive()#RSA Pop Quiz
*Lời kết:
Last updated