### Problem description:```Please select one of flowing options:1 - You send me any message then I will give you corresponding cipher text2 - I show you the challenge flag and you have 3 times to guess the plain textYour choice: 1Your message: aThe cipher text: TUVHQg==...Your choice: 2Nice! Your challenge message: MHGCKGADMEGBIACFONEIIECBMJGMKPAKPPFKJFDAOHECNPHKLHBCPAFFLHBCONEIIJCMOLEOIDCGPGFDKDAGPJFMLIBNPNFILEBBNMHJJKDPNDHGJNDIMKGPIICNOCEHJHDCNEHBOFEALFBAOHECKGADOCEHIGCDMMGJLOBLNLHOJEDBYour guess: ```The server provides 2 functions:1. encrypt any message you provided, output base64 encoded encryption result;2. given encrypted challenge message, 
### Solving:start from basic length 1 string, I got following encryption result (after base64 decoding).```0 JFDA1 JEDB2 JHDC3 JGDD4 JBDE5 JADF6 JDDG7 JCDH8 JNDI9 JMDJA OEEBB OHECC OGEDD OBEEE OAEFF ODEGG OCEHH ONEII OMEJJ OPEKK OOELL OJEMM OIENN OLEOO OKEPP PFFAQ PEFBR PHFCS PGFDT PBFEU PAFFV PDFGW PCFHX PNFIY PMFJZ PPFKa MEGBb MHGCc MGGDd MBGEe MAGFf MDGGg MCGHh MNGIi MMGJj MPGKk MOGLl MJGMm MIGNn MLGOo MKGPp NFHAq NEHBr NHHCs NGHDt NBHEu NAHFv NDHGw NCHHx NNHIy NMHJz NPHK```Some observations:1. all results are of length 4;2. all bytes of output are in range "ABCDEFGHIJKLMNOP"3. the last 2 bytes of each output are in ascending order.
Sounds like hex encoding? OK. replacing 'ABCDEFGHIJKLMNOP‘ with hexidecimal digits, we got:```0 95301 9431...A e441B e742...a c461b c762```1. the output is hex encoding of 2 bytes, and the 2nd byte equals to the input byte.2. the xor of 2 bytes is 0xA5
Now for multi-byte input:```hello MNGIKIANMEGBKIANMHGC cd68a80dc461a80dc762world NCHHLNBIMPGKKDAGMHGC d277bd18cf6aa306c762```1. the output is in group of 4 bytes, 1 group for each input byte;2. each group has the same property as the 1 byte encryption output.
Dropping every other byte, we got:```hello  68 0d 61 0d 62world  77 18 6a 06 62```1. the 1st output byte gives (hex encoded) 1st input byte;2. xor of adjacent output bytes gives the subsequent input bytes.
So here is the decryption function:```# decoding one byte from 4 output bytes.def dec4(w):    w = w.decode('hex')    assert len(w) == 2 and (ord(w[0])^ord(w[1])) == 0xa5    return w[1]
import stringtr = string.maketrans('ABCDEFGHIJKLMNOP', '0123456789abcdef')
# decoding input string.def decrypt(s):    res = s.translate(tr)    c = [dec4(res[i:i+4]) for i in range(0, len(res), 4)]    o = [c[0]]*len(c)    for i in range(1, len(o)):        o[i] = chr(ord(c[i-1])^ord(c[i]))    o = ''.join(o)    return o```
Now apply the decryption to the given flag, and send back the result, we got:> Awesome! Here is the final flag: Good fun with bad crypto