This introduction to cryptography employs a programming-oriented approach to study the most important cryptographic schemes in current use and the main cryptanalytic attacks against them. Discussion of the theoretical aspects, emphasizing precise security definitions based on methodological tools such as complexity and randomness, and of the mathematical aspects, with emphasis on number-theoretic algorithms and their applications to cryptography and cryptanalysis, is integrated with the programming approach, thus providing implementations of the algorithms and schemes as well as examples of realistic size. A distinctive feature of the author's approach is the use of Maple as a programming environment in which not just the cryptographic primitives but also the most important cryptographic schemes are implemented following the recommendations of standards bodies such as NIST, with many of the known cryptanalytic attacks implemented as well. The purpose of the Maple implementations is to let the reader experiment and learn, and for this reason the author includes numerous examples. The book discusses important recent subjects such as homomorphic encryption, identity-based cryptography and elliptic curve cryptography. The algorithms and schemes which are treated in detail and implemented in Maple include AES and modes of operation, CMAC, GCM/GMAC, SHA-256, HMAC, RSA, Rabin, Elgamal, Paillier, Cocks IBE, DSA and ECDSA. In addition, some recently introduced schemes enjoying strong security properties, such as RSA-OAEP, Rabin-SAEP, Cramer--Shoup, and PSS, are also discussed and implemented. On the cryptanalysis side, Maple implementations and examples are used to discuss many important algorithms, including birthday and man-in-the-middle attacks, integer factorization algorithms such as Pollard's rho and the quadratic sieve, and discrete log algorithms such as baby-step giant-step, Pollard's rho, Pohlig--Hellman and the index calculus method.This textbook is suitable for advanced undergraduate and graduate students of computer science, engineering and mathematics, satisfying the requirements of various types of courses: a basic introductory course; a theoretically oriented course whose focus is on the precise definition of security concepts and on cryptographic schemes with reductionist security proofs; a practice-oriented course requiring little mathematical background and with an emphasis on applications; or a mathematically advanced course addressed to students with a stronger mathematical background. The main prerequisite is a basic knowledge of linear algebra and elementary calculus, and while some knowledge of probability and abstract algebra would be helpful, it is not essential because the book includes the necessary background from these subjects and, furthermore, explores the number-theoretic material in detail. The book is also a comprehensive reference and is suitable for self-study by practitioners and programmers.