Cryptography With Python 简明教程

Python Overview and Installation

Python 是一种开源脚本语言,它高级、直譯、互动且面向对象的。它被设计为高度可读。Python 语言的语法易于理解且经常使用英语关键字。

Python is an open source scripting language which is high-level, interpreted, interactive and object-oriented. It is designed to be highly readable. The syntax of Python language is easy to understand and uses English keywords frequently.

Features of Python Language

Python 提供以下主要功能 −

Python provides the following major features −

Interpreted

Python 在运行时使用解释器处理。在执行之前无需编译程序。它类似于 PERL 和 PHP。

Python is processed at runtime using the interpreter. There is no need to compile a program before execution. It is similar to PERL and PHP.

Object-Oriented

Python 遵循面向对象样式和设计模式。它包括类定义,具有封装和多态性等各种功能。

Python follows object-oriented style and design patterns. It includes class definition with various features like encapsulation and polymorphism.

Key Points of Python Language

Python 编程语言的关键点如下 −

The key points of Python programming language are as follows −

  1. It includes functional and structured programming and methods as well as object oriented programming methods.

  2. It can be used as a scripting language or as a programming language.

  3. It includes automatic garbage collection.

  4. It includes high-level dynamic data types and supports various dynamic type checking.

  5. Python includes a feature of integration with C, C++ and languages like Java.

Python 语言的下载链接如下 − www.python.org/downloads 它包括 Windows、MacOS 和 Linux 发行版等各种操作系统的软件包。

The download link for Python language is as follows − www.python.org/downloadsIt includes packages for various operating systems like Windows, MacOS and Linux distributions.

python download

Python Strings

字符串的基本声明如下所示 −

The basic declaration of strings is shown below −

str = 'Hello World!'

Python Lists

Python 列表可以声明为复合数据类型,用逗号分隔并用方括号 ([]) 括起来。

The lists of python can be declared as compound data types, separated by commas and enclosed within square brackets ([]).

list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']

Python Tuples

元组是 Python 的动态数据类型,由用逗号分隔的多个值组成。元组用括号括起来。

A tuple is dynamic data type of Python which consists of number of values separated by commas. Tuples are enclosed with parentheses.

tinytuple = (123, 'john')

Python Dictionary

Python 字典是一种哈希表。字典键几乎可以是 Python 的任何数据类型,通常是数字或字符串。

Python dictionary is a type of hash table. A dictionary key can be almost any data type of Python, which are usually numbers or strings.

tinydict = {'name': 'omkar','code':6734, 'dept': 'sales'}

Cryptography Packages

Python 包含一个名为 cryptography 的软件包,该软件包提供加密算法和基础函数。它支持 Python 2.7、Python 3.4+和 PyPy 5.3+。通过以下命令完成 cryptography 软件包的基本安装 −

Python includes a package called cryptography which provides cryptographic recipes and primitives. It supports Python 2.7, Python 3.4+, and PyPy 5.3+. The basic installation of cryptography package is achieved through following command −

pip install cryptography

提供了许多带有高级秘方和低级接口的软件包,可用于 symmetric ciphersmessage digestskey derivation functions. 等通用加密算法。

There are various packages with both high level recipes and low level interfaces to common cryptographic algorithms such as symmetric ciphers, message digests and key derivation functions.

在整个教程中,我们将使用 Python 的各种软件包来实现加密算法。

Throughout this tutorial, we will be using various packages of Python for implementation of cryptographic algorithms.