Advertisement
Guest User

Untitled

a guest
Nov 11th, 2011
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void button1_Click(object sender, EventArgs e)
  21.         {
  22.             string numuti; //on définit "numuti" comme étant une chaine de caractères (vous l'appelez comme vous le voulez)
  23.             numuti = numeroUtilisateur(); //on dit que "numuti" est le résultat de l'exécution de la fonction numeroUtilisateur(), soit le numéro donné par le logiciel pour identifier votre ordinateur
  24.             textBox1.Text = code(numuti); //on met dans la textBox1 le texte correspondant à l'exécution de la fonction code depuis la valeur de votre numéro d'ordinateur, qui est numuti
  25.         }
  26.  
  27.         public static string code(string numeroUtilisateur)
  28.         {
  29.             string str = "";
  30.             int num = 0;
  31.             for (int i = 0; i < numeroUtilisateur.Length; i++)
  32.             {
  33.                 if (numeroUtilisateur[i] != '-')
  34.                 {
  35.                     str = str + "BCDFGHJKMPQRTVWXY2346789"[Convert.ToInt16((int)(numeroUtilisateur[i] + i)) % 0x17];
  36.                     num++;
  37.                     if ((num % 3) == 0)
  38.                     {
  39.                         str = str + "-";
  40.                     }
  41.                 }
  42.             }
  43.             if (str.LastIndexOf('-') == (str.Length - 1))
  44.             {
  45.                 str = str.Substring(0, str.Length - 1);
  46.             }
  47.             return str;
  48.         }
  49.  
  50.  
  51.         public static string numeroUtilisateur()
  52.         {
  53.             string str = "";
  54.             uint volumeSerialNumber = 0;
  55.             uint maximumComponentLength = 0;
  56.             StringBuilder volumeNameBuffer = new StringBuilder(0x100);
  57.             uint fileSystemFlags = 0;
  58.             StringBuilder fileSystemNameBuffer = new StringBuilder(0x100);
  59.             long num4 = GetVolumeInformation(@"C:\", volumeNameBuffer, (uint)volumeNameBuffer.Capacity, ref volumeSerialNumber, ref maximumComponentLength, ref fileSystemFlags, fileSystemNameBuffer, (uint)fileSystemNameBuffer.Capacity);
  60.             string str2 = Convert.ToString(volumeSerialNumber);
  61.             int num5 = 0;
  62.             num5 = 0;
  63.             while (num5 < str2.Length)
  64.             {
  65.                 str = str + "BCDFGHJKMPQRTVWXY2346789"[Convert.ToInt16(str2[num5]) % 0x17];
  66.                 if (((num5 + 1) % 3) == 0)
  67.                 {
  68.                     str = str + "-";
  69.                 }
  70.                 num5++;
  71.             }
  72.             if ((num5 % 3) == 0)
  73.             {
  74.                 str = str + "ABC";
  75.             }
  76.             if ((num5 % 3) == 1)
  77.             {
  78.                 str = str + "AB";
  79.             }
  80.             if ((num5 % 3) == 2)
  81.             {
  82.                 str = str + "A";
  83.             }
  84.             return ("M60-" + str);
  85.         }
  86.  
  87.         [DllImport("kernel32.dll")]
  88.         private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, uint VolumeNameSize, ref uint VolumeSerialNumber, ref uint MaximumComponentLength, ref uint FileSystemFlags, StringBuilder FileSystemNameBuffer, uint FileSystemNameSize);
  89.  
  90.  
  91.     }
  92. }
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement