Skip to content

Commit d07f9bd

Browse files
authored
Merge pull request #43 from SecurityCze/salt_position
Add new salt position options: - As a separate word itself (#36) - Prefix and suffix a word (#38)
2 parents da295fc + 055b441 commit d07f9bd

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

Diceware.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,25 @@ private static void ApplySalt(string[] words, SaltType salt, IEnumerable<SaltSou
294294

295295
words[targetIndex] = $"{words[targetIndex]}{separator}{singleSalt}";
296296
break;
297+
case SaltType.SuffixToRandomWord:
298+
int suffixToIndex = random.AtMost(words.Length - 1);
299+
words[suffixToIndex] = $"{words[suffixToIndex]}{singleSalt}";
300+
break;
301+
case SaltType.PrefixToRandomWord:
302+
int prefixToIndex = random.AtMost(words.Length - 1);
303+
words[prefixToIndex] = $"{singleSalt}{words[prefixToIndex]}";
304+
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;
297316
default:
298317
throw new ArgumentOutOfRangeException(nameof(salt));
299318
}

SaltType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,11 @@ public enum SaltType
3636
BetweenOne,
3737
[Description("Between each word")]
3838
BetweenEach,
39+
[Description("Prepend to the beginning of a random word")]
40+
PrefixToRandomWord,
41+
[Description("Appended to the end of a random word")]
42+
SuffixToRandomWord,
43+
[Description("Insert as a separate word at a random position, once")]
44+
AsSeparateWordOnce,
3945
}
4046
}

0 commit comments

Comments
 (0)