Information security -2:python Hill cipher algorithm [original]

Source: Internet
Author: User

Forwarding Annotated Source: http://www.cnblogs.com/0zcl/p/6106513.html

Objective:

Hill cipher Algorithm I intend to introduce briefly, the encryption matrix I use the textbook 3*3 matrix, only do the encryption, decryption did not do, but I think will be encrypted will be decrypted ~ ~

First, Hill algorithm principle

Hill Password is a multi-letter replacement password, developed by Mathematics Leste Hill in 1929. The cipher algorithm takes m consecutive plaintext letters and replaces them with M-letters, expressed as vectors or matrices (where M=3,c and p are column vectors of length 3, K is the 3*3 matrix):

That is: C=KP (C is ciphertext, p is clear, K is the key matrix)

PS: Cryptographic operation to perform modulo 26 operation

Second, encryption rules

Encryption rules are not difficult, that is, there is a matrix operation (Forget can Gu brother, and line generation about ~)

    1. Group clear text, every 3 letters a set, the letter Z is not enough (I set, the following programming is also fill Z)
    2. Perform matrix operations to find ciphertext for each set of letters

Example:

The first 3 letters of the plaintext are expressed as: pay= (0) T

The process of calculating ciphertext: K (0) t= (375 819 486) Tmod 26= (All) t=lns

And so on, can be ciphertext for LNS HDL EWM TRW

Third, programming and thinking

Ideas please see my drawing flowchart, url http://processon.com/diagraming/583aff30e4b086d1e7d3b617

Source

View Code

Test

View Code

Information security -2:python Hill cipher algorithm [original]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.