Hacking Secret Ciphers with Python

(Ann) #1

152 http://inventwithpython.com/hacking


Email questions to the author: [email protected]




  1. move pointer over



  2. pointer += key


...to this:


transpositionEncrypt.py



  1. move pointer over



  2. pointer += key + 1


Now that the encryption code is broken, when we run the test program it should give us an error:


Test #1: "JEQLDFKJZWALCOYACUPLTRRMLWHOBXQNEAWSLGWAGQQSRSIUIQ..."
Mismatch with key 1 and message
JEQLDFKJZWALCOYACUPLTRRMLWHOBXQNEAWSLGWAGQQSRSIUIQTRGJHDVCZECRESZJARAVIPFOBWZXX
TBFOFHVSIGBWIBBHGKUWHEUUDYONYTZVKNVVTYZPDDMIDKBHTYJAHBNDVJUZDCEMFMLUXEONCZXWAWG
XZSFTMJNLJOKKIJXLWAPCQNYCIQOFTEAUHRJODKLGRIZSJBXQPBMQPPFGMVUZHKFWPGNMRYXROMSCEE
XLUSCFHNELYPYKCNYTOUQGBFSRDDMVIGXNYPHVPQISTATKVKM.
JQDKZACYCPTRLHBQEWLWGQRIITGHVZCEZAAIFBZXBOHSGWBHKWEUYNTVNVYPDIKHYABDJZCMMUENZWW
XSTJLOKJLACNCQFEUROKGISBQBQPGVZKWGMYRMCELSFNLPKNTUGFRDVGNPVQSAKK


Summary


We can use our programming skills for more than just writing programs. We can also program
the computer to test those programs to make sure they work for different inputs. It is a common
practice to write code to test code.


This chapter covered a few new functions such as the random.randint() function for
producing pseudorandom numbers. Remember, pseudorandom numbers aren’t random enough
for cryptography programs, but they are good enough for this chapter’s testing program. The
random.shuffle() function is useful for scrambling the order of items in a list value.


The copy.deepcopy() function will create copies of list values instead of reference values.
The difference between a list and list reference is explained in this chapter as well.


All of our programs so far have only encrypted short messages. In the next chapter, we will learn
how to encrypt and decrypt entire files on your hard drive.

Free download pdf