44namespace ByteSync . Services . Communications ;
55
66/// <summary>
7- /// Cette classe permet de déterminer une liste de mots à partir d'un MD5.
8- /// Elle se base sur mnemonicode pour associer des mots au MD5.
7+ /// This class allows you to determine a list of words from an MD5.
8+ /// It is based on mnemonicode to associate words with MD5.
99/// Infos : https://github.com/singpolyma/mnemonicode // https://github.com/singpolyma/mnemonicode/blob/master/mn_wordlist.c
1010/// </summary>
1111public class SafetyWordsComputer
@@ -19,7 +19,7 @@ public SafetyWordsComputer(string[] availableWords)
1919
2020 public string [ ] Compute ( string hexInput )
2121 {
22- // On contrôle la valeur entrante
22+ // The incoming value is checked.
2323 if ( hexInput . IsNullOrEmpty ( ) )
2424 {
2525 throw new ArgumentOutOfRangeException ( nameof ( hexInput ) , "input can not be empty" ) ;
@@ -29,17 +29,17 @@ public string[] Compute(string hexInput)
2929 throw new ArgumentOutOfRangeException ( nameof ( hexInput ) , "wrong input format" ) ;
3030 }
3131
32- // On convertit hexInput en decimal
33- // On détermine combien de mots seront nécessaires pour couvrir la
34- // Puis on le convertit en base 1633 / mnemonicode en effectuant une division
35- // On complète éventuellement avec les mots manquants
36-
37- // Précédemment, on découpait la chaîne en groupes de 4 caractères, mais cela entraînait des sauts lors de la division
38- // et diminuait la qualité de la conversion
32+ // Convert hexInput to decimal
33+ // We determine how many words will be needed to cover the
34+ // Then we convert it to base 1633 / mnemonicode by performing a division
35+ // We fill in any missing words
36+
37+ // Previously, we split the string into groups of 4 characters, but this caused jumps during division
38+ // and reduced the quality of the conversion
3939
4040 var result = new List < string > ( ) ;
4141
42- // On calcule combien de valeurs possibles existent en fonction de la longueur de la chaîne en entrée
42+ // We calculate how many possible values exist based on the length of the input string
4343 var hexaInputPossibleValues = Math . Pow ( 16 , hexInput . Length ) ;
4444 var coverWordCount = 1 ;
4545 while ( Math . Pow ( AvailableWords . Length , coverWordCount ) < hexaInputPossibleValues )
@@ -51,9 +51,9 @@ public string[] Compute(string hexInput)
5151 string word ;
5252 while ( quotient > AvailableWords . Length )
5353 {
54- // On procède à des divisions successives pour le changement de base
55- // Le reste est ajouté à la liste, le quotient est ensuite redivisé
56- // On continu tant que " quotient est divisable", c'est à dire tant que " quotient > AvailableWords.Length"
54+ // Successive divisions are performed to change the base
55+ // The remainder is added to the list, and the quotient is then divided again
56+ // This is continued as long as “ quotient is divisible,” i.e., as long as “ quotient > AvailableWords.Length”
5757
5858 var modulo = ( int ) ( quotient % AvailableWords . Length ) ;
5959 word = AvailableWords [ modulo ] ;
@@ -62,18 +62,18 @@ public string[] Compute(string hexInput)
6262 quotient = quotient / AvailableWords . Length ;
6363 }
6464
65- // A la fin, on ajoute le dernier quotient à la liste
65+ // At the end, add the last quotient to the list
6666 word = AvailableWords [ ( int ) quotient ] ;
6767 result . Add ( word ) ;
6868
69- // Si le nombre en entrée est trop petit, on n'a pas atteint le nombre de mots attendu
70- // On complète
69+ // If the number entered is too small, the expected number of words has not been reached
70+ // Complete
7171 while ( result . Count < coverWordCount )
7272 {
7373 result . Add ( AvailableWords [ 0 ] ) ;
7474 }
7575
76- // On a ajouté les mots à l'envers, on retourne la liste
76+ // We added the words backwards, then reversed the list
7777 result . Reverse ( ) ;
7878
7979 return result . ToArray ( ) ;
0 commit comments