Simple Number Theory
from nonebot import on_command, CommandSession
import gmpy2
import random
from CTF.flag import FLAG
from CTF.flow import FLOW,GROUPLIST
def main(x,args):
a,m,c=args
return a*x%m==c
@on_command('SimpleNT', only_to_me=False)
async def SimpleNT(session: CommandSession):
state=session.get("AC")
if state==1:
await session.send("Accepted")
await session.send(FLOW("SimpleNT"))
else:
await session.send("Wrong Answer")
@SimpleNT.args_parser
async def _(session: CommandSession):
if session.ctx.get('group_id') not in GROUPLIST:
return
txt = session.current_arg
if session.is_first_run:
m=int(gmpy2.next_prime(random.randint(2**60, 2**62)))
a=random.randint(2**60, 2**62)
c=random.randint(2**60, 2**62)
session.state['args'] = (a,m,c)
session.state['flag'] = FLAG()
session.state['AC'] = 0
session.pause(f'm={m},a={a},c={c}')
if txt == session.state['flag']:
session.state['AC']=1
return
if txt=="HELP":
session.pause('https://zybuluo.com/Scarlet/note/1696013')
if main(int(txt),session.state['args']):
session.pause
else:
return None