<gh_stars>0
#!/usr/bin/env python3
from Crypto.Util.number import getPrime
import os

# Local imports
with open('flag.txt','rb') as f:
    FLAG = f.read()
    f.close()

# Key gen
P = getPrime(512//8)
Q = getPrime(256)
R = getPrime(256)
N = P**8 * Q * R
E = 0x10001

def pad_hard(m):
    m <<= 256
    m += int.from_bytes(os.urandom(256//8),'big')
    m += -m % P**2
    m += -m % P**3
    return m

# Pad FLAG
M = pad_hard(int.from_bytes(FLAG,'big'))
print('M < N    :',M < N)
print('M < P**8 :',M < (P**8))
print('M < Q*R  :',M < (Q*R))

# Encrypt FLAG
C = pow(M, E, N)
print('\nn =', N)
print('e =', E)
print('c =', C)

# Hint
F = P**7 * (P-1) * (Q-1) * (R-1)
D = pow(E, -1, F)
print('\nD(C) =',pow(C,D,N))

#----------------------------------------------------
#                       Output
#----------------------------------------------------
# M < N    : True
# M < P**8 : False
# M < Q*R  : False
n = 51214772223826458947343903953001487476278631390021520449180482250318402223871910467589821176474724615270573620128351792442696435406924016685353662124634928276565604574767844305337546301974967758679072483930469188209450741154719808928273796360060047042981437882233649203901005093617276209822357002895662878141
e = 65537
c = 41328763458934302623886982279989290133391941143474825043156612786022747186181626092904440906629512249693098336428292454473471954816980834113337123971593864752166968333372184013915759408279871722264574280860701217968784830530130601590818131935509927605432477384634437968100579272192406391181345133757405127746
M = 36121865463995782277296293158498110427613111962414238045946490101935688033022876541418793886469647898078579120189419552431787379541843120009675223060979171856818401470674058515557901674369835328155371791544935440499813846484080003978652786490718806523938327240659684439275298596339460595405316567186468069580
#!/usr/bin/env python3
from Crypto.Util.number import getPrime
import os

# Local imports
with open('flag.txt','rb') as f:
    FLAG = f.read()
    f.close()

# Key gen
P = getPrime(512//8)
Q = getPrime(256)
R = getPrime(256)
N = P**8 * Q * R
E = 0x10001

def pad_hard(m):
    m <<= 256
    m += int.from_bytes(os.urandom(256//8),'big')
    m += -m % P**2
    m += -m % P**3
    return m

# Pad FLAG
M = pad_hard(int.from_bytes(FLAG,'big'))
print('M < N    :',M < N)
print('M < P**8 :',M < (P**8))
print('M < Q*R  :',M < (Q*R))

# Encrypt FLAG
C = pow(M, E, N)
print('\nn =', N)
print('e =', E)
print('c =', C)

# Hint
F = P**7 * (P-1) * (Q-1) * (R-1)
D = pow(E, -1, F)
print('\nD(C) =',pow(C,D,N))

#----------------------------------------------------
#                       Output
#----------------------------------------------------
# M < N    : True
# M < P**8 : False
# M < Q*R  : False
n = 51214772223826458947343903953001487476278631390021520449180482250318402223871910467589821176474724615270573620128351792442696435406924016685353662124634928276565604574767844305337546301974967758679072483930469188209450741154719808928273796360060047042981437882233649203901005093617276209822357002895662878141
e = 65537
c = 41328763458934302623886982279989290133391941143474825043156612786022747186181626092904440906629512249693098336428292454473471954816980834113337123971593864752166968333372184013915759408279871722264574280860701217968784830530130601590818131935509927605432477384634437968100579272192406391181345133757405127746
M = 36121865463995782277296293158498110427613111962414238045946490101935688033022876541418793886469647898078579120189419552431787379541843120009675223060979171856818401470674058515557901674369835328155371791544935440499813846484080003978652786490718806523938327240659684439275298596339460595405316567186468069580
#!/usr/bin/env python3 # Local imports # Key gen # Pad FLAG # Encrypt FLAG # Hint #---------------------------------------------------- #                       Output #---------------------------------------------------- # M < N    : True # M < P**8 : False # M < Q*R  : False