Table Of ContentPython for Secret Agents
Analyze, encrypt, and uncover intelligence data using
Python, the essential tool for all aspiring secret agents
Steven F. Lott
BIRMINGHAM - MUMBAI
Python for Secret Agents
Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2014
Production reference: 1190814
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78398-042-0
www.packtpub.com
Cover image by Jarek Blaminsky (milak6@wp.pl)
Credits
Author Copy Editors
Steven F. Lott Insiya Morbiwala
Sayanee Mukherjee
Reviewers Deepa Nambiar
Nick Glynn
Karuna Narayanan
Steven Heinrich
Adithi Shetty
Sanjeev Jaiswal
Laxmi Subramanian
Maurice HT Ling
Project Coordinator
Acquisition Editor Sageer Parkar
Sam Wood
Proofreaders
Content Development Editor Ameesha Green
Prachi Bisht Samantha Lyon
Technical Editors Indexers
Veena Pagare Hemangini Bari
Anand Singh Rekha Nair
Graphics
Sheetal Aute
Production Coordinator
Nilesh R. Mohite
Cover Work
Nilesh R. Mohite
About the Author
Steven F. Lott has been programming since the 70s, when computers were large,
expensive, and rare. As a contract software developer and architect, he has worked
on hundreds of projects, from very small to very large ones. He's been using Python
to solve business problems for over 10 years.
He's particularly adept in struggling with gnarly data representation problems. He is
also the author of Mastering Object-oriented Python, Packt Publishing.
He is currently a technomad who lives in various places on the East Coast
of the U.S. His technology blog is located at http://slott-softwarearchitect.
blogspot.com.
About the Reviewers
Nick Glynn is currently employed as a technical trainer and consultant delivering
courses and expertise on Android, Python, and Linux at home in the UK and
across the globe. He has a broad range of experience, from board bring-up, Linux
driver development, and systems development to full stack deployments, web app
development, and security hardening for both the Linux and Android platforms.
I would like to thank my family for their love and my beautiful baby
girl, Inara, for always brightening my day.
Steven Heinrich is a full stack web developer who specializes in geospatial
applications. He has a Bachelor's degree in Geographic Information Systems (GIS)
and a Master's degree in GIS Management, both from Salisbury University. Steve
likes to stay updated on new technologies and build a diverse portfolio.
Working on a wide array of projects allows him to work with a tech stack that best
fits the unique needs of each project. This versatility and his desire to learn new
technologies keeps Steve energized and motivated.
Besides enjoying spending time with his family, sports, and being a tech geek, he
relaxes by sipping on one of the many homebrewed beers on tap in his garage.
Sanjeev Jaiswal is a computer graduate with 5 years of industrial experience.
He basically uses Perl and GNU/Linux for his day-to-day work. He also teaches
Drupal and WordPress CMS to bloggers. He has worked closely with top companies
such as CSC, IBM, and Motorola Mobility. He has also developed an interest in web
application penetration testing since 2013.
Sanjeev loves to impart his technical knowledge to engineering students and
IT professionals and has been teaching since 2008. He founded Alien Coders
(http://www.aliencoders.com/) based on the learning through sharing principle for
computer science students and IT professionals in 2010 and has become a huge hit in
India among engineering students.
He usually uploads technical videos on YouTube under the Alien Coders tag.
He has a huge fan base on his site because of his simple yet effective way of
teaching and his philanthropic nature towards students. You can follow him at
http://www.facebook.com/aliencoders on Facebook and http://twitter.com/
aliencoders on Twitter.
He has authored Instant PageSpeed Optimization, Packt Publishing, and is looking
forward to author or review more books by Packt Publishing and other publishers.
I would like to thank my parents and my wife, Shalini Jaiswal, for
their moral support in every phase of my life and growth.
I also give deep thanks and gratitude to my best friends, Ritesh
Kamal and Ranjan Pandey, for their personal and professional help
that is always available. It is because of them and some of my best
friends, Rakesh Pandey, Rakesh Sharma, Abhishek Shukla, Anil
Sharma, Santosh Vishwakarma, and others, that I have achieved
a set of impossible goals in such a short time.
Maurice HT Ling (personal website: http://maurice.vodien.com) has
completed his PhD in Bioinformatics and BSc (Hons) in Molecular and Cell Biology
from The University of Melbourne. He is currently a research fellow at Nanyang
Technological University, Singapore, and an honorary fellow at The University of
Melbourne, Australia. Maurice is the chief editor of the journal, Computational and
Mathematical Biology, iConcept Press Ltd.; the co-editor of the e-journal, The Python
Papers; and the co-founder of the Python User Group (Singapore).
Recently, Maurice co-founded the first synthetic biology start-up in Singapore,
AdvanceSyn Pte. Ltd., as Director and Chief Technology Officer. His research
interests lie in life—biological life, artificial life, and artificial intelligence—using
computer science and statistics as tools to understand life and its numerous aspects.
In his free time, Maurice likes to read, enjoy a cup of coffee, write his personal
journal, or philosophize on the various aspects of life.
www.PacktPub.com
Support files, eBooks, discount offers
and more
You might want to visit www.PacktPub.com for support files and downloads related to
your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
TM
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can access, read and search across Packt's entire library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib
today and view nine entirely free books. Simply use your login credentials for immediate access.
Table of Contents
Preface 1
Chapter 1: Our Espionage Toolkit 7
Getting the tools of the trade – Python 3.3 8
Windows secrets 8
Mac OS X secrets 9
Getting more tools – a text editor 9
Getting other developer tools 10
Getting a tool to get more Python components 10
Confirming our tools 11
How do we stop? 12
Using the help() system 12
Mac OS and GNU/Linux secrets 13
Windows secrets 13
Using the help mode 14
Background briefing – math and numbers 14
The usual culprits 14
The ivory tower of numbers 16
Integer numbers 16
Rational numbers 17
Floating-point numbers 17
Decimal numbers 18
Complex numbers 20
Outside the numbers 20
Assigning values to variables 21
Writing scripts and seeing output 23
Gathering user input 24
Handling exceptions 25
Looping and trying again 26
Description:Analyze, encrypt, and uncover intelligence data using Python, the essential tool for all aspiring secret agents About This BookBuild a toolbox of Python gadgets for password recovery, currency conversion, and civic data hackingUse stenography to hide secret messages in imagesGet to grips with geocod