Skip to content

Instantly share code, notes, and snippets.

@tomekziel
Created September 7, 2020 20:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomekziel/5f95c9bb7274d037916d52df492ffc32 to your computer and use it in GitHub Desktop.
Save tomekziel/5f95c9bb7274d037916d52df492ffc32 to your computer and use it in GitHub Desktop.
Program w języku C# do seryjnego generowania numerów PESEL
using System;
using System.Diagnostics;
using System.IO;
// https://informatykzakladowy.pl
//
// material dodatkowy do tekstu o szyfrowaniu dokumentow z mBanku
// 2020.09.07
//
// public domain
namespace peselgenerator
{
class Program
{
static void Main(string[] args)
{
new Program().liczPesel(50, 100);
}
private void liczPesel(int rokstartowy, int rokkoncowy)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
long licznik = 0;
using (FileStream target = File.Create(@"pesele.txt"))
{
using (StreamWriter writer = new StreamWriter(target, bufferSize:1024*2014))
{
for (int rok = rokstartowy; rok < rokkoncowy; rok++)
{
for (int miesiac = 1; miesiac <= 12; miesiac++)
{
Console.WriteLine(rok + "/" + miesiac);
for (int dzien = 1; dzien <= 31; dzien++)
{
for (int nr = 0; nr < 10000; nr++)
{
licznik++;
long pesel = (rok * 100000000L) + (miesiac * 1000000L) + (dzien * 10000) + nr;
int liczba = CountSum(pesel);
writer.Write(pesel);
writer.WriteLine(CountSum(pesel));
}
}
}
}
}
}
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("Czas pracy " + elapsedTime+" / liczba numerow PESEL "+licznik);
}
private static readonly int[] mnozniki = { 1, 3, 7, 9, 1, 3, 7, 9, 1, 3 };
private static int CountSum(long pesel)
{
long sum = 0;
long dzielnik = 1000000000;
for (int i = 0; i < mnozniki.Length; i++)
{
int m = mnozniki[i];
int c = (int)((pesel / dzielnik) % 10);
sum += m * c;
dzielnik /= 10;
}
int reszta = (int)(sum % 10);
return reszta == 0 ? reszta : (10 - reszta);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment