ZCMU 1294: OD

Description

In cryptography, encryption is the process of encoding messages (or information) in such a way that third parties cannot read it, but only authorized parties can. Encryption doesn't prevent hacking but it prevents the hacker from reading the data that is encrypted. In an encryption scheme, the message or information (referred to as plaintext) is encrypted using an encryption algorithm, turning it into an unreadable ciphertext (ibid.). This is usually done with the use of an encryption key, which specifies how the message is to be encoded. Any adversary that can see the ciphertext should not be able to determine anything about the original message. An authorized party, however, is able to decode the ciphertext using a decryption algorithm, that usually requires a secret decryption key, that adversaries do not have access to. For technical reasons, an encryption scheme usually needs a key-generation algorithm to randomly produce keys.

There are so many ways to encrypt a message. In general, there are two kinds of method: Symmetric key encryption and Public key encryption. In Symmetric-key schemes, the encryption and decryption keys are the same. Thus communicating parties must agree on a secret key before they wish to communicate. But In public-key encryption schemes, the encryption key is published for anyone to use and encrypt messages. However, only the receiving party has access to the decryption key and is capable of reading the encrypted messages. Public-key encryption is a relatively recent invention: historically, all encryption schemes have been symmetric-key (also called private-key) schemes. Likewise, there are many algorithms used in encryption efficiently, such as DES(Data Encryption Standard), 3DES, RC2&RC4, IDEA and so forth. What’s more, you can also define your own rules to encrypt messages. For example, we can define a method named OE which first makes every digit of the number add 9 then mod 10. Then separate the digits in odd positions and the digits in even positions from the new number in their original order, then connect the two parts with the set of digits in odd positions first.

One of the earliest public key encryption applications was called Pretty Good Privacy (PGP). It was written in 1991 by Phil Zimmermann and was purchased by Symantec in 2010.

Encryption is also used to protect data in transit, for example data being transferred via networks (e.g. the Internet, e-commerce), mobile telephones, wireless microphones, wireless intercom systems, Bluetooth devices and bank automatic teller machines. There have been numerous reports of data in transit being intercepted in recent years. Encrypting data in transit also helps to secure it as it is often difficult to physically secure all access to networks.

Digital signature and encryption must be applied at message creation time (i.e. on the same device it has been composed) to avoid tampering. Otherwise any node between the sender and the encryption agent could potentially tamper it. It should be noted that encrypting at the time of creation only adds security if the encryption device itself has not been tampered with.

With the information on encryption above, you also want to encryption some passwords with some ingenious methods and efficient algorithms. To make the problem more easier, your task is to encrypt a number with your own method------OE. Good luck, ACMer!

Input

First line contains a positive integer T(T<=10000). Then T cases follow. Each case contains one line with a positive number N(N<100000000), which stands for the password.

Output

One line for each case, output the password after encrypted in OE method.

Sample Input

2

1257

5321041

Sample Output

0416

4190203

【分析】

有用的就这一段,For example, we can define a method named OE which first makes every digit of the number add 9 then mod 10. Then separate the digits in odd positions and the digits in even positions from the new number in their original order, then connect the two parts with the set of digits in odd positions first.翻译过来就是把每个数字加9余10.然后将偶数位置的数字按原来顺序全部提出来然后接在剩下的奇数位置的后面

#include<stdio.h>
int main()
{
    int t,x,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&k);
        int dig=0;
        x=k;
        while(x>0)
        {//得到位数
            x/=10;
            dig++;
        }
        int a[10],b[10];
        for(int i=dig;i>0;i--)
        {
            a[i]=(k%10+9)%10;k=k/10;
        }//得到每位加密后的数字存在数组a中

        int c=1;int t=(dig+1)/2+1;
        for(int j=1;j<=dig;j++)
        {
            if(j%2==1){b[c]=a[j];c++;}
            else {b[t]=a[j];t++;}
        }//按奇偶要求转存到数组b

        for(int z=1;z<=dig;z++)
            printf("%d",b[z]);
        //输出
     printf("\n");
    }
    return 0;
}

下面这个没过,不知道错哪

#include<bits/stdc++.h>
int main()
{
    char a[10],t;
    scanf("%d",&t);
    while(t--)
        {
        scanf("%s",a);
        int len=strlen(a);
        for(int i=0;i<len;i++)
        {
            if(i%2==0)printf("%d",(a[i]-'0'+9)%10);
        }
        for(int j=0;j<len;j++)
        {
            if(j%2==1)printf("%d",(a[j]-'0'+9)%10);
        }
        printf("\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_39315193/article/details/81459398