Hacking Secret Ciphers with Python

(Ann) #1

66 http://inventwithpython.com/hacking


Email questions to the author: [email protected]


30 o .daed era meht fo o
29 w .daed era meht fo ow
28 t .daed era meht fo owt
27 .daed era meht fo owt
26 f .daed era meht fo owt f
25 i .daed era meht fo owt fi
24 .daed era meht fo owt fi
23 , .daed era meht fo owt fi ,
22 t .daed era meht fo owt fi ,t
21 e .daed era meht fo owt fi ,te
20 r .daed era meht fo owt fi ,ter
19 c .daed era meht fo owt fi ,terc
18 e .daed era meht fo owt fi ,terce
17 s .daed era meht fo owt fi ,terces
16 .daed era meht fo owt fi ,terces
15 a .daed era meht fo owt fi ,terces a
14 .daed era meht fo owt fi ,terces a
13 p .daed era meht fo owt fi ,terces a p
12 e .daed era meht fo owt fi ,terces a pe
11 e .daed era meht fo owt fi ,terces a pee
10 k .daed era meht fo owt fi ,terces a peek
9 .daed era meht fo owt fi ,terces a peek
8 n .daed era meht fo owt fi ,terces a peek n
7 a .daed era meht fo owt fi ,terces a peek na
6 c .daed era meht fo owt fi ,terces a peek nac
5 .daed era meht fo owt fi ,terces a peek nac
4 e .daed era meht fo owt fi ,terces a peek nac e
3 e .daed era meht fo owt fi ,terces a peek nac ee
2 r .daed era meht fo owt fi ,terces a peek nac eer
1 h .daed era meht fo owt fi ,terces a peek nac eerh
0 T .daed era meht fo owt fi ,terces a peek nac eerhT
.daed era meht fo owt fi ,terces a peek nac eerhT


The first line, which shows “48. .”, is showing what the expressions i, message[i], and
translated evaluate to after the string message[i] has been added to the end of
translated but before i is decremented. You can see that the first time the program execution
goes through the loop, i is set to 48 , and so message[i] (that is, message[48]) is the string
'.'. The translated variable started as a blank string, but when message[i] was added to
the end of it on line 9, it became the string value '.'.


On the next iteration of the loop, the print() call displays “47. .d”. You can see that i has
been decremented from 48 to 47 , and so now message[i] is message[47], which is the
'd' string. (That’s the second “d” in “dead”.) This 'd' gets added to the end of translated
so that translated is now set to '.d'.


Now you can see how the translated variable’s string is slowly “grown” from a blank string
to the reverse of the string stored in message.

Free download pdf