Advertisement
futuricon

pinfl_generator

Feb 28th, 2025 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 KB | None | 0 0
  1. // Online C# Editor for free
  2. // Write, Edit and Run your C# code using C# Online Compiler
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7.  
  8. public class HelloWorld
  9. {
  10.     public static void Main(string[] args)
  11.     {
  12.         var dates = GenerateRandomBirthdates(20, 21, 60);
  13.         foreach(var date in dates)
  14.         {
  15.             var pinfl =  FakeGeneratorPinfl(date);
  16.             Console.WriteLine($"BithDate: {date.ToString("yyyy-MM-dd")} - PINFL: {pinfl}");
  17.         }
  18.     }
  19.    
  20.     public static List<DateTime> GenerateRandomBirthdates(int count, int minAge, int maxAge)
  21.     {
  22.         List<DateTime> birthdates = new List<DateTime>();
  23.         Random random = new Random();
  24.  
  25.         for (int i = 0; i < count; i++)
  26.         {
  27.             int daysOld = random.Next(minAge * 365, maxAge * 365); // Convert age to days
  28.             birthdates.Add(DateTime.Today.AddDays(-daysOld));
  29.         }
  30.  
  31.         return birthdates;
  32.     }
  33.    
  34.     public static string FakeGeneratorPinfl(DateTime birthDate)
  35.     {
  36.         var random = new Random();
  37.         var gender = (Gender)random.Next(0, 2);
  38.        
  39.         List<int> multipliers = new List<int> { 7, 3, 1, 7, 3, 1, 7, 3, 1, 7, 3, 1, 7 };
  40.  
  41.         int firstDigit;
  42.         if (birthDate.Year >= 1900 && birthDate.Year <= 1999)
  43.         {
  44.             firstDigit = gender == Gender.Male ? 3 : 4;
  45.         }
  46.         else if (birthDate.Year >= 2000 && birthDate.Year <= 2099)
  47.         {
  48.             firstDigit = gender == Gender.Male ? 5 : 6;
  49.         }
  50.         else
  51.         {
  52.             throw new ArgumentOutOfRangeException(nameof(birthDate), "Year must be between 1900 and 2099");
  53.         }
  54.  
  55.         // Convert date to PINFL part
  56.         var birthDateDigits = birthDate.ToString("ddMMyy").Select(c => c - '0').ToList();
  57.  
  58.         // Generate 6 random digits
  59.         var randomDigits = new List<int>();
  60.         for (int i = 0; i < 6; i++)
  61.         {
  62.             randomDigits.Add(random.Next(0, 10));
  63.         }
  64.  
  65.         // Combine all parts
  66.         List<int> pinfl = new List<int> { firstDigit };
  67.         pinfl.AddRange(birthDateDigits);
  68.         pinfl.AddRange(randomDigits);
  69.  
  70.         // Calculate control digit
  71.         int sum = 0;
  72.         for (int i = 0; i < 13; i++)
  73.         {
  74.             sum += pinfl[i] * multipliers[i];
  75.         }
  76.         int controlDigit = sum % 10;
  77.  
  78.         // Append control digit
  79.         pinfl.Add(controlDigit);
  80.  
  81.         return string.Join("", pinfl);
  82.     }
  83.  
  84.         public enum Gender
  85.         {
  86.             Female =0,
  87.             Male = 1
  88.         }
  89. }
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement