import sympy import random from gmpy2 import gcd, invert from Crypto.Util.number import getPrime, isPrime, getRandomNBitInteger, bytes_to_long, long_to_bytes from z3 import * flag = b"MRCTF{xxxx}" base = 65537
def GCD(A): B = 1 for i in range(1, len(A)): B = gcd(A[i-1], A[i]) return B
def gen_p(): P = [0 for i in range(17)] P[0] = getPrime(128) for i in range(1, 17): P[i] = sympy.nextprime(P[i-1]) print("P_p :", P[9]) n = 1 for i in range(17): n *= P[i] p = getPrime(1024) factor = pow(p, base, n) print("P_factor :", factor) return sympy.nextprime(p)
from Crypto.Util.number import* e = n = dp = c = for i inrange(1,65538): if (dp*e-1)%i == 0: if n%(((dp*e-1)//i)+1)==0: p=((dp*e-1)//i)+1 q=n//(((dp*e-1)//i)+1) phi = (p-1)*(q-1) d=inverse(e,phi) m=pow(c,d,n) print(long_to_bytes(m))
ps:这个题目名字好像就是flag捏(
[BJDCTF2020]Polybius
好像是道古典密码捏
题目名字就是这个密码然后懒狗直接找了wp(
emmm没啥好说的不是很难就写个脚本列举出aeiou排列顺序和替换i/j然后找出有意义的序列
[NPUCTF2020]EzRSA
一道神奇的题目(
先看题目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from gmpy2 import lcm , powmod , invert , gcd , mpz from Crypto.Util.number import getPrime from sympy import nextprime from random import randint p = getPrime(1024) q = getPrime(1024) n = p * q gift = lcm(p - 1 , q - 1) e = 54722 flag = b'NPUCTF{******************}' m = int.from_bytes(flag , 'big') c = powmod(m , e , n) print('n: ' , n) print('gift: ' , gift) print('c: ' , c) #输出略(
\(gift\)为\((p-1)\)和\((q-1)\)的最小公倍数,其比特位为2045
而$ φ \(的比特位应为2048位,所以应有\)φ = gift *
i\(其中\) i ∈ ( 4 , 8 ) $
key = "whoami" flag = "flag{********************************}" s = [] t = [] f = "" j = 0 for i inrange(256): s.append(i) t.append(key[i%len(key)]) for i inrange(256): j = (j+s[i]+ord(t[i]))%256 s[i],s[j]=s[j],s[i] for m inrange(38): i = (i+1)%256 j = (j+s[i])%256 s[i], s[j] = s[j], s[i] x = (s[i]+(s[j]%256))%256 f += chr(ord(flag[m])^s[x]) print(f)
key = "whoami" flag = [0x00,0xBA,0x8F,0x11,0x2B,0x22,0x9F,0x51,0xA1,0x2F,0xAB,0xB7,0x4B,0xD7,0x3F,0xEF,0xE1,0xB5,0x13,0xBE,0xC4,0xD4,0x5D,0x03,0xD9,0x00,0x7A,0xCA,0x1D,0x51,0xA4,0x73,0xB5,0xEF,0x3D,0x9B,0x31,0xB3] s = [] t = [] f = "" j = 0 for i inrange(256): s.append(i) t.append(key[i%len(key)]) for i inrange(256): j = (j+s[i]+ord(t[i]))%256 s[i], s[j] = s[j], s[i] i,j = 0,0 for m inrange(38): i = (i+1)%256 j = (j+s[i])%256 s[i], s[j] = s[j], s[i] x = (s[i]+(s[j]%256))%256 f += chr(flag[m] ^ s[x]) print(f)
import Crypto.Util.strxor as xo import libnum, codecs, numpy as np
defisChr(x): iford('a') <= x and x <= ord('z'): returnTrue iford('A') <= x and x <= ord('Z'): returnTrue returnFalse
definfer(index, pos): if msg[index, pos] != 0: return msg[index, pos] = ord(' ') for x inrange(len(c)): if x != index: msg[x][pos] = xo.strxor(c[x], c[index])[pos] ^ ord(' ')
dat = []
defgetSpace(): for index, x inenumerate(c): res = [xo.strxor(x, y) for y in c if x!=y] f = lambda pos: len(list(filter(isChr, [s[pos] for s in res]))) cnt = [f(pos) for pos inrange(len(x))] for pos inrange(len(x)): dat.append((f(pos), index, pos))
c = [codecs.decode(x.strip().encode(), 'hex') for x inopen('Problem.txt', 'r').readlines()]
msg = np.zeros([len(c), len(c[0])], dtype=int)
getSpace()
dat = sorted(dat)[::-1] for w, index, pos in dat: infer(index, pos)
print('\n'.join([''.join([chr(c) for c in x]) for x in msg]))