Column permutation (column replacement) encryption in cryptographic programs

Source: Internet
Author: User

Implement column permutation encryption through programming, gain a deeper understanding of its principles, and master the column permutation algorithm.

Steps:

(1) enter the key

(2) sort out the letters in the key

(3) Input plaintext

(4) The plaintext order is disrupted by the letter order in the key.

(5) Output ciphertext

(6) Decryption

(7) Output plaintext

# Include <stdio. h> # include <string. h> int main () {int I, j, L, K, M, num [30]; char key [30], plantext [100], plantext2 [100], cipher [100]; printf ("Please input the key \ n"); scanf ("% s", key); L = strlen (key); for (I = 0; I <L; I ++) {num [I] = 0; For (j = 0; j <L; j ++) {If (Key [J] <= Key [I]) {num [I] = num [I] + 1 ;} if (Key [J] = Key [I] & J> I) num [I] = num [I]-1 ;}} printf ("Please input the plantext \ n"); scanf ("% s", plantext); k = strlen (plantext); I = 0; // complete xfor (M = K % L; m <L; m ++) {plantext [K + I] = 'X'; I ++ ;} if (K % L = 0) // calculate the number of rows M = K/L; else M = K/L + 1; printf ("encrypted: \ n "); for (I = 0; I <m; I ++) {for (j = 0; j <L; j ++) {cipher [I * L + J] = plantext [I * L + num [J]-1] ;}}for (I = 0; I <L; I ++) // output ciphertext {for (j = 0; j <m; j ++) printf ("% C", cipher [J * L + I]);} printf ("\ n"); printf ("decryption: \ n"); // decrypt the ciphertext for (I = 0; I <m; I ++) {for (j = 0; j <L; j ++) {plantext2 [I * L + num [J]-1] = cipher [I * L + J];} plantext2 [(I-1) * l + J] = '\ 0'; printf ("% s \ n", plantext2); Return 0 ;}

You can only understand the principle of column replacement password, that is, hands-on exercises, but not practical applications.

The program runs as follows:

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.