Last active
March 21, 2016 14:46
-
-
Save e-yes/8bf7dc9a2484121cba0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Many Time Pad | |
Let us see what goes wrong when a stream cipher key is used more than once. | |
Below are eleven hex-encoded ciphertexts that are the result of encrypting eleven plaintexts with a stream cipher, | |
all with the same stream cipher key. | |
Your goal is to decrypt the last ciphertext, and submit the secret message within it as solution. | |
Hint: XOR the ciphertexts together, and consider what happens when a space is XORed with a character in [a-zA-Z]. | |
''' | |
CIPHERS = ( | |
bytearray.fromhex('315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b16349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba5025b8cc57ee59418ce7dc6bc41556bdb36bbca3e8774301fbcaa3b83b220809560987815f65286764703de0f3d524400a19b159610b11ef3e'), | |
bytearray.fromhex('234c02ecbbfbafa3ed18510Abd11fa724fcda2018A1a8342cf064bbde548b12b07df44ba7191d9606Ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb74151f6d551f4480c82b2cb24cc5b028aa76eb7b4ab24171ab3cdadb8356f'), | |
bytearray.fromhex('32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de81230b59b7afb5f41afa8d661cb'), | |
bytearray.fromhex('32510ba9aab2a8a4fd06414fb517b5605cc0aa0dc91a8908c2064ba8ad5ea06a029056f47a8ad3306ef5021eafe1ac01a81197847a5c68a1b78769a37bc8f4575432c198ccb4ef63590256e305cd3a9544ee4160ead45aef520489e7da7d835402bca670bda8eb775200b8dabbba246b130f040d8ec6447e2c767f3d30ed81ea2e4c1404e1315a1010e7229be6636aaa'), | |
bytearray.fromhex('3f561ba9adb4b6ebec54424ba317b564418fac0dd35f8c08d31a1fe9e24fe56808c213f17c81d9607cee021dafe1e001b21ade877a5e68bea88d61b93ac5ee0d562e8e9582f5ef375f0a4ae20ed86e935de81230b59b73fb4302cd95d770c65b40aaa065f2a5e33a5a0bb5dcaba43722130f042f8ec85b7c2070'), | |
bytearray.fromhex('32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd2061bbde24eb76a19d84aba34d8de287be84d07e7e9a30ee714979c7e1123a8bd9822a33ecaf512472e8e8f8db3f9635c1949e640c621854eba0d79eccf52ff111284b4cc61d11902aebc66f2b2e436434eacc0aba938220b084800c2ca4e693522643573b2c4ce35050b0cf774201f0fe52ac9f26d71b6cf61a711cc229f77ace7aa88a2f19983122b11be87a59c355d25f8e4'), | |
bytearray.fromhex('32510bfbacfbb9befd54415da243e1695ecabd58c519cd4bd90f1fa6ea5ba47b01c909ba7696cf606ef40c04afe1ac0aa8148dd066592ded9f8774b529c7ea125d298e8883f5e9305f4b44f915cb2bd05af51373fd9b4af511039fa2d96f83414aaaf261bda2e97b170fb5cce2a53e675c154c0d9681596934777e2275b381ce2e40582afe67650b13e72287ff2270abcf73bb028932836fbdecfecee0a3b894473c1bbeb6b4913a536ce4f9b13f1efff71ea313c8661dd9a4ce'), | |
bytearray.fromhex('315c4eeaa8b5f8bffd11155ea506b56041c6a00c8a08854dd21a4bbde54ce56801d943ba708b8a3574f40c00fff9e00fa1439fd0654327a3bfc860b92f89ee04132ecb9298f5fd2d5e4b45e40ecc3b9d59e9417df7c95bba410e9aa2ca24c5474da2f276baa3ac325918b2daada43d6712150441c2e04f6565517f317da9d3'), | |
bytearray.fromhex('271946f9bbb2aeadec111841a81abc300ecaa01bd8069d5cc91005e9fe4aad6e04d513e96d99de2569bc5e50eeeca709b50a8a987f4264edb6896fb537d0a716132ddc938fb0f836480e06ed0fcd6e9759f40462f9cf57f4564186a2c1778f1543efa270bda5e933421cbe88a4a52222190f471e9bd15f652b653b7071aec59a2705081ffe72651d08f822c9ed6d76e48b63ab15d0208573a7eef027'), | |
bytearray.fromhex('466d06ece998b7a2fb1d464fed2ced7641ddaa3cc31c9941cf110abbf409ed39598005b3399ccfafb61d0315fca0a314be138a9f32503bedac8067f03adbf3575c3b8edc9ba7f537530541ab0f9f3cd04ff50d66f1d559ba520e89a2cb2a83'), | |
bytearray.fromhex('32510ba9babebbbefd001547a810e67149caee11d945cd7fc81a05e9f85aac650e9052ba6a8cd8257bf14d13e6f0a803b54fde9e77472dbff89d71b57bddef121336cb85ccb8f3315f4b52e301d16e9f52f904') | |
) | |
KEY = bytearray(b'\x66\x39\x6e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') # I left only first 3 bytes | |
def xor_bytearray(a, b, replace_unreadable_with_dot=True): | |
res = bytearray() | |
length = min(len(a), len(b)) | |
for i in range(0, length): | |
c1 = a[i:i+1] | |
c2 = b[i:i+1] | |
res = res + bytes([ord(c1) ^ ord(c2)]) | |
pb = bytearray() | |
for byte_ in res: | |
if byte_ > ord(b'0') and byte_ < ord(b'z'): | |
pb += bytes([byte_]) | |
elif byte_ == 0: | |
pb += b'#' | |
else: | |
if replace_unreadable_with_dot: | |
pb += b'.' | |
else: | |
pb += bytes([byte_]) | |
print(pb) | |
def main(): | |
print('Stage1:') | |
for i in range(0, len(CIPHERS)-1): # Hmm, not-Pythonic way is useful (sometimes) | |
for j in range(i, len(CIPHERS)): | |
if i != j: | |
print('Comparing %d and %d' % (i, j)) | |
xor_bytearray(CIPHERS[i], CIPHERS[j]) | |
print('Stage2:') | |
for c in CIPHERS: | |
xor_bytearray(c, KEY, False) | |
if __name__ == '__main__': | |
main() | |
## output: | |
## | |
## Stage1: | |
## Comparing 0 and 1 | |
## bytearray(b'..L..NW....O.R...B..M...OH.T..#HN..A...MT......E..MO:#SC#NC....RF.....#..EC.....R..tN....M.U.O.NT7....CST.H..#.M') | |
## Comparing 0 and 2 | |
## bytearray(b'..EC..C.A....GT..O..M.#.Y]ZQW#.HN..A..U.R.........KR.EC..ND....#.A...RO.H.A#..B..RB..W...#.O...') | |
## Comparing 0 and 3 | |
## bytearray(b'..EC..P...#..TT..O.#...RBH.AW...KQ......T.#.P.....GT?.#...K.L..#....O.ST..P....#.T.ER....E.#..GAT......#..C....I..R..G.....M..r?....Ph;....') | |
## Comparing 0 and 4 | |
## bytearray(b'..UC..NA.C...TT..#.#.B.RSTA#..T.A.U....MF.##P.T....W?.#...C....Z..C..RS#..L...B..RB..W...CAr...N....N..M..N....#..R..I....') | |
## Comparing 0 and 5 | |
## bytearray(b'..E..NA..C#..##..E.U..E.RHET....P..ACT..A.O.....R.GL;EK...#....E..C...ET..O.U...##]\\T...HS.S....T...N..A#OW....#....EK...E#ENR7..E..F.A....') | |
## Comparing 0 and 6 | |
## bytearray(b'..E..NA..C#..##..E.U..E.YAAO....H.OA...MT...P.....]#..EC..V....E..C##RU..EB.#..E.OCVEW..HB.E..GT..A.....T.N.A..ET....#.....RHSr..#R3O>.#...') | |
## Comparing 0 and 7 | |
## bytearray(b'#######...T..ET..I#.M...RT.T..T.H..A..U.N...#.T..SO#..O..NB..S.SF....RA..EC......S.XO..T.O.E.O.R..A..#DE..I....E..RHEa.#M6.A@I.') | |
## Comparing 0 and 8 | |
## bytearray(b'.E....V...Y..Y]HEE#.....I^[#....M.U.....SC\\M....#.ZH:..C..M.#.OAF.....D..##...B..NTGA.#..#.E..K#.R.....D..EB...#.....P##.._#LN6O.E..O......') | |
## Comparing 0 and 9 | |
## bytearray(b'w1H.A.O.....Ro...R.1....O_TR.I\\Z.ACHN........U....ZOw.SC..EA...#..CT.#I#..GN.M.E.O]CI..T.O.E.AG') | |
## Comparing 0 and 10 | |
## bytearray(b'..EC..C...T..S...EN..XE.HT[#....GQ.A.#..A.O....##_.N2.E.A.S.L..EF...O.O..ET...B..CT') | |
## Comparing 1 and 2 | |
## bytearray(b'...E.I..U..I..O.....#.....O.H..#####..SC.......A.....E.A.#....#RAS.#.EO.FF....T.A_SaCN...M...E.') | |
## Comparing 1 and 3 | |
## bytearray(b'...E.I.....E..O.....C#.J.##.H..A.O.N...P#...R..G......SL.O..R..RG...N.SO.I....#.XY#1.......U.YO.#6....@SE.......') | |
## Comparing 1 and 4 | |
## bytearray(b'...E.O.H.L.A..O..B..YE.J..TT..TC..WK..##....R.MG..C...SS.E#.....E#T.#ES..A....T.A_SaCN....O..T.#B...E.H.M......M') | |
## Comparing 1 and 5 | |
## bytearray(b'.....#...L.W.R.....YO.N..#P#...A...#EI.H..E....HB....E.E.PC.....T#T...EO#R..Y...R.L.....Y....E.B#...E.O.TT.....M') | |
## Comparing 1 and 6 | |
## bytearray(b'.....#...L.W.R.....YO.N...T....P..M#...###..R..L...O...#.O..##..N.T..EU..#.#...OFBR..N..Y....KO.H.U...B_#...O...') | |
## Comparing 1 and 7 | |
## bytearray(b'..L..NW...DT..O.....#.....###.TC...#..SU.#....MI.E.O...N.#...N..##...EA..##.....E^#....N.....#..O.U.....N...#...') | |
## Comparing 1 and 8 | |
## bytearray(b'.UD.#I....IK..FBA...R.....NT...E..WS...E.HVO...O....#._#.A....E.#..#.#D..EC...T.ECE3...#.M...SCNAe....B.U..E...M') | |
## Comparing 1 and 9 | |
## bytearray(b'e..#Rc.....EP=.....=I...#.A..A\\.^_A.H........E.R...#M.##.H.O...RO.TO..I..N.R.P.OSBL7.#.N....#.O') | |
## Comparing 1 and 10 | |
## bytearray(b'...E.E....DM......L.S_N=..NT...N.O.#...E..E....E.IC....RAU..R...#...N.O..#....T#NNE') | |
## Comparing 2 and 3 | |
## bytearray(b'####.#..E.....#..#..C..E..O.#..A.O.N..Y.....O........MC..O..I..#.O..TA.FC.....T...SP_O...E.O..H') | |
## Comparing 2 and 4 | |
## bytearray(b'...#...BTT..#.#..O..Yk.E...QO.SC..WK..SC....O.R...E..OC..E.....Z.SL..#..E.....########.#.Cb=...') | |
## Comparing 2 and 5 | |
## bytearray(b'###R.I..ET...GT....TO.E.....O..A...#ZET...P.....P....#...PD....E.SL..F.FF...C#O..R.IYT..NS...#.') | |
## Comparing 2 and 6 | |
## bytearray(b'###R.I..ET...GT....TO.E.#...G..P..M#..EC...#O......R.H.A.O.....E.TL..#..EF....EC...CH#..NB....H') | |
## Comparing 2 and 7 | |
## bytearray(b'..EC..C.E.H...#....##<.#..O.H.SC...#..#.......R..H.R.R...#...V.SAS..##..DF....U...SMBR.A.O5..E.') | |
## Comparing 2 and 8 | |
## bytearray(b'.HMP.#..T.E....AB...R2.....QS..E..WS..T..YCT.........SOA#A....EAAP.#.E..R.A...#....RLT...#....D') | |
## Comparing 2 and 9 | |
## bytearray(b't<.EN...C...N.X.....I.......YI[.^_A.W.E......G......SA.A.H.R...#.FLO.R..I..N.YRC...VDN.A.O...KH') | |
## Comparing 2 and 10 | |
## bytearray(b'####..#.E#H...S#..U.SqE2...QU..N.O.#..R...P......DE..V..NU..I..EAK..TM#.EF....#....') | |
## Comparing 3 and 4 | |
## bytearray(b'...#...O.R...##..O.#.E.#..TAO.E..RE....P..#.##L#..I.#.#.....A..Z..O.NA#T......T...SP_O....Dr..E.B...O..M.......I###.#.....') | |
## Comparing 3 and 5 | |
## bytearray(b'###R.I..#R#..TT....U..DC.#P.O..#.H.NNR....O.H...O.#..MK...K#E..E..O.A..#....E....TL.....C..S..RM#...O..A.N.....I..L.L....T..C_E..I...E.....R....') | |
## ...skipping... | |
## bytearray(b'.HMP.#....Y....PR......T..NAS....EE......I\\NA..........L....L.SAG...C..U..P..#T...E......E.E...AAS.##..D...R...I.#C.......DMACDp.I...C?...#R...N') | |
## Comparing 3 and 9 | |
## bytearray(b't<.EC......#X;X...#1...I..A.YWMS[.SGC.......SA......H.SL...SA..#..ODW..T...H.R.E..L....U#.#E.W#') | |
## Comparing 3 and 10 | |
## bytearray(b'####....#.T...S...D.._Dw..NAU....#.N......O.I....^I...E.O...#..EG...#..R.I.#..T...E') | |
## Comparing 4 and 5 | |
## bytearray(b'...R.O.U.#...TT..E.U.FAC...T#.R...YKHY.H..O.H.C.U.I..OK...C......##..F.T....N.O..R.IYT..R.I....BB...#....E..#..#..L.L....R') | |
## Comparing 4 and 6 | |
## bytearray(b'...R.O.U.#...TT..E.U.FAC..#O..A....K...#....##L...SW..ES7.........#..#..#A....EC...CH#9.R.R7..E..#R.O..AM.#.I..EO.H..I....') | |
## Comparing 4 and 7 | |
## bytearray(b'..UC..NT.EW...#.#I..YW.E.#TT..##..PK..SU....P.#..YAW..O..E.#.L#.E#E..#...A..#.U...SMBR.A..W7.T....R.H.O......#.E..#nL...E.') | |
## Comparing 4 and 8 | |
## bytearray(b'.O]P...F#EZ....TOE...Y.T...#..H...#....E.R\\MA.G...T....S......I.E.R..E....L...#....RLT...CK7..IN.E..O#.....T...#.#C1......') | |
## Comparing 4 and 9 | |
## bytearray(b'y;.ED..I.I..N;X.#R.1.C.I...R.F.QQB.BE.......SAC...T.H.SS...I#..Z..#I.R.#...I.GRC...VDN.A..D7.ZE') | |
## Comparing 4 and 10 | |
## bytearray(b'...#...U.TW...S..EB...Aw.#.#..I..RAK...E..O.I.H..U#...E.P...A...E.E.NM..#A....#....') | |
## Comparing 5 and 6 | |
## bytearray(b'########################..........C#BN.H..A.H...O#.L.H.E..V....#..#..F.S.R..U..U.O...T..#.....RXH.N.O..MTA..I..EW...TK.#.U....E#.ES...E....N.O..#...E.....TFBR..U..#1....I..') | |
## Comparing 5 and 7 | |
## bytearray(b'..E..NA.#ET..ET....TO.H.#.P#..R....#DST...A...C.FW.L.R...PB..C..T#E..F.N.R..N....SL....EP....E.^O.N.H.H..V.....E..LA#...Ps.....') | |
## Comparing 5 and 8 | |
## bytearray(b'.HM..I...EY..Y]YP#.C..P....T......YSYA#..T.W....R....SGE..M...R.T.R....U..O.O.O..N...#..GS....^.AA..O....R.H...#....Y....G_E...T.#....E....#.#.RD.........Z.') | |
## Comparing 5 and 9 | |
## bytearray(b't<[email protected]#.Y...LA.E..ES...E..#S...T...MOY.U.O#....EC....KR') | |
## Comparing 5 and 10 | |
## bytearray(b'###R.E.##TT..S...#SI.\\#4...T.....H.#^T..#.#.....R[I..V..E.S.E..#T.E.A..R.R..A.O..C.') | |
## Comparing 6 and 7 | |
## bytearray(b'..E..NA.#ET..ET....TO.H...T...A.#.J#..EU.##.P.L..W.#...N.O...N..N.E..#...#.....M..R..R.OP..#.KF...#...EIN...O..#N#HLTa..Q.....R') | |
## Comparing 6 and 8 | |
## bytearray(b'.HM..I...EY..Y]YP#.C..P....O.......S...E.HRTA......H..I#...#..M.N.R..E...EB...EG.....T..GB.#...T.EP.#.#HU..DF#.EE....P....ER..DT.EP5#.#...#N.O.OD...Y.......') | |
## Comparing 6 and 9 | |
## bytearray(b't<..Ec...I..Oo.....d..T......RIBXI..O.#.....SA.....OT..#3..E...E..#T.R...N.R.T.#.#...N.OC..#.E#') | |
## Comparing 6 and 10 | |
## bytearray(b'###R.E.##TT..S...#SI.\\#4...O.....Y[#...E..A.I....[SN..#Rg..#R..#N.E.OM..##....EO...') | |
## Comparing 7 and 8 | |
## bytearray(b'.E....V..#.....PO.#.R.....NT..H...PS..T..HRP..G..I.H..CN.A...YI.#....E...EC...U.#.E....N.O.#.SJR.MP...E....R...E..C_Y1.#N4DA...') | |
## Comparing 7 and 9 | |
## bytearray(b'w1H.A.O...S.H.X.#...I.....A..E.QXYF.I.E......YC..P.OW..N.H.I.R.SO.EN.R...N.O.S.M..L....#.#.#..F') | |
## Comparing 7 and 10 | |
## bytearray(b'..EC..C.#.#...S...N.SMH2.#NT..I..I.#..R...A...H...AN....GU..TT..#.#.TM...#....U...E') | |
## Comparing 8 and 9 | |
## bytearray(b'[email protected].....^.E6QFO..........R.C@W]U.ZT.....]E.L....#.M._#...E..TAO.RO......GF#RRG.......N.O.#.].') | |
## Comparing 8 and 10 | |
## bytearray(b'.HMP........#.ZAG#N..CP...##.....EAS...#.M.C....#ET...IRN..#L.H.#...C....ET...#...#') | |
## Comparing 9 and 10 | |
## bytearray(b't<.ES.....S.E<....D..YT>...R.SA\\W.W.S.....N..P...\\T.E..RT..EA..EO.EYW....N.H.NRO...') | |
## Stage2: | |
## bytearray(b'We can factor the number 15 with quantum computers. We can also factor the number<!l-4LguA\x8c\xe7\xdck\xc4\x15V\xbd\xb3k\xbc') | |
## bytearray(b'Euler would probably enjoy that now his theorem becomes a corner stone of crypto 10\x18c-J}d\x0c\x82\xb2\xcb$\xcc[\x02\x8a\xa7n\xb7') | |
## bytearray(b'The nice thing about Keeyloq is now we cryptographers can drive a lot of fancy cancy carsA\xaf\xa8\xd6a\xcb') | |
## bytearray(b'The ciphertext produced by a weak encryption algorithm looks as good as ciphertexh0)\x7f,Af~\x04\x89\xe7\xda}\x83T\x02\xbc\xa6p\xbd') | |
## bytearray(b"You don\'t want to buy a set of car keys from a guy who specializes in stealing cancy chro\x02\xcd\x95\xd7p\xc6[@\xaa\xa0e\xf2") | |
## bytearray(b'There are two types of cryptography - that which will keep secrets safe from your<|0y7Iv=\x12\x84\xb4\xcca\xd1\x19\x02\xae\xbcf\xf2') | |
## bytearray(b'There are two types of cyptography: one that allows the Government to use brute fsb:hcQ|=\x03\x9f\xa2\xd9o\x83AJ\xaa\xf2a\xbd') | |
## bytearray(b'We can see the point where the chip is unhappy if a wrong bit is sent and consumeo04b1@3m\x0e\x9a\xa2\xca$\xc5GM\xa2\xf2v\xba') | |
## bytearray(b'A (private-key) encryption scheme states 3 algorithms, namely a procedure for geru+l7L}zA\x86\xa2\xc1w\x8f\x15C\xef\xa2p\xbd') | |
## bytearray(b' The Concise OxfordDictionary (2006) de\xef\xac\x81nes crypto as the art of writing o r ss|/d-B3~\x0e\x89\xa2\xcb*\x83') | |
## bytearray(b'The<REMOVED. WHY NOT TO TRY A BIT HARDER?>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment