Skip to content

Commit 055b441

Browse files
committed
Add As Separate Word salt position options, closes #36
1 parent 67ca878 commit 055b441

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Diceware.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ private static void ApplySalt(string[] words, SaltType salt, IEnumerable<SaltSou
302302
int prefixToIndex = random.AtMost(words.Length - 1);
303303
words[prefixToIndex] = $"{singleSalt}{words[prefixToIndex]}";
304304
break;
305+
case SaltType.AsSeparateWordOnce:
306+
int insertBefore = random.AtMost(words.Length);
307+
if (insertBefore != words.Length)
308+
{
309+
words[insertBefore] = $"{singleSalt}{separator}{words[insertBefore]}";
310+
}
311+
else // There is no word with index insertBefore, we need to append it
312+
{
313+
words[insertBefore - 1] = $"{words[insertBefore - 1]}{separator}{singleSalt}";
314+
}
315+
break;
305316
default:
306317
throw new ArgumentOutOfRangeException(nameof(salt));
307318
}

SaltType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ public enum SaltType
4040
PrefixToRandomWord,
4141
[Description("Appended to the end of a random word")]
4242
SuffixToRandomWord,
43+
[Description("Insert as a separate word at a random position, once")]
44+
AsSeparateWordOnce,
4345
}
4446
}

0 commit comments

Comments
 (0)