ברוכים הבאים לאתר השאלות והתשובות. מקום בו תוכלו לשאול כל שאלה ולקבל תשובות מהקהילה. יצירת קשר במייל aviboots(AT)netvision.net.il

התגיות הפופולריות ביותר

c#

כיצד להמציא הצפנה בסיסית למספר בן 6 ספרות

0 אהבו 0 לא אהבו
180 views
asked Nov 3, 2013 in C# תכנות על-ידי avibootz (3,230 נקודות)

תשובה אחת

0 אהבו 0 לא אהבו

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int pass = 792531, encode_pass = 0, decode_pass = 0;
            int[] arr;

            Console.WriteLine("password = {0}", pass);
            arr = intToArray(pass);
            arr = basic_encode(arr);
            foreach (int num in arr)
                encode_pass = encode_pass * 10 + num;
            Console.WriteLine("encode_pass = {0}", encode_pass);

            arr = decode(encode_pass);
            foreach (int num in arr)
                decode_pass = decode_pass * 10 + num;
            Console.WriteLine("decode_pass = {0}", decode_pass);
           
        }
        // Just swap a few number, you can swap other numbers or make some basic calculation
        // Don't forget that you have to decode to original password number.
        // With calculation you can easily lost your original password.
        // For example +1 to all numbers. 9 turns to 10, and than what?
        // There is solution to everything but it's more complicated.
        public static int[] basic_encode(int[] arr)
        {
            int tmp;

            tmp = arr[1];
            arr[1] = arr[arr.Length - 2];
            arr[arr.Length - 2] = tmp;

            tmp = arr[2];
            arr[2] = arr[arr.Length - 3];
            arr[arr.Length - 3] = tmp;
            
            return arr;
        }
        public static int[] decode(int encode_pass)
        {
            int[] arr = intToArray(encode_pass);
            
            int tmp;

            tmp = arr[arr.Length - 2];
            arr[arr.Length - 2] = arr[1];
            arr[1] = tmp;

            tmp = arr[arr.Length - 3];
            arr[arr.Length - 3] = arr[2];
            arr[2] = tmp;
            
            return arr;
        }
        public static int[] intToArray(int num)
        {
            int[] arr = new int[num.ToString().Length];

            for (int i = arr.Length - 1; i >= 0; i--)
            {
                arr[i] = num % 10;
                num /= 10;
            }
            return arr;
        }
    }
}

XLOVE אתר היכרויות

answered Nov 3, 2013 על-ידי avibootz (3,230 נקודות)
edited Nov 3, 2013 על-ידי avibootz
...