@@ -0,0 +1,2597 @@
+### QUESTION:%0A'''%0A    Mr. X is approached in the subway by a guy who claims to be an alien stranded on Earth and to possess time machine%0Athat allows him to know the future. He needs funds to fix his flying saucer but filling in winning numbers for next week's lottery%0Awould create a time paradox. Therefore, he's willing to sell next week's winning numbers to Mr. X at a favorable price. Mr. X,%0Aas gullible as he is, feels that this may be a scam and asks for a proof. Alien gives him the next week's winning numbers in%0Aencrypted form so that Mr. X can't use them and then decide not to pay for them. After the lottery draw he'll give Mr. X the key%0Ato unlock the file and Mr. X can verify that the prediction was correct.%0AAfter the draw, Mr. X gets the key and lo and behold, the numbers are correct! To rule out the possibility that it happened by chance,%0Athey do the experiment twice. Then thrice. Finally, Mr. X is persuaded. He pays the alien and gets the set of numbers for the next%0Aweek's draw. But the numbers drawn are completely different.%0A    And now the question: How did the scam work? %0A'''%0A%0A### SOLUTION:%0Afrom random import randint%0A%0Agen_encrypted_winning_no    = lambda    : ''.join(%5Bchr(randint(48,90)) for _ in range(256)%5D)%0Adef gen_decrypt_key(locked_winning_no_to_MrX, data):%0A    key = ''.join(%5B'1' if i+1 in data else '0' for i in range(36)%5D)%0A    d = dict(%5B(i,chr(v)) for i,v in enumerate(range(ord('0'), ord('9')) + range(ord('A'), ord('Z')) + range(ord('a'), ord('z')) + %5Bord('-'), ord('_')%5D)%5D)%0A    dr = dict(%5B(d%5Bk%5D, k) for k in d%5D)%0A    return ''.join(%5Bd%5Beval('0b' + key%5Bi*6:i*6+6%5D)%5D for i in range(6)%5D)%0A    %0Adef decrypt_winning_no(locked_winning_no_to_MrX, passwd):%0A    d = dict(%5B(i,chr(v)) for i,v in enumerate(range(ord('0'), ord('9')) + range(ord('A'), ord('Z')) + range(ord('a'), ord('z')) + %5Bord('-'), ord('_')%5D)%5D)%0A    dr = dict(%5B(d%5Bk%5D, k) for k in d%5D)%0A    dd = ''.join(%5B('000000' + bin(dr%5Bi%5D)%5B2:%5D)%5B-6:%5D for i in passwd%5D)%0A    return %5Bi+1 for i,v in enumerate(dd) if v == '1'%5D%0A%0Alocked_winning_no_to_MrX = gen_encrypted_winning_no() # give fake encrypted no. to mr. X%0Aprint 'locked_winning_no_to_MrX :%5Cn%5Ct', locked_winning_no_to_MrX%0Akey_to_unlock = gen_decrypt_key(locked_winning_no_to_MrX, %5B1,2,5,6,7,9,12,13,15,16,17,20,21,23,25,26,27,28,29,30,33,36%5D) # wait for actual winning no. is out and generate fake key%0Aprint 'key_to_unlock :%5Cn%5Ct', key_to_unlock%0Aunlocked_winning_no_to_MrX = decrypt_winning_no(locked_winning_no_to_MrX, key_to_unlock) # mr. X uses the fake key to decrypt the fake encrpted no.%0Aprint 'unlocked_winning_no_to_MrX :%5Cn%5Ct', unlocked_winning_no_to_MrX%0A%0A

Create secret_lottery_winning_no2.py