<jupyter_start><jupyter_text>This is my workspace for crypto challenges from hackthebox<jupyter_code>import string
from secret import MSG

def encryption(msg):
    ct = []
    for char in msg:
        ct.append((123 * char + 18) % 256)
    return bytes(ct)

ct = encryption(MSG)
f = open('./msg.enc','w')
f.write(ct.hex())
f.close()

x = "<KEY>"
x = bytes.fromhex(x)
# I know that the values are just shifted.
x = list(x)
print(x)
my_dict = {}
for i in range(33,126):
  my_dict.update({(i*123 + 18)%256 : i})
print(my_dict)
for i in x:
  if i in my_dict:
    print(chr(my_dict.get(i)), end='')
!pip install pycrypto
from Crypto.Util.number import getPrime, long_to_bytes, inverse
flag = open('flag.txt', 'r').read().strip().encode()

class RSA:
    def __init__(self):
        self.p = getPrime(512)
        self.q = getPrime(512)
        self.e = 3
        self.n = self.p * self.q
        self.d = inverse(self.e, (self.p-1)*(self.q-1))
    def encrypt(self, data: bytes) -> bytes:
        pt = int(data.hex(), 16)
        ct = pow(pt, self.e, self.n)
        return long_to_bytes(ct)
    def decrypt(self, data: bytes) -> bytes:
        ct = int(data.hex(), 16)
        pt = pow(ct, self.d, self.n)
        return long_to_bytes(pt)

def main():
    crypto = RSA()
    print ('Flag:', crypto.encrypt(flag).hex())

if __name__ == '__main__':
    main()
# this is the flag encrypted output.
# can you recover the modulus?
flag = "05c61636499a82088bf4388203a93e67bf046f8c49f62857681ec9aaaa40b4772933e0abc83e938c84ff8e67e5ad85bd6eca167585b0cc03eb1333b1b1462d9d7c25f44e53bcb568f0f05219c0147f7dc3cbad45dec2f34f03bcadcbba866dd0c566035c8122d68255ada7d18954ad604965"
flag = list(bytes.fromhex(flag))
flagstr = ''.join(chr(i) for i in flag)<jupyter_output>Æ6Iô8©>g¿oIö(WhÉªª@´w)3à«È>ÿgå­½nÊu°Ìë3±±F-|%ôNS¼µhððRÀ}ÃË­EÞÂóO¼­ËºmÐÅf\"ÖU­§ÑT­`Ie
{'fraction_non_alphanumeric': 0.16004296455424274, 'fraction_numerical': 0.09774436090225563, 'mean_word_length': 3.864229765013055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '482644', 'license': 'MIT', 'n_tokens_mistral': 915, 'n_tokens_neox': 814, 'n_words': 157, 'path': 'htbcrypto.ipynb', 'repo_name': 'JuanARoig/crypto-workspace', 'size': '2017'}