Single Table replacement password

Source: Internet
Author: User
Tags printf

In a single table replacement password, the key is made up of letters and spaces such as Shana

Before there is a key effect, the permutation table is as follows

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Under the action of the key, the permutation table will be changed, as follows

Fills the key in the permutation table, ignores the duplicate characters if it is encountered, and then fills in the order of the original table, ignoring the repeating characters, as shown in the following table

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
S H A N B C D E F G I J K L M O P Q R T U V W X Y Z

First, Shan is filled in the table, because A already appears earlier, so ignore it, and then fill in sequentially the alphabet minus s H A n four characters


The specific C language code implementation is as follows, this code personal feeling write not concise, later have the opportunity to revise

The idea is to read the key and fill in the empty permutation table, and then fill the list into the permutation table to form the cipher table.


#include <stdio.h> #include <stdlib.h> int main () {//permutation table char list[27] = {0}; Alphabetic table Char Alpha[26] = {' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' I ', ' J ', ' K ', ' L ', ' M ', ' N ', ' O ', ' P ', ' Q ', ' R ', ' S ', '
	T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z '};
	Key char key[101] = {0};
	PlainText char message[101] = {0};
	Ciphertext char ciphertext[101] = {0};

	int Num = 0;
	Get the key printf ("Please enter a key (less than 100 characters):");

	Gets (Key); Construct permutation table for (int i = 0; Key[i];
		++i) {if (key[i] = = ") continue;
				for (int j = 0; J < ++j) {if (alpha[j] = = Key[i]) {alpha[j] = 0;
			list[num++] = Key[i]; }} for (int i = 0; i < ++i) {if (!
		Alpha[i]) continue;
	list[num++] = Alpha[i];
	//Get plaintext printf ("Please enter clear text (within 100 characters):");

	Gets (message); Encrypt for (int i = 0; Message[i];
		++i) {if (message[i] = = ') ciphertext[i] = ';
	else ciphertext[i] = list[message[i]-' a ';

	//Print ciphertext printf ("Encrypted ciphertext:%s\n", ciphertext);
	System ("PAUSE");
return 0; }


Related Article

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.