none
Help with cryptography RRS feed

  • Question

  • 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.

    Tuesday, February 21, 2017 3:30 AM

All replies

  • Hi Orleans,

    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;
            }
        }
    }
    

    Here is the test result.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Kristin Xie Friday, February 24, 2017 2:30 AM
    Tuesday, February 21, 2017 7:04 AM