n = 5496273377454199065242669248583423666922734652724977923256519661692097814683426757178129328854814879115976202924927868808744465886633837487140240744798219 e = 431136 ct = 3258949841055516264978851602001574678758659990591377418619956168981354029697501692633419406607677808798749678532871833190946495336912907920485168329153735
defencrypt(m, e, n):# standard rsa res = pad(m, n) if res != -1: print(f"c: {pow(m, e, n)}") else: print("error :(", "message too long")
menu = """ [1] enc() [2] enc(flag) [3] quit """[1:]
e, n = keygen() print(f"e: {e}") print(f"n: {n}") whileTrue: try: print(menu) opt = input("opt: ") if opt == "1": encrypt(int(input("msg: ")), e, n) elif opt == "2": encrypt(bytes_to_long(open("/challenge/flag.txt", "rb").read()), e, n) elif opt == "3": print("bye") exit(0) else: print("idk") except Exception as e: print("error :(", e)
1
Yeah I use randomized padding, it increases security!Note: This is a part 1 challenge of randompad. Take a look at the source for that one and compare the two for a hint on how to solve.
try: x = int(input('Take a share... BUT ONLY ONE. ')) except: print('Do you know what an integer is?') sys.exit(1) ifabs(x) < 1: print('No.') else: print(sum(map(lambda i: poly[i] * pow(x, i), range(len(poly)))))
from sympy import poly, symbols from collections import deque import Crypto.Random.random as random from Crypto.Util.number import getPrime, bytes_to_long, long_to_bytes
defbuild_poly(coeffs): x = symbols('x') return poly(sum(coeff * x ** i for i, coeff inenumerate(coeffs)))
defencrypt_msg(msg, poly, e, N): return long_to_bytes(pow(poly(msg), e, N)).hex()
p = getPrime(256) q = getPrime(256) N = p * q e = 11
flag = bytes_to_long(open("/challenge/flag.txt", "rb").read())
coeffs = deque([random.randint(0, 128) for _ inrange(16)])
welcome_message = f""" Welcome to RotorSA! With our state of the art encryption system, you have two options: 1. Encrypt a message 2. Get the encrypted flag The current public key is n = {N} e = {e} """
print(welcome_message)
whileTrue: padding = build_poly(coeffs) choice = int(input('What is your choice? ')) if choice == 1: message = int(input('What is your message? '), 16) encrypted = encrypt_msg(message, padding, e, N) print(f'The encrypted message is {encrypted}') elif choice == 2: encrypted_flag = encrypt_msg(flag, padding, e, N) print(f'The encrypted flag is {encrypted_flag}') coeffs.rotate(1)
from functools import reduce from operator import mul from secrets import token_bytes from sys import exit
from Crypto.Util.number import bytes_to_long, getPrime, long_to_bytes
defmain(): a = getPrime(512) b = reduce(mul, [getPrime(64) for _ inrange(12)]) flag = open("flag.txt", 'rb').read() flag_int = bytes_to_long(flag + token_bytes(20)) if flag_int > b: print("this was not supposed to happen") exit() print("Try decrypting this =>", pow(flag_int, a, b)) print("Hint =>", a) print("Thanks for helping me test this out,") print("Now try to break it") for _ inrange(2): inp = int(input(">>> ")) if inp % b in [0, 1, b - 1]: print("No cheating >:(") exit() res = pow(flag_int, inp * a, b) print(res) if res == 1: print(flag)
if __name__ == "__main__": try: main() except Exception: print("oopsie")
#!/usr/bin/env python # -*- coding: utf-8 -*- from functools import reduce from operator import mul from Crypto.Util.number import long_to_bytes from gmpy2 import *
c = 20203085489987560014293976792631284029865794716340199579184268249383267835221417646400206440280554986191046482410144704655493648278552773961629440429092902828200586765600142014056717474264892592819336816357109261631354026033919601 a = 9199145544343906785257237030819067819650706729960940719583789075672838085664891493875966859020683165873915514690329495098632224089726035146839813982911647 res1 = 11556035784052138857307507506198973288367411883788209466242603646975181772393709048116382813114147667439254757077994923530326940311774811806341624846606432421390147764067475588289999480688178793625567838893122456687987320482961046 res2 = 31851104354654545190670904771335276903093012765843101980283420984000643289499190154554669289569530261009163188908584430876887966331849339667406478926717953660650120468017201255286785290943940825754781159249398489654218469154878634 # b = gcd(c**2-res1, c**3-res2) b = 35928904747031491940426212169291743107379982701504027058404714745969854722708017688279836779414010447803620033738718602141821905862755021890356381265244649437631255336699627199559173294827426763360743177116198238833752565119866603 p1 = 9663156357322877677 p2 = 17687198236208397641 p3 = 13483379498110779557 p4 = 9827362203600815249 p5 = 16048195073366111129 p6 = 9608504155966563959 p7 = 17592003464121633761 p8 = 16940133308409174757 p9 = 10013743477508178887 p10 = 18085688756284030699 p11 = 15237723747921143731 p12 = 12510206954070273583 p = [] for i inrange(1, 13): p.append(eval('p'+str(i))) assert b == reduce(mul, [_ for _ in p]) phi = reduce(mul, [_-1for _ in p]) d = invert(a, phi) flag_int = long_to_bytes(pow(c, d, b)) print(flag_int)