本文介绍了密码学帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写程序来加密和解密整数数据.例如,7234/1000 = 7和7234%1000 = 234(其余部分可以使用)例如8 * 100 + 5 * 10 + 3 * 1 =853.用户将 然后提示您输入一个不超过4位数字的数字进行加密.然后它将显示答案,然后向用户询问要解密的编号,然后也显示该答案.

Hi, I need help with writing a program to encrypt and decrypt integer data. For example, 7234 / 1000 = 7 and 7234 % 1000 = 234 (the remainder to work with) Also, for example, 8 * 100 + 5 * 10 + 3 * 1 = 853. The user will then be prompted to enter a number, no more than 4 digits, to encrypt. Then it will display the answer, then ask the user for  number to decrypt, then display the answer to that too.

推荐答案

您想以哪种方式进行加密和解密?根据您的描述,很抱歉,我不清楚.

What kind of way do you want to encrypt and decrypt? Based on your description, I am sorry It is not clear to me.

在这里我做了一个小演示

Here I made a small demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestEncryptandDecrypt
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please input no more than 4 digits");
            int i;
            string input= Console.ReadLine();

            if (int.TryParse(input, out i))
            {
                while (i / 10000 > 0)
                {
                    Console.WriteLine("Please input again and no more than 4 digits");
                    int.TryParse(Console.ReadLine(), out i);
                }
                int num = Encrypt(i);
                Console.WriteLine(num);
            }
            else
            {
                Console.WriteLine("Your input not an number!");
            }
            Console.ReadLine();
        }
       static int Encrypt(int num)
        {
            int i = num / 1000;
            int i2 = num % 1000;
            return i2;
        }
    }
}

这是测试结果.

最诚挚的问候,

克里斯汀


这篇关于密码学帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-13 01:20