Add emoji support

This commit is contained in:
Illya Marchenko 2024-03-28 14:41:28 +02:00
parent 8e68218be8
commit 05e148698a
Signed by: stuzer05
GPG Key ID: A6ABAAA9268F9F4F
3 changed files with 65 additions and 13 deletions

@ -1,6 +1,6 @@
# Password generator # Password generator
* can generate multiple passwords at once (separated by \n) * can generate multiple passwords at once (separated by \n)
* can use Cyrillic/Japanese/Chinese character sets * can use Cyrillic/Japanese/Chinese/Emoji character sets
* uses at least one character from each character set * uses at least one character from each character set
## Build ## Build
@ -14,14 +14,16 @@ go build .
```sh ```sh
Usage of ./passgen: Usage of ./passgen:
-L int length of the generated password (default 16) -L int length of the generated password (default 16)
-S use spaces
-all use all character sets
-c int how many passwords to generate (default 1) -c int how many passwords to generate (default 1)
-l use lowercase ascii characters -l use lowercase ascii characters
-U use uppercase ascii characters -U use uppercase ascii characters
-n use numbers -n use numbers
-s use special characters -s use special characters
-unicode-cyrillic use unicode Cyrillic characters -S use spaces
-unicode-chinese use unicode Chinese characters --unicode-cyrillic use unicode Cyrillic characters
-unicode-japanese use unicode Japanese characters --unicode-chinese use unicode Chinese characters
--unicode-japanese use unicode Japanese characters
--unicode-emoji use unicode emoji characters
--all use all character sets
``` ```

45
dictionary/sets/emoji.go Normal file

@ -0,0 +1,45 @@
package sets
func emojiGenerateFromUnicodeRange(start, end rune) []int {
var emojis []int
for emoji := start; emoji <= end; emoji++ {
emojis = append(emojis, int(emoji))
// Variations with variation selectors
for vs := rune(0xFE00); vs <= rune(0xFE0F); vs++ {
combined := []rune{emoji, vs}
combinedStr := string(combined)
emojis = append(emojis, int([]rune(combinedStr)[0]))
}
// Variations with skin tone modifiers
for st := rune(0x1F3FB); st <= rune(0x1F3FF); st++ {
combined := []rune{emoji, st}
combinedStr := string(combined)
emojis = append(emojis, int([]rune(combinedStr)[0]))
}
}
return emojis
}
func Emoji() (dict []int) {
// Unicode ranges for emojis
ranges := [][]rune{
{0x1F600, 0x1F64F}, // Emoticons
{0x1F300, 0x1F5FF}, // Miscellaneous Symbols and Pictographs
{0x1F900, 0x1F9FF}, // Supplemental Symbols and Pictographs
{0x1F1E6, 0x1F1FF}, // Enclosed Alphanumeric Supplement (for flags)
{0x1F680, 0x1F6FF}, // Transport and Map Symbols
{0x2600, 0x26FF}, // Miscellaneous Symbols
{0x2700, 0x27BF}, // Dingbats
{0xFE00, 0xFE0F}, // Variation Selectors
{0x1F1E6, 0x1F1FF}, // Regional Indicator Symbols
{0xE0030, 0xE0039}, // Variation Selectors Supplement
}
for _, r := range ranges {
dict = append(dict, emojiGenerateFromUnicodeRange(r[0], r[1])...)
}
return
}

@ -22,6 +22,7 @@ func main() {
flagSetUnicodeCyrillic := flag.Bool("unicode-cyrillic", false, "use unicode cyrillic characters") flagSetUnicodeCyrillic := flag.Bool("unicode-cyrillic", false, "use unicode cyrillic characters")
flagSetUnicodeJapanese := flag.Bool("unicode-japanese", false, "use unicode Japanese characters") flagSetUnicodeJapanese := flag.Bool("unicode-japanese", false, "use unicode Japanese characters")
flagSetUnicodeChinese := flag.Bool("unicode-chinese", false, "use unicode Chinese characters") flagSetUnicodeChinese := flag.Bool("unicode-chinese", false, "use unicode Chinese characters")
flagSetUnicodeEmoji := flag.Bool("unicode-emoji", false, "use unicode emoji characters")
flag.Parse() flag.Parse()
@ -46,10 +47,11 @@ func main() {
*flagSetUnicodeCyrillic = true *flagSetUnicodeCyrillic = true
*flagSetUnicodeJapanese = true *flagSetUnicodeJapanese = true
*flagSetUnicodeChinese = true *flagSetUnicodeChinese = true
*flagSetUnicodeEmoji = true
} }
// use default password preset no sets were requested // use default password preset no sets were requested
if !*flagSetAll && !*flagSetAsciiLowercase && !*flagSetAsciiUppercase && !*flagSetNumbers && !*flagSetSpecialChars && !*flagSetSpaces && !*flagSetUnicodeCyrillic && !*flagSetUnicodeJapanese && !*flagSetUnicodeChinese { if !*flagSetAll && !*flagSetAsciiLowercase && !*flagSetAsciiUppercase && !*flagSetNumbers && !*flagSetSpecialChars && !*flagSetSpaces && !*flagSetUnicodeCyrillic && !*flagSetUnicodeJapanese && !*flagSetUnicodeChinese && !*flagSetUnicodeEmoji {
*flagSetAsciiLowercase = true *flagSetAsciiLowercase = true
*flagSetAsciiUppercase = true *flagSetAsciiUppercase = true
*flagSetNumbers = true *flagSetNumbers = true
@ -84,6 +86,9 @@ func main() {
if *flagSetUnicodeChinese { if *flagSetUnicodeChinese {
characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Chinese())) characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Chinese()))
} }
if *flagSetUnicodeEmoji {
characterSets = append(characterSets, dictionary.ShuffleDictionarySet(sets.Emoji()))
}
// generate passwords // generate passwords
for i := 0; i < *flagCount; i++ { for i := 0; i < *flagCount; i++ {