本题是Bacon的变型,原题题目为
Mr. Bacon is back and wants to challenge you again.
This time it is way harder to decode. I have changed the encoder after researching the baconian chiffre on the interwebs.
Note one: We still use a full 26 character encoding.
Note two: X means space as a word separator.
Note three: Your solution is again random and bound to your session.
求解的密文为
bacON's CIpHER OR tHe bacOnIaN CIPHeR iS a meTHoD oF StEGAnoGrApHy (A meThOD Of hidiNG a SecReT meSsAGE aS opposED To A truE CIpHEr) DEvIsEd bY fRaNCiS bacON. a meSsAGe iS cOnCEaled iN The PrEsENtAtIOn oF TeXT, rAtHeR ThaN ITs ContEnt. to EnCoDE a meSSAGE, each leTTEr oF THE pLaiNTEXT IS RePLaced bY a gRoup oF FIvE OF tHe leTtErs 'A' Or 'B'. THIS rEpLACEMEnt IS dOnE ACcOrDING TO The alPHAbeT oF tHe bacONiaN CiPHeR, ShOwn BelOw. notE: A sEcOnD VeRSiOn oF bacON's CIPHEr usEs A UnIQUE cODe fOR each leTtER. iN OTHER WorDs, I aND J Each haS ITS own pATtERN. THe WRiTeR mUst MAKE USe OF Two DiffeREnt typEfaceS FOR ThiS CIPheR. AFTeR PrEpARInG a falSE meSSage WiTH tHe SAMe NUmbeR oF LeTtERS aS All OF tHe aS AnD bS iN tHe REAL, sEcReT meSsAGe, TWo typEfaceS aRE chOSeN, OnE TO rEprEsENT aS AND tHE otHEr BS. tHEn Each leTTeR OF The falSe meSsAge mUst BE prESEntEd iN tHe aPproprIaTe TYPEFace, accORdiNG TO wHEtHeR It stAnDS FOR aN A Or A b. To DEcODE THe meSSage, The REvErsE meTHoD Is AppLIed. each 'TYpEface 1' leTtEr In tHe falSe meSsAge iS RePLAced WiTH AN A aNd each 'TYpEface 2' leTtER iS rEpLaced WItH a b. THE bacONiaN ALPhabeT Is tHeN usED To rECovER THE OrIgiNAl meSSage. aNy MeTHOd OF WRItInG tHe meSSAGE THAT ALLOws two DiSTiNCt rEPREsEntAtIons FOR Each chaRAcTeR caN BE usEd fOr tHE BacOn CIpHEr. BacOn himself prepared a biliteral alphabet[2] for handwritten capital and small letters with each having two alternative forms, one to be used as a and the other as b. this was published as an illustrated plate in his de augmentis scientiarum (the advancement of learning). because any message of the right length can be used to carry the encoding, the secret message is effectively hidden in plain sight. the false message can be on any topic and thus can distract a person seeking to find the real message.
题目中说明的是编码方式不同,因此需要考虑'a’和'b'在文中是如何编码的。
已经说明仍然使用26个字母进行编码,从而仅需要考虑不同字母编码的可能性即可。由于最简单的大小写编码在前面已经使用,所以,这里需要考虑的就是仅使用大写、小写字母或者不考虑大小写,对字母进行13-13分割为a和b编码。
因此,这里首先考虑这三种情况
def bacon():
first_encode = {'A': 'aaaaa', 'B': 'aaaab', 'C': 'aaaba', 'D': 'aaabb', 'E': 'aabaa', 'F': 'aabab', 'G': 'aabba',
'H': 'aabbb', 'I/J': 'abaaa', 'K': 'abaab', 'L': 'ababa', 'M': 'ababb', 'N': 'abbaa', 'O': 'abbab',
'P': 'abbba', 'Q': 'abbbb', 'R': 'baaaa', 'S': 'baaab', 'T': 'baaba', 'U/V': 'baabb', 'W': 'babaa',
'X': 'babab', 'Y': 'babba', 'Z': 'babbb'}
second_encode = {'A': 'aaaaa', 'B': 'aaaab', 'C': 'aaaba', 'D': 'aaabb', 'E': 'aabaa', 'F': 'aabab', 'G': 'aabba',
'H': 'aabbb', 'I': 'abaaa', 'J': 'abaab', 'K': 'ababa', 'L': 'ababb', 'M': 'abbaa', 'N': 'abbab',
'O': 'abbba', 'P': 'abbbb', 'Q': 'baaaa', 'R': 'baaab', 'S': 'baaba', 'T': 'baabb', 'U': 'babaa',
'V': 'babab', 'W': 'babba', 'X': 'babbb', 'Y': 'bbaaa', 'Z': 'bbaab'}
text = input()
text_new = ''
for i in text:
# or i >= 'A' and i <= 'M'
if(i >= 'A' and i <= 'M'):
text_new += 'a'
# or i >= 'N' and i <= 'Z'
elif(i >= 'N' and i <= 'Z'):
text_new += 'b'
else:
continue
# print(text_new)
output = ''
for i in range(0, len(text_new), 5):
a = text_new[i:i + 5]
flag = 0
for key, value in second_encode.items():
if(value == a):
output += key
flag = 1
break
if(flag == 0):
output += ' '
print(output)
上述代码中,通过对text中的字母进行约束,获得不同的编码结果。最后发现,当仅对大写字母编码,且A-M为a,N-Z为b的情况下,可以获得明文信息:
YOUXCANXREADXTHEXHIDDENXMESSAGEXSOXIXWILLXTELLXYOUXTHEXSOLUTIONXWHICHXISXTWELVEXRANDOMXLETTERSXLMGEROMDLRCB
再有,题中说明X表示空格,因此结果为:
YOU CAN READ THE HIDDEN MESSAGE SO I WILL TELL YOU THE SOLUTION WHICH IS TWELVE RANDOM LETTERS LMGEROMDLRCB
最终结果为: LMGEROMDLRCB