s="What this means is that the distribution of very large keys is supremely important in the use of this perfectly secure cryptosystem. There's a nice story of how important the management of one-time pads can be from a wonderful book called \textit{Between Silk and Cyanide: A Codebreaker’s War}\index{Between Silk and Cyanide: A Codebreaker’s War} \cite{marks1999between} on cryptology during (part of) World War II by the author Leo Marks\index{Leo Marks}. Marks ran spies into Nazi-occupied Holland during the war, and when he took over, the spies were given cyanide pills to take so that they could commit suicide if ever captured. That way they would not give away the cryptosystems they used to radio back to England all the secrets they uncovered. Instead, under Marks's direction, they were given large one-time pads, written on sheets of silk thin enough to be worn underneath their clothes when they were first sent to Holland. That way, if captured later, they could tell everything they new about the codes they used and without having the specific one-time pad used by other spies or the one they intended to use later, the Nazis could get no information from intercepted ciphertexts. Which all meant that captured spies had no particular reason to commit suicide, and instead could cooperate and perhaps live out the rest of the war in a POW camp, if captured. This story of silk undergarments with cryptosystem keys written on them is the first time we see what will become a recurring theme in this subject: key distribution, management, and security can often be the most important practical consideration in applied cryptography. \chapter{Block Ciphers}\label{chap:blockciphers} Most of the encryption today on the Internet is probably done with one of the cryptosystems called \textit{block ciphers}\index{block ciphers}, which do not provide as perfect cryptographic security as a one-time pad, but which have a much, much more modest level of difficulty in key management. Block ciphers are also very fast and have some nice security features that cryptosystems structured like the ones we've seen so far do no. Examples of block ciphers you may have encountered might include: \begin{itemize} \item[$\bullet$] \textit{Advanced Encryption Standard [AES]}\index{Advanced Encryption Standard [AES]}\index{AES (Advanced Encryption Standard)}, authorized by the National Institute of Standards and Technology [NIST]\index{National Institute of Standards and Technology [NIST]}\index{NIST: National Institute of Standards and Technology} for use by the US federal government in unclassified situations; \item[$\bullet$] the \textit{Data Encryption Standard [DES]}\index{Data Encryption Standard [DES]}\index{DES: Data Encryption Standard}, which was the NIST-authorized block cipher from 1977 to 2001; and \item[$\bullet$] \textit{3DES}\index{3DES} or ``\textit{triple DES}\index{triple DES},'' a block cipher pretty much consisting of doing DES three times, which was used for a while after it was known that DES was nearly broken but before AES was standardized. \end{itemize} In this chapter, we will very briefly touch upon some of the most basic design principles for block ciphers\index{block ciphers}, do a little {\Python} implementation to explore these principles, and use some code libraries to do real encryption with state-of-the art block ciphers." fh=open('test.pdf','rb') input=fh.read() type(input) input len(input) fh_out=open('test.pdf.new','wb') fh_out.write(input) fh_out.close() fh_out2=open('test.pdf.newer','wb') input[0] input[0]=17 len(input) from random input * rand_data=[randint(0,255) for i in range(627804)] len(rand_data) fh_out2.write(rand_data) fh_out2.write(bytes(rand_data)) fh_out2.close() input otp=[randint(0,255) for i in range(len(input))] b_otp = bytes(otp) fh_output3=open('key','wb') fh_output3.write(b_otp) fh_output3.close() for i in range(len(input)): ciphertext=[] for i in range(len(input)): ciphertext.append((input[i]+b_otp[i])%256) ciphertext fh_output4=open('test.pdf.enc','wb') fh_output4.write(bytes(ciphertext)) fh_output4.close() fh_new=optn('test.pdf.enc','rb') encfile=fh_new.read() encfile len(encfile) fh_new1=open('key','rb') keyvals=fh_new1.read() keyvals len(keyvals) decfile=[] for i in range(len(encfile)): decfile.append((encfile[i]-keyvals[i])%256) decfile fh_new2=open('test.pdf.dec','wb') fh_new2.write(bytes(decfile))