from given import Pg,Cg defGenerate(key1,key2): global K1 s="" for i in K1: if(i==key1): s+="00" if(i==(255-key1)): s+="01" if(i==key2): s+="10" if(i==(255-key2)): s+="11" assertlen(s)==512 print(s) K1,K2=[],[] for i inrange(len(Pg)): K1.append((Pg[i]^Cg[i])&0xff) K2.append((~Pg[i]^Cg[i])&0xff) print(K1) print(K2) Generate(78,86) Generate(78,169) Generate(177,86) Generate(177,169) Generate(86,78) Generate(86,177) Generate(169,78) Generate(169,177)
from hashlib import md5 from Crypto.Util.number import * from given import Cf x0,r=0.840264,1.2 defgenerate(x): returnround(r*x*(3-x),6) defencrypt(key1,key2,x0,m,n): num = m*n//8 seqs = [] x = x0 bins = '' tmp = [] for i inrange(num): x = generate(x) tmp.append(x) seqs.append(int(x*22000)) for x in seqs: bin_x = bin(x)[2:] iflen(bin_x) < 16: bin_x = '0'*(16-len(bin_x))+bin_x bins += bin_x return bins decstr=encrypt(169,78,0.840264,24,16) Pf=[] for i inrange(len(Cf)): op=int(decstr[i*2:i*2+2],2) #print(op) if(op==0): Pf.append(Cf[i]^169) if(op==1): Pf.append(Cf[i]^86) if(op==2): Pf.append(Cf[i]^78) if(op==3): Pf.append(Cf[i]^177) print(Pf) S=0 for i in Pf: S*=256 S+=i S=long_to_bytes(S) print('CISCN{'+md5(S).hexdigest()+'}') #CISCN{7fa176002ced947e49f1752c1eb9dd62}
from Crypto.Util.number import * from secret import flag p = getPrime(512) q = getPrime(512) n = p * q e = 65537 print(n) print(pow(bytes_to_long(flag) , e , n)) _q = int(bin(q)[2:][::-1] , 2) print(p ^ _q)
from Crypto.Util.number import * from given import e,n,c,a bina=bin(a)[2:] bina='0'*(512-len(bina))+bina defdfs(P,Q,Round): if Round==256: if P*Q==n: global p,q p,q=P,Q return1 for i inrange(2): for j inrange(2): CurP=P+i*(2**(511-Round))+(int(bina[Round])^j)*(2**Round) CurQ=Q+j*(2**(511-Round))+(int(bina[511-Round])^i)*(2**Round) if CurP*CurQ>n: continue if (CurP+2**(511-Round))*((CurQ+2**(511-Round)))<n: continue if (CurP*CurQ)%(2**(Round+1))!=n%(2**(Round+1)): continue dfs(CurP,CurQ,Round+1) return0 #------Main Below------# p,q=None,None dfs(0,0,0) assert p!=Noneand q!=None phi=(p-1)*(q-1) d=inverse(e,phi) print(long_to_bytes(pow(c,d,n)))
import java.math.BigInteger; import java.util.Random; publicclassTest0 { staticBigIntegertwo=newBigInteger("2"); staticBigIntegerp=newBigInteger("11360738295177002998495384057893129964980131806509572927886675899422214174408333932150813939357279703161556767193621832795605708456628733877084015367497711"); static BigInteger h= newBigInteger("7854998893567208831270627233155763658947405610938106998083991389307363085837028364154809577816577515021560985491707606165788274218742692875308216243966916"); /* Alice write the below algorithm for encryption. The public key {p, h} is broadcasted to everyone. @param val: The plaintext to encrypt. We suppose val only contains lowercase letter {a-z} and numeric charactors, and is at most 256 charactors in length. */ publicstatic String pkEnc(String val){ BigInteger[] ret = newBigInteger[2]; BigInteger bVal=newBigInteger(val.toLowerCase(),36); BigIntegerr=newBigInteger(newRandom().nextInt()+""); ret[0]=two.modPow(r,p); ret[1]=h.modPow(r,p).multiply(bVal); return ret[0].toString(36)+"=="+ret[1].toString(36); }
/* Alice write the below algorithm for decryption. x is her private key, which she will never let you know. public static String skDec(String val,BigInteger x){ if(!val.contains("==")){ return null; } else { BigInteger val0=new BigInteger(val.split("==")[0],36); BigInteger val1=new BigInteger(val.split("==")[1],36); BigInteger s=val0.modPow(x,p).modInverse(p); return val1.multiply(s).mod(p).toString(36); } } */ publicstaticvoidmain(String[] args)throws Exception { System.out.println("You intercepted the following message, which is sent from Bob to Alice:"); System.out.println("eag0vit7sboilgcfu0fbkbrmjgs4pzi2oznmqrkey5h1bwicvborngscx050u8vpghi69xqjmotgrtj4vq8fgw9tzi916o034bu==ahcwy7c0qq5cnxdntssqrj972nhvzt5liqlq0cvv0o1fm2ee4205nemuy5tvkda0hyetu5a5xcqqov8exk901z5xebvkcdo3jiq1gj8pkxzhjaeg9z6syu58neijxy56am7d1l9grhgtgkkfc432wm6h3jr8y1xx"); System.out.println("Please figure out the plaintext!"); } } //eag0vit7sboilgcfu0fbkbrmjgs4pzi2oznmqrkey5h1bwicvborngscx050u8vpghi69xqjmotgrtj4vq8fgw9tzi916o034bu==ahcwy7c0qq5cnxdntssqrj972nhvzt5liqlq0cvv0o1fm2ee4205nemuy5tvkda0hyetu5a5xcqqov8exk901z5xebvkcdo3jiq1gj8pkxzhjaeg9z6syu58neijxy56am7d1l9grhgtgkkfc432wm6h3jr8y1xx